Agentic Design Patterns
Planning Pattern
3 min read
Complex tasks require breaking down into manageable steps. The planning pattern enables agents to decompose problems, create execution strategies, and adapt as they learn more.
Task Decomposition
When faced with a complex request, agents can plan before acting:
# Planning pattern implementation
def plan_and_execute(task):
# Step 1: Create a plan
plan = llm.generate(f"""
Task: {task}
Break this into specific, actionable steps:
1. [First step]
2. [Second step]
...
For each step, identify:
- What action to take
- What information is needed
- How to verify success
""")
# Step 2: Execute each step
results = []
for step in parse_plan(plan):
result = execute_step(step)
results.append(result)
# Step 3: Adapt if needed
if needs_replanning(result):
plan = replan(task, results)
return synthesize_results(results)
Planning Strategies
| Strategy | Best For | Example |
|---|---|---|
| Linear | Sequential tasks | Data processing pipeline |
| Hierarchical | Complex projects | Software development |
| Iterative | Exploratory tasks | Research, analysis |
| Conditional | Dynamic situations | Customer support |
ReAct: Reasoning + Acting
The ReAct pattern combines reasoning with action in an interleaved manner:
Thought: I need to find the company's revenue for Q3 2024
Action: search("Company X Q3 2024 revenue report")
Observation: Found earnings report showing $2.3B revenue
Thought: Now I need to compare with Q2...
Action: search("Company X Q2 2024 revenue")
Observation: Q2 revenue was $2.1B
Thought: I can now calculate the growth rate
Final Answer: Revenue grew 9.5% from Q2 to Q3 2024
When Planning Helps Most
- Multi-step tasks: Research requiring multiple sources
- Uncertain paths: When the solution approach isn't clear
- Resource-intensive: When you want to minimize API calls
- Quality-critical: When accuracy matters more than speed
Planning Pitfalls
⚠️ Over-planning: Sometimes acting quickly and adjusting is better than extensive upfront planning
- Don't plan for simple, single-step tasks
- Set planning time limits
- Allow for plan revision during execution
- Balance planning depth with task complexity
Next, we'll combine these patterns into powerful multi-step workflows. :::