Planning and task decomposition
What Is Task Decomposition?
WHY do we need it?
- Complexity management: A single LM call has a fixed context window and limited effective reasoning depth per forward pass—while chain-of-thought prompting lets a model reason over many steps, an agent that must call external tools (search, code, APIs) cannot fit all those interactions into one pass. Decomposition spreads the work across multiple grounded steps.
- Failure isolation: If subtask 3 fails, you don't restart from scratch—just retry that branch.
- Paralelization: Independent subtasks can run concurrently (e.g., fetch from 3 APIs simultaneously).
- Interpretability: The plan is human-readable; you see why the agent took each step.
HOW does it work? The agent uses one of three strategies:
- Hierarchical planning: Top-down recursion (goal → subgoals → primitive actions).
- Forward chaining: Start from current state, apply actions until goal is reached.
- Backward chaining: Start from goal, work backward to find required preconditions.
Derivation: Why Decomposition Reduces Search Space
Problem: Given a goal and possible actions at each step, naive search over depth has complexity .
Insight: If we decompose into independent subgoals , each requiring depth , the complexity becomes:
Derivation:
- Without decomposition: Explore all paths to depth .
- With decomposition:
- Solve in paths.
- Solve independently in paths.
- Total: paths.
- Why is this better? For :
- Naive: paths.
- Decomposed: paths.
The exponential becomes linear in when subgoals are independent.
Planning Strategies in Detail
1. Hierarchical Task Network (HTN) Planning
HTN planning decomposes tasks using a hierarchy of methods: each complex task has multiple refinement rules.
Algorithm:
function HTN-Plan(task, state):
if task is primitive:
return [action(task)]
else:
for each method m that decomposes task:
subtasks = m.decompose(task, state)
subplans = [HTN-Plan(st, state) for st in subtasks]
if all subplans succeed:
return concatenate(subplans)
return FAIL
Example: Goal: "Prepare coffee"
- Method 1: [Boil water, Grind beans, Brew]
- Method 2 (if no grinder): [Boil water, Use instant coffee]
The agent checks state.has_grinder and picks a method.
Why this step? Checking state ensures the plan is feasible given current resources.
Decomposition (forward chaining):
- Search for earthquake data API → finds USGS API.
- Fetch data for 2023 → HTTP GET request.
- Parse JSON → extract magnitude field.
- Plot histogram → call matplotlib.
- Return image to user.
Each step's output feeds the next. If step 2 fails (API down), retry or switch to CSV fallback.
2. ReAct: Reasoning + Acting
ReAct interleaves thought (reasoning about what to do) and action (tool use).
Pattern:
Thought: I need to find the current population of Tokyo.
Action: search("Greater Tokyo Area population 2026")
Observation: ~37 million (Greater Tokyo Area, world's largest metro)
Thought: Now compare to the New York metro area.
Action: search("New York metropolitan area population 2026")
Observation: ~19.5 million
Thought: Tokyo is larger by ~17.5 million.
Answer: The Greater Tokyo Area (~37M) is roughly 90% larger than the New York metro area (~19.5M).
Why "Thought"? It makes the next action grounded in the current subgoal, not random tool spam. Note on units: always specify which boundary you mean—city proper (Tokyo ~14M) vs. metro area (Greater Tokyo ~37M)—or the comparison is meaningless.
Plan (backward chaining):
- Need: Grammy winner in year .
- To get : release year of 1989.
- Action 1:
search("1989 Taylor Swift release year")→ 2014. - Action 2:
search("Grammy Album of the Year 2015")→ Morning Phase by Beck (awarded in 2015 for 2014 albums). - Answer: Beck.
Why this order? We can't ask for the Grammy winner until we know the year.
3. LM-Modulo Framework
Combines LLM's creativity with external verifiers (solvers, simulators).
Loop:
- LM proposes a plan .
- Verifier checks (e.g., run code, check constraints).
- If valid, execute . Else, LM refines based on error feedback.
Example: Planning robot actions in a kitchen.
- LLM: "Pick up mug, pour coffee, place mug on table."
- Verifier (physics sim): "Collision! Mug is inside table."
- LLM (revision): "Pick up mug, move to position above table, lower mug, release."
Why this step? The verifier catches infeasible plans before real execution (safety-critical for robots).
Common Mistakes
Example:
- Bad: "Add 2+2" → [Parse input, Identify operation, Execute addition, Format output]
- Good: Just call
calculate(2+2).
Example:
- Goal: "Summarize paper X and compare to paper Y."
- Subtasks:
- : Fetch paper X.
- : Fetch paper Y.
- : Summarize X (depends on ).
- : Summarize Y (depends on ).
- : Compare summaries (depends on ).
- Correct order: Run , then , then .
Example:
- Plan: [Search Wikipedia, Extract info, Cite source]
- Failure: Wikipedia returns "Page not found."
- Replan: [Search Google Scholar, Download PDF, Extract info, Cite source]
Active Recall Flashcards
#flashcards/ai-ml
What is task decomposition in AI agents? :: Breaking a complex goal into a DAG of simpler, executable subtasks with clear dependencies.
Why does decomposition reduce search complexity?
What is hierarchical task network (HTN) planning?
What is the ReAct pattern?
What is the LLM-Modulo framework?
What is adaptive decomposition?
Why must we build a dependency graph for subtasks?
What is replanning in agent systems?
What is forward chaining in planning?
What is backward chaining in planning?
Recall Explain to a 12-Year-Old
Imagine you want to build a huge LEGO castle, but you've never done it before. If you just start randomly sticking bricks together, you'll get stuck or make a mess. Instead, you make a plan:
- Break it down: "I'll build the base first, then the walls, then the towers, then the roof."
- Order matters: You can't put the roof on before the walls exist! So you do them in sequence.
- Check as you go: After building the base, you check—does it look right? Is it strong enough? If not, fix it before moving on.
- If something breaks: Say a tower falls over. You don't throw away the whole castle! You just rebuild that tower.
That's exactly what AI agents do with big tasks. They split them into steps, do them in order, check their work, and fix mistakes. Without a plan, the AI would just guess randomly and probably fail. With a plan, it's like having LEGO instructions—it knows exactly what to do next.
Connections
- 6.2.01-Tool-augmented-LMs: Task decomposition determines when and which tools to call.
- 6.2.03-Multi-agent-systems: Each agent can have its own planner; coordination requires planning at the team level.
- 5.3.02-Chain-of-thought-prompting: CoT is single-call multi-step reasoning; agent planning adds external actions interleaved with reasoning.
- 6.2.05-Memory-in-agents: Long-term memory stores past plans and outcomes to improve future decomposition.
- 8.1.03-Reasoning-under-uncertainty: Plans must account for uncertain outcomes (use probability over actions).
- Classical AI: HTN planning from STRIPS (1971), means-ends analysis from Newell & Simon (1961).
Key Takeaway: Planning transforms an intractable search problem into a structured, verifiable process. The agent's intelligence lies not just in acting, but in deciding what to do next and recognizing when to revise.
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Chalo, ise ek simple tarike se samajhte hain. Task decomposition ka core idea yeh hai ki AI agent ko jab koi bada aur complex goal diya jaye — jaise "research question ka answer do" — toh woh usko chhote-chhote executable steps mein tod deta hai, jaise "papers search karo → key claims nikalo → findings ko jodo". Bilkul waise jaise ek lambi road trip ko aap gas stops, hotel booking aur route checkpoints mein baant dete ho. Agar aap decomposition nahi karoge, toh agent ya toh confuse hoke atak jaayega (bahut complex hai!) ya phir randomly sab kuch try karta rahega. Isliye directed acyclic graph (DAG) banana zaroori hai, jahan har subtask ke clear inputs, outputs aur dependencies ho.
Ab yeh matter kyun karta hai? Sabse bada reason hai search space ka kam ho jaana. Socho, agar har step pe possible actions hain aur depth hai, toh naive search ki complexity hoti hai — jo exponentially badh jaati hai. Lekin agar goal ko independent subgoals mein tod do, toh complexity ho jaati hai. Example dekho: par naive search mein 10 lakh paths lagte, par decomposition ke saath sirf 300 paths! Yeh exponential se linear ka jaadu hai. Iske alawa failure isolation milta hai (agar subtask 3 fail ho toh sirf usko retry karo, poora restart nahi), independent tasks ko parallel chala sakte ho, aur plan human-readable hota hai toh aap samajh sakte ho ki agent ne har step kyun liya.
Practical mein teen strategies use hoti hain: Hierarchical planning (top-down, goal ko subgoals aur phir primitive actions mein todna), Forward chaining (current state se shuru karke goal tak pahunchna), aur Backward chaining (goal se ulta chalke required preconditions dhoondhna). Jaise HTN planning mein "coffee banao" goal ke liye agent state check karta hai — agar grinder hai toh beans grind karega, warna instant coffee use karega. Real example mein GPT-4 + Code Interpreter earthquake data plot karne ke liye pehle API search karta hai, phir data fetch, parse, aur matplotlib se histogram banata hai — har step ka output agle step mein jaata hai. Yahi hai smart agents ka asli dimaag, dost — bade problem ko manageable pieces mein todna.