Autonomous FutureModule 1

1.2Task Decomposition Logic

25 min 2 code blocks Practice Lab Homework Quiz (5Q)

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:

  1. Zero Ambiguity: The agent knows exactly what success looks like.
  2. Singular Focus: It requires only one primary tool or one specific type of reasoning.
  3. 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:
    1. Node 1 (Scraper): Fetch top 5 trending AI news articles from HackerNews RSS. (Output: Array of URLs)
    2. Node 2 (Reader): Extract text from URLs and summarize key technical shifts. (Output: JSON array of summaries)
    3. Node 3 (Writer): Draft a 3-act podcast script using the summaries. Apply 'Irfan Junejo' voice guidelines. (Output: Markdown script)
    4. Node 4 (Audio Gen): Pass script chunks to ElevenLabs API asynchronously. (Output: .mp3 files)
    5. 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:

text
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_output generated 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

Practice Lab: Building the Dependency Graph

  1. The Goal: "Write and deploy a fully functional Next.js landing page with a working Stripe checkout."
  2. The Lab: Manually decompose this goal into at least 7 distinct atomic tasks.
  3. 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

🎯 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

code
📊 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

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

Includes hands-on practice labHomework assignment included2 runnable code examples5-question knowledge check below

Quiz: Task Decomposition Logic

5 questions to test your understanding. Score 60% or higher to pass.