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.
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.
A task is only fully decomposed when it reaches a "Leaf Node" state. A Leaf Node has:
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)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
}
]
}
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:
expected_output generated by Agent T1.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.