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:
| Component | Purpose |
|---|---|
| Input | Data from the previous step or initial parameters |
| Action | The tool call that does the work |
| Output | Data passed to the next step |
| Error handler | What to do if this step fails |
| Rollback | How to undo this step if a later step fails |
Error Handling Strategies
Different errors need different responses:
| Error Type | Example | Strategy |
|---|---|---|
| Transient | API timeout, rate limit | Retry with exponential backoff (max 3 attempts) |
| Permanent | File not found, permission denied | Log error, skip item, continue workflow |
| Critical | Safety rule violation, budget exceeded | Halt workflow immediately, alert user |
| Partial | 8 of 10 files processed, 2 failed | Complete 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:
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:
Example: File Management Workflow
Here's a practical 3-step workflow:
| Step | Tool | Input | Output | On Error |
|---|---|---|---|---|
| 1. Scan | file-organizer | downloads.json | categorized file list | Halt — can't proceed without files |
| 2. Organize | file-organizer | categorized list | move results | Rollback moves, report |
| 3. Report | report-generator | move results | summary document | Log 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:
Key Takeaways
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