Module 8 Lesson 3: Task Decomposition
·Agentic AI

Module 8 Lesson 3: Task Decomposition

Breaking it down. How to turn a complex project into a set of discrete, delegated Tasks in CrewAI.

Task Decomposition: The Art of Delegation

In Module 3, we learned about the Planner–Executor pattern. CrewAI formalizes this through the Task object. You don't give the whole project to the "Crew"; you give a Sequence of Tasks that move from one agent to the next.

1. What is a "Task"?

A Task in CrewAI is a specific "Assignment." It includes:

  • Description: Detailed instructions on what to do.
  • Expected Output: A clear definition of what to return (e.g., "A 3-paragraph summary").
  • Agent: The specific persona assigned to this work.

2. Passing the Baton

One of the most powerful features of CrewAI is that the Output of Task A automatically becomes the Input of Task B.

graph LR
    T1[Task 1: Research] --> T2[Task 2: Analyze]
    T2 --> T3[Task 3: Write]
    T3 --> T4[Task 4: Review]

Why this works:

The Writer agent (Task 3) doesn't have to worry about "Searching." It can assume that Task 1 and 2 have already provided it with a clean, high-quality "Context" of data.


3. Code Example: Defining Tasks

from crewai import Task

research_task = Task(
  description='Analyze the current stock market trends for Apple (AAPL) in 2024.',
  expected_output='A bulleted list of the top 5 events affecting the stock price.',
  agent=researcher
)

summary_task = Task(
  description='Based on the research provided, write a brief update for the CEO.',
  expected_output='A 100-word summary emphasizing the risks.',
  agent=writer
)

# Crucial: Task 2 depends on Task 1's result.

4. The "Expected Output" Trick

If you want your agent to return data for a computer to read (like JSON), you specify it in the expected_output.

Pro Tip: You can use the output_json or output_pydantic parameters in CrewAI to force the agent to return a structured Python object rather than a string of text.


5. Visualizing the Decomposition

GoalTask 1 (Research)Task 2 (Analysis)Task 3 (Drafting)
InputURLSearch ResultsAnalysis Report
OutputRaw TextClean CSVWord Doc

Key Takeaways

  • Tasks are discrete units of work assigned to specialized agents.
  • Decomposition reduces the "Context Burden" on any single agent.
  • Sequential flow allows agents to build upon each other's work.
  • Clearly defining the Expected Output is the best way to prevent vague agent responses.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn