Back to guides
5
4 min

Workflows

Multi-Step Automation Pipelines

From Single Tools to Pipelines

A single tool does a single task. A workflow chains multiple tools into an automated pipeline — scan your downloads, organize by type, summarize new documents, and send a daily report. The real power of agents comes from this composition.

But chaining actions multiplies risk. If step 1 moves a file and step 3 fails, you might lose track of where things are. Workflows need error handling, rollback logic, and safety controls that single tools don't.

Workflow Architecture

A workflow is a directed graph of steps, where each step is a tool call with inputs, outputs, and error handling:

Step 1 (scan) → Step 2 (filter) → Step 3 (process) → Step 4 (report)
                     ↓ (no files)          ↓ (error)
                   [skip]              [rollback + alert]

Each step has:

ComponentPurpose
InputData from the previous step or initial parameters
ActionThe tool call that does the work
OutputData passed to the next step
Error handlerWhat to do if this step fails
RollbackHow to undo this step if a later step fails

Error Handling Strategies

Different errors need different responses:

Error TypeExampleStrategy
TransientAPI timeout, rate limitRetry with exponential backoff (max 3 attempts)
PermanentFile not found, permission deniedLog error, skip item, continue workflow
CriticalSafety rule violation, budget exceededHalt workflow immediately, alert user
Partial8 of 10 files processed, 2 failedComplete what's possible, report failures

Never silently swallow errors. Every failure should be logged and reported, even if the workflow continues.

Rollback Logic

Rollback answers the question: "If step 3 fails, how do I undo steps 1 and 2?"

Not every action is reversible. Here's how to handle common cases:

  • File moves — record original and destination paths, move back on rollback
  • File creation — record created file paths, delete on rollback
  • API calls — generally not reversible — use compensating actions instead
  • Data modifications — create backups before modifying, restore on rollback
  • The key principle: record enough state before each step to undo it later.

    Workflow Safety Controls

    Workflows need additional safety beyond what individual tools provide:

    Timeouts — set a maximum execution time for the entire workflow. A workflow that runs forever is a workflow that's stuck.

    Max retries — limit how many times a failed step can retry. Without limits, a retry loop becomes an infinite cost generator.

    Budget tracking — track cumulative API costs across all steps. A workflow with 10 steps that each costs $0.05 adds up to $0.50 per run — which adds up to $15/month if it runs hourly.

    Human-in-the-loop — some actions should require explicit user approval:

  • Deleting more than N files
  • Spending more than $X in a single workflow
  • Sending external API calls or emails
  • Modifying files outside the working directory
  • Example: File Management Workflow

    Here's a practical 3-step workflow:

    StepToolInputOutputOn Error
    1. Scanfile-organizerdownloads.jsoncategorized file listHalt — can't proceed without files
    2. Organizefile-organizercategorized listmove resultsRollback moves, report
    3. Reportreport-generatormove resultssummary documentLog warning, workflow still succeeds

    Notice that step 3 failing doesn't require rolling back steps 1-2 — the files are already organized correctly. Error handling should be proportional to the impact.

    Testing Workflows

    Test each layer independently:

  • Unit test each tool in isolation
  • Integration test the full workflow with sample data
  • Error injection — force individual steps to fail and verify rollback
  • Budget test — verify cost tracking across all steps
  • Timeout test — verify the workflow halts when the time limit is reached
  • Key Takeaways

  • Workflows chain tools into pipelines — powerful but riskier than single tools.
  • Every step needs an error handler and rollback logic. Partial completion is often worse than none.
  • Use different strategies for transient, permanent, critical, and partial errors.
  • Add timeouts, max retries, budget tracking, and human-in-the-loop for high-risk actions.
  • Test workflows with error injection — force failures and verify the system recovers correctly.
  • This is chapter 5 of Open Source AI Agents (OpenClaw).

    Get the full hands-on course — free during early access. Build the complete system. Your projects become your portfolio.

    View course details