Planning, Reasoning & Decision Making
From the course AI Agents: Building Autonomous Systems
The intelligence of an agent comes from its ability to plan multi-step tasks, reason about complex situations, and make good decisions under uncertainty.
Planning Strategies
Upfront planning: Generate a complete plan before executing any steps.
- Advantages: Coherent strategy, predictable behavior
- Disadvantages: Plans may not survive contact with reality
- Best for: Well-understood tasks with predictable steps
Incremental planning: Plan one step ahead, execute, then plan the next step.
- Advantages: Adapts to unexpected results
- Disadvantages: May lose sight of the overall goal
- Best for: Exploratory tasks with uncertain outcomes
Hybrid planning: Create a high-level plan, then plan details for each step as you reach it.
- Advantages: Strategic coherence with tactical flexibility
- Disadvantages: More complex to implement
- Best for: Most real-world agent tasks
Implementation with LangGraph
from langgraph.graph import StateGraph
from typing import TypedDict, Annotated
class PlanExecuteState(TypedDict):
input: str
plan: list[str]
current_step: int
results: list[str]
final_response: str
def planner(state: PlanExecuteState):
"""Generate a multi-step plan."""
plan = llm.invoke(f"""
Create a step-by-step plan to accomplish: {state['input']}
Return as a numbered list. Each step should be a single, actionable task.
""")
return {"plan": parse_steps(plan)}
def executor(state: PlanExecuteState):
"""Execute the current step."""
step = state["plan"][state["current_step"]]
result = agent_with_tools.invoke(step)
return {
"results": state["results"] + [result],
"current_step": state["current_step"] + 1,
}
def replanner(state: PlanExecuteState):
"""Review progress and adjust plan if needed."""
assessment = llm.invoke(f"""
Original plan: {state['plan']}
Completed steps and results: {list(zip(state['plan'][:state['current_step']], state['results']))}
Should we continue with the remaining plan, modify it, or are we done?
""")
return update_plan(state, assessment)
Reasoning Techniques
Chain-of-thought: Force the agent to think step by step before acting. Dramatically improves complex reasoning.
Self-reflection: After completing a subtask, ask the agent to evaluate its own output:
- "Is this result correct and complete?"
- "Did I miss anything?"
- "Should I approach this differently?"
Decomposition: Break complex problems into simpler sub-problems:
- "What are the independent components of this task?"
- Solve each component separately
- Combine results
Handling Uncertainty
Agents must handle situations where they're not sure what to do:
- Confidence scoring: Have the agent rate its confidence (1-10) and escalate when low
- Fallback strategies: Define what to do when the primary approach fails
- Ask for clarification: When the task is ambiguous, ask the user rather than guessing
- Bounded exploration: Set limits on how many approaches to try before giving up
Key Takeaways
- •Hybrid planning (high-level plan + step-level detail) works best for most real-world tasks
- •Self-reflection after each step catches errors before they compound
- •Chain-of-thought prompting dramatically improves agent reasoning on complex tasks
- •Handle uncertainty with confidence scoring, fallbacks, and strategic clarification requests
Progress is kept in this browser only.