Introduction
Agents basically work in a "think 1 step, do 1 step" style. Advanced agents need to know how to plan, self-evaluate, and self-correct. This article covers the most important design patterns.
1. Plan-and-Execute Pattern
User Request → Planner (tạo plan) → Executor (thực hiện từng step) → Re-planner (adjust)
2. Self-Reflection / Critic Loop
def reflect_and_improve(agent_output, original_task):
critic_prompt = f"""
Task: {original_task}
Agent Output: {agent_output}
Evaluate:
1. Does it fully answer the task? (completeness)
2. Is the information accurate? (accuracy)
3. Is it well-structured? (quality)
If issues found, provide specific improvements.
"""
feedback = call_llm(critic_prompt)
if "APPROVED" in feedback:
return agent_output
else:
improved = call_llm(f"Improve based on feedback: {feedback}")
return improved
3. Tree-of-Thoughts
Instead of 1 chain of thought, explore multiple branches of parallel thoughts, then choose the best branch.
Summary
- Plan-and-Execute: plan first, execute later
- Self-Reflection: criticism loop improves output quality
- Tree-of-Thought: explore many reasoning paths
- Combine patterns for the strongest agent
Exercises
- Implement Plan-and-Execute agent
- Add self-reflection loop (max 3 iterations)
- Compare output quality: with vs without reflection
- Implement Tree-of-Thought for math problem solving