Breaking Down Tasks (Task Decomposition) › A First Example: Breaking Down a Complex Request
Michael BrenndoerferJuly 19, 20252 min read
AI Agent HandbookAll chapters Part 9 of 15Planning - Agents with a Plan
Breaking Down Tasks (Task Decomposition) › A First Example: Breaking Down a Complex RequestOne section · Sections in this chapter4 / 12 ↓
Sections in this chapter12
Let's build an agent that can decompose a multi-step request. We'll use Claude Sonnet 4.5 because of its strong reasoning capabilities, and we'll explicitly prompt it to break down the task before doing anything else.
First, we'll create a function that prompts the model to decompose a task:
In[4]:
Code## Using Claude Sonnet 4.5 for its superior agent reasoning capabilities
import os
import re
from anthropic import Anthropic
import json
client = Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
def decompose_task(user_request):
"""Ask the agent to break down a complex task into subtasks."""
prompt = f"""You are a helpful assistant that breaks down complex tasks.
User request: {user_request}
Please decompose this request into specific, actionable subtasks.
Each subtask should be concrete and done independently.
Organize them in a logical order.
Respond ONLY with a JSON list, no other text: ["subtask 1", "subtask 2", ...]"""
response = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=500,
messages=[{"role": "user", "content": prompt}]
)
text = response.content[0].text
# Extract JSON array from response (in case there's extra text)
match = re.search(r'\[.*\]', text, re.DOTALL)
if match:
return json.loads(match.group())
return json.loads(text)Now let's test it with our presentation example:
In[5]:
Codeuser_request = """Help me prepare for my client presentation next Friday.
I need to research the client's industry, create a slide deck,
practice my delivery, and send a meeting invite to the team."""
subtasks = decompose_task(user_request)
print("Decomposed Task List:")
for i, subtask in enumerate(subtasks, 1):
print(f"{i}. {subtask}")Out[5]:
ConsoleDecomposed Task List: 1. Research the client's industry trends, key competitors, and recent news 2. Identify the client's main pain points and business challenges 3. Define the presentation objectives and key messages 4. Create an outline for the slide deck structure 5. Design and build the presentation slides with content 6. Add visual elements, charts, and graphics to the slides 7. Prepare speaker notes for each slide 8. Review and proofread the entire slide deck 9. Practice the presentation delivery out loud at least twice 10. Time the presentation to ensure it fits the allocated duration 11. Prepare answers to potential questions the client might ask 12. Create a list of team members who need to attend 13. Draft the meeting invite with date, time, location, and agenda 14. Send the meeting invite to all team members 15. Send a calendar reminder for final preparation the day before
When you run this, the agent might produce:
Decomposed Task List:
1. Research the client's industry, including recent news and key trends
2. Create a slide deck based on research findings
3. Practice delivery of the presentation
4. Send a meeting invite to the team for next FridayNotice what happened here. The agent took our messy, compound request and turned it into a clean, ordered list. Each item is specific enough to guide action, and they're arranged in a sensible sequence (you wouldn't practice your delivery before creating the slides).
This is the heart of task decomposition: transforming ambiguity into clarity.