Pattern 1: ReAct (Reason + Act)
The foundational agent pattern. Think, then act, then observe.
Loop:
1. Thought: "I need to find the user's order status"
2. Action: call get_order_status(order_id="12345")
3. Observation: "Order shipped, tracking: UPS123"
4. Thought: "I have the answer"
5. Final Answer: "Your order was shipped. Tracking: UPS123"When: Single-step tool use, Q&A with data lookup.
result = agent.run("What is the status of order 12345?",
tools=[get_order_status, search_products])Pattern 2: Plan-and-Execute
Separate planning from execution for complex tasks.
1. PLAN: Break task into steps
- Step 1: Analyze current database schema
- Step 2: Design new tables for feature X
- Step 3: Write migration scripts
- Step 4: Update API endpoints
- Step 5: Add tests
2. EXECUTE: Run each step
- [Step 1] Reading schema... done
- [Step 2] Designing tables... done
- ...
3. REPLAN: Adjust if needed
- Step 3 revealed a dependency -> add Step 3.5When: Multi-file code changes, research tasks, project-level work.
Pattern 3: Reflection
Agent reviews and improves its own output.
1. Generate: Write first draft of code
2. Reflect: Review for bugs, edge cases, style
3. Improve: Fix identified issues
4. Reflect again: Check improvements
5. Final: Output polished resultWhen: Code generation, writing, any quality-sensitive output.
draft = agent.generate(task)
critique = agent.reflect(draft, criteria=["correctness", "style", "edge_cases"])
final = agent.improve(draft, critique)Pattern 4: Tool Use
Agent selects and uses external tools to accomplish tasks.
Available tools:
- search_web(query) -> results
- run_sql(query) -> data
- send_email(to, subject, body)
- create_file(path, content)
Agent decides which tool(s) to call based on the task.When: Any task requiring external data or actions. Foundation of most agents.
Pattern 5: Multi-Agent
Multiple specialized agents collaborate.
Supervisor Agent
-> Research Agent (web search, data gathering)
-> Coding Agent (write code, run tests)
-> Review Agent (check quality, security)
-> Deploy Agent (CI/CD, monitoring)Frameworks: CrewAI, AutoGen, LangGraph, Mastra.
When: Complex workflows with distinct specialist roles.
Pattern 6: Human-in-the-Loop
Agent pauses for human approval at critical points.
Agent: "I plan to delete the old database table. Approve? [Y/N]"
Human: "Y"
Agent: proceeds with deletion
Agent: "I want to send this email to 500 customers. Approve?"
Human: "N - change the subject line first"
Agent: revises and asks againWhen: Destructive operations, external communications, financial transactions.
Pattern 7: Code Agent
Agent writes and executes code to solve problems.
Task: "Analyze this CSV and find outliers"
Agent writes Python:
import pandas as pd
df = pd.read_csv("data.csv")
outliers = df[df["value"] > df["value"].mean() + 2*df["value"].std()]
print(f"Found {len(outliers)} outliers")
Agent executes the code and returns results.Frameworks: Smolagents (Code Agent mode), OpenHands.
When: Data analysis, math, any task where code is more precise than natural language.
Pattern 8: Memory-Augmented
Agent stores and retrieves memories across sessions.
Session 1: "We decided to use PostgreSQL for this project"
-> Stored in memory
Session 2: "Set up the database"
-> Recalls: "We chose PostgreSQL"
-> Acts accordinglyTools: Engram, Mem0, CLAUDE.md files.
When: Long-running projects, personalized assistants, knowledge management.
Choosing the Right Pattern
Simple question + tool? -> ReAct
Complex multi-step? -> Plan-and-Execute
Quality matters? -> Add Reflection
Multiple specialists? -> Multi-Agent
Safety critical? -> Add Human-in-the-Loop
Data/math heavy? -> Code Agent
Cross-session context? -> Memory-AugmentedMost production agents combine 2-3 patterns.
FAQ
Q: Which pattern should I start with? A: ReAct + Tool Use. It covers 80% of use cases. Add other patterns as needed.
Q: Can I combine patterns? A: Yes, most production agents use 2-3 patterns. Example: Plan-and-Execute + Reflection + Human-in-the-Loop.
Q: Which frameworks implement these patterns? A: LangGraph (all patterns), CrewAI (Multi-Agent), AutoGen (Multi-Agent), Smolagents (Code Agent), Claude Code (ReAct + Plan-and-Execute + Tool Use).