1.2 — Task Decomposition Logic
Task Decomposition Logic: Teaching AI to Think Like an Engineer
If you ask an AI to "Build a CRM," it will fail. If you ask it to "Write a SQL schema for a Users table, then write a Python class to insert data, then draft an HTML form," it will succeed flawlessly.
The secret to building unstoppable autonomous systems isn't using a "smarter" model; it is mastering Task Decomposition. In this lesson, we explore the algorithmic breakdown of complex objectives into atomic, solvable nodes.
🧩 The Anatomy of a Task
An LLM is a stateless prediction engine. It struggles with long-horizon planning because the context window becomes polluted with previous outputs, leading to "attention drift."
Task decomposition solves this by enforcing Cognitive Isolation.
The Atomic Unit (The "Leaf Node")
A task is only fully decomposed when it reaches a "Leaf Node" state. A Leaf Node has:
- Zero Ambiguity: The agent knows exactly what success looks like.
- Singular Focus: It requires only one primary tool or one specific type of reasoning.
- Deterministic Verification: A separate deterministic script (or another agent) can definitively say "Yes, this is complete."
Example: "Launch a Podcast"
- ❌ Bad Prompt: "Research, write, and generate audio for a podcast episode about AI." (Agent will hallucinate, skip steps, or produce shallow garbage).
- ✅ Decomposed Graph:
Node 1 (Scraper):Fetch top 5 trending AI news articles from HackerNews RSS. (Output: Array of URLs)Node 2 (Reader):Extract text from URLs and summarize key technical shifts. (Output: JSON array of summaries)Node 3 (Writer):Draft a 3-act podcast script using the summaries. Apply 'Irfan Junejo' voice guidelines. (Output: Markdown script)Node 4 (Audio Gen):Pass script chunks to ElevenLabs API asynchronously. (Output: .mp3 files)Node 5 (Compiler):Stitch .mp3 files together using FFmpeg. (Output: final_podcast.mp3)
🧠 Algorithmic Decomposition: The 'Tree of Thoughts' Approach
Elite systems don't just hardcode the breakdown; they use an LLM (like Gemini 2.5 Pro) as a Planner Agent to dynamically generate the execution graph at runtime.
Here is the system prompt architecture for a Master Planner Agent:
SYSTEM PROMPT: THE ARCHITECT
You are an elite Staff Software Engineer. Your only job is Task Decomposition.
The user will provide a complex, vague objective.
You will not execute the objective. You will break it down into a Directed Acyclic Graph (DAG) of atomic sub-tasks.
RULES FOR DECOMPOSITION:
1. Every task must be achievable by a single narrowly-scoped AI agent in under 30 seconds.
2. Clearly define the required INPUT (dependencies) and expected OUTPUT schema for each task.
3. Tasks that do not depend on each other must be marked as 'parallelizable'.
OUTPUT FORMAT (Strict JSON):
{
"execution_plan": [
{
"task_id": "T1",
"description": "...",
"required_tools": ["SerpAPI"],
"dependencies": [],
"expected_output_schema": "{ 'urls': 'list of strings' }"
},
{
"task_id": "T2",
"dependencies": ["T1"] // Cannot start until T1 finishes
}
]
}
⚙️ Advanced Execution: The Context Injection Strategy
When executing a decomposed plan, never pass the entire context history to every agent. This is the most common mistake novice developers make. It wastes tokens and confuses the model.
The Principle of Least Privilege:
- Agent T2 only receives the specific
expected_outputgenerated by Agent T1. - It does not receive the original user prompt or the internal monologue of the Planner Agent.
- By scoping the context strictly to the immediate inputs, you enforce surgical precision.
Practice Lab: Building the Dependency Graph
- The Goal: "Write and deploy a fully functional Next.js landing page with a working Stripe checkout."
- The Lab: Manually decompose this goal into at least 7 distinct atomic tasks.
- The Constraint: Map out the dependencies. Which tasks can be run in parallel (e.g., generating the copy vs. scaffolding the Next.js app), and which are strictly sequential?
📺 Recommended Videos & Resources
-
LangGraph: Stateful Multi-Step Reasoning — Build directed acyclic graphs (DAGs) for agent task execution
- Type: Documentation
- Link description: Visit github.com/langchain-ai/langgraph for tutorials
-
AutoGen Task Decomposition — Microsoft AutoGen's approach to breaking down complex objectives
- Type: Documentation
- Link description: Search "AutoGen task planning" on Microsoft's AutoGen site
-
Tree of Thoughts: Exploring the Cosmos — How LLMs think hierarchically about complex problems
- Type: Research Paper
- Link description: Search arXiv for "tree of thoughts llm planning"
-
Building an AI Decomposition Engine for Karachi Agencies — Real-world tutorial for Pakistani automation use cases
- Type: YouTube
- Link description: Search YouTube for "LLM task decomposition tutorial 2025"
-
Dependency Graph Visualization — Graphviz tool for visualizing task DAGs
- Type: Tool
- Link description: Visit graphviz.org to learn ASCII/graph rendering
🎯 Mini-Challenge
Decompose a Real Pakistani Business Process (5 minutes)
Your mission: Break down this objective into 5 atomic tasks:
"Launch a LinkedIn cold email campaign targeting 50 Pakistani SaaS CTOs in 48 hours"
For each task, write:
- Task ID (T1, T2, T3...)
- What tool/agent handles it
- What the output schema is
- Which tasks can run in parallel
Hint: Can you scrape LinkedIn profiles AND write email templates at the same time? Yes. Can you send emails before writing them? No.
🖼️ Visual Reference
📊 Task Decomposition Dependency Graph
User Goal: "Launch LinkedIn Campaign"
│
↓
┌────────────────────┐
│ Planner Agent │
│ (Decomposer) │
└─────────┬──────────┘
│
┌─────────┴──────────┐
│ │
↓ ↓
┌────────┐ ┌────────┐
│ T1: │ │ T2: │ (PARALLEL)
│Scrape │ │ Write │
│Profiles│ │ Templates
└────┬───┘ └────┬───┘
│ │
└─────────┬──────────┘
↓
┌─────────┐
│ T3: │
│ QC │
│ Emails │
└────┬────┘
↓
┌─────────┐
│ T4: │
│ Deploy │
│ via API │
└─────────┘
Homework: Automated Decomposition
Write a small Python script utilizing the google-generativeai SDK.
Send a massive, vague goal (e.g., "Build an automated competitor analysis pipeline") to Gemini 2.5 Pro.
Force the model to return a strict JSON array of 5 decomposed tasks, complete with task_id, description, and dependencies.
Bonus: Write a parsing function that visually prints this graph to the terminal.
Lesson Summary
Quiz: Task Decomposition Logic
5 questions to test your understanding. Score 60% or higher to pass.