Multi-Step Workflows
Build complex workflows using subagents, task orchestration, and prompt chaining. Learn to break big jobs into coordinated steps that work reliably.
Premium Course Content
This lesson is part of a premium course. Upgrade to Pro to unlock all premium courses and content.
- Access all premium courses
- 1000+ AI skill templates included
- New content added weekly
One Agent Isn’t Enough
🔄 Quick Recall: In the previous lesson, you learned to test skills with Promptfoo and Cisco Skill Scanner. Now let’s build skills that are too complex for a single step — workflows that need multiple agents working together.
OpenObserve, a monitoring company, built 8 specialized AI sub-agents for their QA process. Each agent had a clear role: one analyzed test failures, one generated new tests, one reviewed code coverage, and so on. The result? Flaky tests dropped by 85%, and test coverage grew from 380 to 700+ tests.
The key insight: bounded agents with clear roles outperform generalist agents. Instead of one all-knowing agent, create focused specialists that work together.
Anthropic’s engineering team put it this way: “Like programming with threads, explicit orchestration of which steps get delegated to sub-agents yields the best results.”
Pattern 1: Subagents
Subagents are the primary orchestration primitive. Each runs in its own context window with:
- A custom system prompt (specific instructions)
- Specific tool access (scoped permissions)
- Independent permissions (limited blast radius)
Example: A research workflow
Your main skill orchestrates three subagents:
# Market Research Workflow
When the user asks for market research on a topic:
## Step 1: Data Gathering (Subagent)
Launch a subagent with instructions:
"Search the web for the latest data on [topic]. Find 5-10 recent
sources with statistics, market size, growth rates, and key players.
Return a structured list of findings with source URLs."
## Step 2: Competitive Analysis (Subagent)
Launch a subagent with instructions:
"Using the data gathered in Step 1, identify the top 5 competitors
in this space. For each, document: company name, market share,
key products, strengths, weaknesses."
## Step 3: Synthesis (Main Agent)
Using the outputs from Steps 1 and 2, create a final report with:
- Executive Summary (3 sentences)
- Market Overview (key stats and trends)
- Competitive Landscape (comparison table)
- Opportunities (based on competitor gaps)
- Recommended Next Steps
Each subagent works in isolation — it can’t see the other subagents’ conversations. The main agent coordinates the results.
The key constraint: Subagents cannot spawn other subagents. If Step 2 needs to delegate further, it must handle it internally or the main agent needs to break it into additional steps.
✅ Quick Check: Why run steps 1 and 2 as separate subagents instead of having one agent do all the research? (Answer: Focused subagents produce better results — the data gatherer focuses only on finding sources, the analyzer focuses only on competitive analysis. Each gets a clean context window without confusion from the other task.)
Pattern 2: Prompt Chaining
Prompt chaining is sequential processing where each step transforms the output of the previous one. Unlike subagents (which can run in parallel), chains are inherently sequential.
Example: Content pipeline
# Blog Post Pipeline
Process the user's draft through these stages:
## Stage 1: Structure Analysis
Analyze the draft for structure issues: missing introduction,
weak conclusion, unclear sections. Output a structured critique.
## Stage 2: Content Improvement
Using the critique from Stage 1, rewrite the weak sections.
Preserve the author's voice and strong sections.
## Stage 3: SEO Optimization
Using the improved draft from Stage 2, add SEO elements:
- Title tag (under 60 chars)
- Meta description (under 160 chars)
- Header optimization (H1, H2, H3)
- Keyword density check
## Stage 4: Final Review
Compare the final version with the original draft.
Output a summary of changes made at each stage.
Why chain instead of doing it all at once? Because each stage has a different focus. Mixing structure critique with SEO optimization in one prompt produces mediocre results at both. Chaining lets each stage do one thing well.
Advanced: Different models per stage. You can use a fast, cheap model for Stage 1 (structure is straightforward) and a powerful model for Stage 2 (rewriting requires nuance). This optimizes both cost and quality.
Pattern 3: Task DAGs (Directed Acyclic Graphs)
For complex workflows with dependencies, task systems let you define which steps can run in parallel and which must wait for others.
# Release Preparation
Prepare a release with these tasks:
Task 1: Run Tests → Must complete before Task 4
Task 2: Update Changelog → Must complete before Task 4
Task 3: Lint Code → Must complete before Task 4
Task 4: Build Package → Depends on Tasks 1, 2, 3
Task 5: Create Release Notes → Depends on Task 2
Task 6: Publish → Depends on Tasks 4 and 5
Tasks 1, 2, and 3 can run in parallel.
Task 4 waits for all three.
Task 5 only needs Task 2.
Task 6 waits for everything.
The agent can execute Tasks 1, 2, and 3 simultaneously, then proceed to Tasks 4 and 5, and finally Task 6. This is the fastest possible execution order while respecting dependencies.
✅ Quick Check: In the release preparation example, what happens if Task 1 (Run Tests) fails? (Answer: Task 4 (Build Package) and Task 6 (Publish) cannot proceed because they depend on Task 1. Tasks 2, 3, and 5 can still complete. The workflow reports the failure and waits for resolution.)
Design Principles for Multi-Step Skills
1. Each step should be independently testable. If you can’t test a step in isolation, it’s doing too much.
2. Define clear inputs and outputs. Step 2 should know exactly what format to expect from Step 1.
3. Handle failures at each step. What happens if the web search returns nothing? If the API is down? Don’t let one failure crash the entire workflow.
4. Minimize cross-step dependencies. The fewer connections between steps, the more robust the workflow. Tight coupling means one failure cascades everywhere.
5. Use the simplest pattern that works.
| Complexity | Use |
|---|---|
| One step | Regular skill (no orchestration needed) |
| Sequential steps | Prompt chaining |
| Parallel steps | Subagents |
| Dependencies + parallelism | Task DAGs |
| Multiple specialized roles | Subagent team with coordinator |
Real-World Example: Weekly Report Generator
Combining all patterns:
# Weekly Report Automation
## Phase 1 (Parallel Subagents):
- Subagent A: Pull completed tasks from project management tool
- Subagent B: Gather key metrics from analytics dashboard
- Subagent C: Collect team status updates from shared channel
## Phase 2 (Prompt Chain):
- Step 1: Merge all Phase 1 outputs into a single data set
- Step 2: Identify themes and highlights across the data
- Step 3: Format into the weekly report template
## Phase 3 (Main Agent):
- Review the formatted report for accuracy
- Create a 3-sentence executive summary
- Draft a delivery email with the report attached
- Save to the reports folder (DO NOT send email — draft only)
This uses subagents for parallel data gathering, prompt chaining for sequential processing, and the main agent for final assembly.
Key Takeaways
- Focused agents outperform generalists — the OpenObserve case study proved this at scale
- Subagents run in isolated context windows with scoped permissions (but can’t spawn children)
- Prompt chaining processes data sequentially — each step refines the previous output
- Task DAGs manage dependencies — parallel where possible, sequential where required
- Use the simplest pattern that solves your problem (don’t orchestrate when a single skill works)
- Every step should be independently testable with clear inputs and outputs
Up Next
Your skills are powerful. But with power comes responsibility. In the next lesson, we cover the security checklist — the 7 attack vectors that exploit skills, and how to make sure yours isn’t one of them.
Knowledge Check
Complete the quiz above first
Lesson completed!