Episode 4 — Generative AI Engineering / 4.16 — Agent Design Patterns
4.16 — Exercise Questions: Agent Design Patterns
Practice questions for all four subtopics in Section 4.16. Mix of conceptual, design, and hands-on tasks.
How to use this material (instructions)
- Read lessons in order —
README.md, then4.16.a->4.16.d. - Answer closed-book first — then compare to the matching lesson.
- Build the examples — implement the patterns from the lessons, then attempt these exercises.
- Interview prep —
4.16-Interview-Questions.md. - Quick review —
4.16-Quick-Revision.md.
4.16.a — Planner-Executor (Q1–Q10)
Q1. Define the Planner-Executor pattern in one sentence. What problem does it solve that a single-prompt approach cannot?
Q2. What are the two agents in this pattern, and what is each one's sole responsibility? Why is it important that neither agent does the other's job?
Q3. A user asks: "Analyze my website's performance and suggest improvements." Break this into a Planner output — list 5-6 steps with tool names, dependencies, and expected outputs.
Q4. What is a dependency graph in the context of a plan? Draw the dependency graph for a plan with these steps: (1) Load data, (2) Clean data (depends on 1), (3) Calculate stats (depends on 2), (4) Generate chart (depends on 3), (5) Detect anomalies (depends on 3), (6) Write report (depends on 3, 4, 5). Which steps can run in parallel?
Q5. Step 3 of a 6-step plan fails. Describe three different strategies the system could use: (a) skip dependents, (b) retry, (c) re-plan. For each, explain when it is the right choice.
Q6. Write the Planner system prompt for a code migration agent that can use these tools: read_file, analyze_dependencies, refactor_code, run_tests, write_file. Include the JSON output format.
Q7. Why should the Planner output be structured JSON rather than free-text? What breaks if the Planner returns a paragraph description of the steps instead?
Q8. Hands-on: Implement an Executor function that takes a plan (JSON) and executes steps in dependency order. Use Promise.allSettled to run independent steps in parallel. Test with the plan from Q4.
Q9. Your Planner generates plans with 15-20 steps for simple tasks. How do you fix this? Name two prompt engineering techniques to constrain plan complexity.
Q10. Design: You need to build an agent that can process customer support tickets — read the ticket, search the knowledge base, draft a response, check the response against policy, and send it. Design the plan structure (steps, tools, dependencies).
4.16.b — Researcher-Writer (Q11–Q20)
Q11. Define the Researcher-Writer pattern. Why is separating research from writing more effective than a single "research and write" prompt?
Q12. Name three types of data sources a Researcher agent might use. For each, give a concrete example and the type of information it would retrieve.
Q13. What is the critical instruction in the Writer's system prompt that prevents hallucination? Why is this instruction necessary even though the Researcher already gathered facts?
Q14. Write a Researcher system prompt for an agent that searches for information about competitor products. Include the output JSON format with facts, sources, and reliability scores.
Q15. Your Researcher returns 50 facts, all from the same website. What problem does this create, and how would you validate research quality before passing it to the Writer?
Q16. The Writer's report contains a statistic that does NOT appear in the Researcher's output. What went wrong? How do you detect and prevent this?
Q17. Why do the Researcher and Writer use different temperature settings? What temperature would you set for each, and why?
Q18. Hands-on: Build a simple Researcher-Writer pipeline that (a) takes a topic, (b) generates structured research with at least 5 facts and 3 statistics (simulated or real), (c) passes it to a Writer that produces a 500-word summary.
Q19. How do you handle the case where the Researcher finds no relevant information about the topic? What should the Writer do?
Q20. Design: You are building an automated earnings report summarizer. The input is a 50-page PDF. Design the Researcher-Writer pipeline, including how the Researcher extracts structured data and how the Writer produces a 1-page executive summary.
4.16.c — Critic-Refiner (Q21–Q30)
Q21. Define the Critic-Refiner pattern. What are the three agents involved, and what does each do?
Q22. Why must the Critic be strict and specific? Give an example of bad Critic feedback and good Critic feedback for the same issue.
Q23. What are the two exit conditions for the Critic-Refiner loop? Why do you need both?
Q24. Your Critic gives the same content a score of 5 on one run and a score of 9 on another run. This is a consistency problem. How do you diagnose and fix it?
Q25. Explain diminishing returns in the Critic-Refiner loop. If the score improves from 7 to 7.5 between iterations 2 and 3, should you continue to iteration 4? Why or why not?
Q26. Compare self-reflection (single agent critiques its own work) with separate Critic-Refiner (two agents). When would you choose each approach?
Q27. Hands-on: Implement a Critic that evaluates JavaScript code against these criteria: correctness, security, error handling, readability, performance. Return a structured JSON score card.
Q28. You are building a legal document generator. Choose the quality threshold (1-10), max iterations, and explain your reasoning. What is the cost per document at $0.025 per iteration?
Q29. How can the Critic-Refiner pattern be combined with the Researcher-Writer pattern? Describe the full pipeline.
Q30. Design: Build a Critic-Refiner loop for email drafting. The Generator produces an email based on context (who, what, tone). The Critic evaluates tone, clarity, professionalism, and length. The Refiner improves. Define the Critic's scoring rubric.
4.16.d — Router Agents (Q31–Q43)
Q31. Define the Router pattern. What is the Router's sole job, and why should it NOT answer questions itself?
Q32. Name three approaches to intent classification: LLM-based, keyword-based, and hybrid. For each, describe the trade-off between speed, accuracy, and cost.
Q33. Why is it important that each specialized handler has its own system prompt and temperature? Give a concrete example where using the same temperature for two different handlers would produce poor results.
Q34. Write the Router system prompt for a customer support system with these intents: billing, technical_support, returns, product_info, escalate_to_human. Include the JSON output format.
Q35. Design a three-tier fallback strategy for when the Router cannot confidently classify a message. What happens at high confidence (>0.8), medium (0.5-0.8), and low (<0.5)?
Q36. Why should the Router use a smaller, cheaper model (like GPT-4o-mini) instead of GPT-4o? What is the cost impact for a system handling 100,000 requests/day?
Q37. Compare the Router pattern with function calling (4.7). They seem similar — when would you use each one? Can they work together?
Q38. Hands-on: Implement a keyword-based router that classifies messages into 4 categories. Test with 10 example messages. Track how many are classified correctly vs incorrectly.
Q39. Your Router misclassifies "help me write a SQL query" as creative_writing instead of code_help. How do you debug this? Name two ways to improve classification accuracy.
Q40. What metrics should you log at the Router level? Name at least 5 metrics and explain what each one tells you about system health.
Q41. Design: You are building a multi-tenant AI assistant where different companies have different capabilities enabled. How would you modify the Router pattern to support per-tenant handler registries?
Q42. Explain how the Router pattern supports adding new capabilities without code changes. How does dynamic handler registration work?
Q43. Cross-pattern design: A user sends "Research the top 5 JavaScript frameworks and write a comparison blog post." Which patterns would you combine (Router + Planner-Executor + Researcher-Writer + Critic-Refiner)? Describe the full flow.
Answer Hints
| Q | Hint |
|---|---|
| Q4 | Steps 4 and 5 both depend on step 3 but not on each other — they run in parallel. Step 6 waits for 3, 4, and 5. |
| Q5 | Skip: fast failure for non-critical steps. Retry: transient errors (network, rate limit). Re-plan: structural failure (tool doesn't exist, wrong approach). |
| Q7 | Free-text plans cannot be parsed reliably. The Executor needs structured data to call tools with correct parameters. |
| Q9 | Add "maximum 8 steps" constraint and "combine related operations into single steps" instruction. |
| Q15 | Validate source diversity: check unique source count >= 3. Use validateResearch() function before passing to Writer. |
| Q16 | The Writer hallucinated from its training data. Fix: add "Use ONLY the facts below — if a fact is not listed, do NOT include it" to the Writer prompt. Detect: compare Writer output facts against Researcher output facts programmatically. |
| Q17 | Researcher: temperature 0 (factual, precise). Writer: temperature 0.3-0.5 (readable, slightly creative prose). |
| Q24 | Critic prompt is too vague. Fix: add explicit rubric with numbered criteria and specific score anchors ("8 = all criteria met, no critical issues"). Use temperature 0 for the Critic. |
| Q25 | Diminishing returns — a 0.5-point improvement likely does not justify another iteration costing ~$0.025. Stop if delta < 1.0. |
| Q28 | Legal: threshold 9/10, max 3 iterations, cost $0.075/doc. Threshold below 9 risks legal errors. Max 4+ has diminishing returns. |
| Q33 | Code agent at temp 0.9 produces creative but incorrect code. Creative writing agent at temp 0 produces flat, boring prose. |
| Q36 | Router call with GPT-4o-mini: ~$0.00015/call. GPT-4o: ~$0.003/call. At 100K/day: $15/day vs $300/day — 20x cheaper. |
| Q37 | Router: selects which agent handles the request. Function calling: selects which tools the agent uses. They operate at different levels. |
| Q40 | Intent distribution, confidence histogram, classification latency, handler latency, fallback rate. |
| Q43 | Router classifies as "research_and_write". Dispatches to Planner-Executor. Planner creates: (1) Research step (Researcher agent), (2) Write step (Writer agent), (3) Review step (Critic-Refiner loop). |
<- Back to 4.16 — Agent Design Patterns (README)