Lesson 6: Real-World Workflows in Practice
Learning goals:
- Combine task decomposition, state management, and error handling to design complete workflows
- Understand the workflow patterns behind three production-grade scenarios
- Master observability and debugging techniques for workflows
Prerequisites: Lesson 5: Error Handling and Retry Strategies
From Theory to Practice
Over the first five lessons we covered the building blocks of workflows: steps, state, decomposition, and error handling. Now we'll put them together and build three production-grade workflows drawn from real scenarios.
The three workflows in this lesson:
- Code refactoring pipeline: refactor legacy code into modern patterns, covering analysis, planning, execution, testing, and verification
- Doc generation pipeline: auto-generate API docs from code, covering extraction, example generation, rendering, and publishing
- Test automation flow: an end-to-end testing workflow, covering environment setup, parallel testing, result aggregation, and report generation
Every workflow shows:
- A complete task decomposition
- State management and checkpoint design
- Error handling and recovery strategies
- Observability and debugging support1
Scenario 1: Code Refactoring Pipeline
Requirements
Refactor a legacy front-end project of 50 components from class components to function components + Hooks.
Challenges:
- The components depend on each other, so you can't refactor them in an arbitrary order
- Refactoring can break behavior, so it needs test verification
- 50 components can't be finished in a single conversation; they need parallel processing2
Task Decomposition
The workflow has 6 phases. The first two can process components in parallel; the later phases run in dependency order.
Full Implementation
Key Design Points
1. Checkpoint strategy: save after each batch completes, so you never re-refactor work
2. Parallel execution: components in the same batch can be refactored in parallel (they don't depend on each other)
3. Retry mechanism: one component's failure doesn't affect the others; use Promise.allSettled to collect every result
4. Fix loop: on test failure, automatically attempt a fix, up to 3 times
5. Observability: every phase logs clearly, and state is persisted to external storage3
Scenario 2: Doc Generation Pipeline
Requirements
Generate complete API docs for a service with 30 REST API endpoints, including endpoint descriptions, request/response examples, and error-code explanations.
Task Decomposition (fan-out/aggregate pattern)
Key characteristics:
- Fan-out/aggregate pattern: 30 endpoints generate docs in parallel, then aggregate at the end
- Stateless: the task is fast enough (< 10 minutes) that it needs no checkpoints
- Idempotent: you can rerun it any time and overwrite the output file1
Scenario 3: Test Automation Flow
Requirements
Run end-to-end tests across several environments (local, staging, production), collect test results and performance metrics, and generate a comparison report.
Full Implementation
Key characteristics:
- Parallel testing: multiple environments run their tests at the same time, cutting total time dramatically
- Fault tolerance: one environment's failure doesn't affect the others
- Smart retry: failed tests retry automatically (network blips and transient faults are common)
- Failure analysis: fix suggestions for failures are generated automatically1
Workflow Observability
A good workflow should be able to answer, at any moment:
- How far along is it? (X/Y done)
- How much longer is it likely to take?
- What errors has it hit?
- Where are the performance bottlenecks?
If you can't answer these, your logging and state tracking aren't detailed enough. Debugging a workflow rides on those records, not on guessing.
Implementing Observability
That bit inside summary() that sorts by duration and prints only the three slowest steps is the simplest form of performance profiling: measure how long each step took, then find the bottleneck from the data instead of guessing which step is slow.
Congratulations on finishing the Agent Workflow Design course.
You now have a handle on:
- The core concepts of workflows and where they fit
- The three strategies for task decomposition
- State management and the checkpoint mechanism
- Error handling and retry strategies
- Three production-grade workflows from real scenarios
Next steps:
- Practice a simple workflow (< 5 steps) in one of your projects
- Add complexity step by step (parallelism, checkpoints, error handling)
- Share your workflow design and get feedback from the community
- Explore more advanced topics (distributed workflows, workflow orchestration frameworks, visual workflow editors)