Agent Mentor Learn
Designing Agent Workflows: From One-Off Conversations to Multi-Step Automation · Lesson 6 of 6

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:

  1. Code refactoring pipeline: refactor legacy code into modern patterns, covering analysis, planning, execution, testing, and verification
  2. Doc generation pipeline: auto-generate API docs from code, covering extraction, example generation, rendering, and publishing
  3. 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.

mermaid
graph TD    A[Phase 1: Dependency analysis] --> B{Parallelizable?}    B -->|Yes| C[Analyze components 1-25]    B -->|Yes| D[Analyze components 26-50]    C --> E[Phase 2: Generate refactoring plan]    D --> E    E --> F[Phase 3: Refactor by batch]    F --> G[Batch 1: Leaf components]    F --> H[Batch 2: Mid-layer components]    F --> I[Batch 3: Root components]    G --> J[Phase 4: Run test suite]    H --> J    I --> J    J --> K{Tests pass?}    K -->|Yes| L[Phase 5: Generate report]    K -->|No| M[Phase 6: Fix failed components]    M --> J    L --> N[End]

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:

  1. Practice a simple workflow (< 5 steps) in one of your projects
  2. Add complexity step by step (parallelism, checkpoints, error handling)
  3. Share your workflow design and get feedback from the community
  4. Explore more advanced topics (distributed workflows, workflow orchestration frameworks, visual workflow editors)

Footnotes

  1. ClaudFlow: 7 Patterns for Claude Code Workflow Automation — https://claudflow.com/guides/claude-code-workflow-automation.html 2 3

  2. Kinde: Multi-Agent Workflows for Complex Refactoring — https://www.kinde.com/learn/ai-for-software-engineering/ai-agents/multi-agent-workflows-for-complex-refactoring-orchestrating-ai-teams/

  3. RefAgent paper: A Multi-Agent LLM Framework for Automated Software Refactoring — https://arxiv.org/html/2511.03153v1

Exercises

01

Pick a real task from your own work and design a complete workflow for it.

Level 1: Design Your Own Workflow

Requirements:

  1. Describe the task (2-3 sentences)
  2. Draw the workflow diagram (phases, branches, parallel steps)
  3. List the state fields (at least 5)
  4. Explain where you'd set checkpoints
  5. List the possible errors and how you'd handle them
Done criteria · checked locally
02

A "batch image processing" workflow fails on the 47th image, with the error message Error: EMFILE: too many open files.

Level 2: Debug a Failing Workflow

Questions:

  1. What type of error is this (transient/permanent)?
  2. Why does it fail on the 47th image rather than the 1st?
  3. How should you fix the workflow? (Give code-change suggestions.)
Done criteria · checked locally