Step fallbacks
Step fallbacks route a failed primary step to a backup step instead of failing the entire workflow immediately. You set fallback_step_id on a StepDefinition to point at another step id in the same workflow. When the primary agent fails in a way that triggers fallback, the engine activates the fallback step and emits StepFallbackActivated in the trace.
Fallbacks complement Retry and backoff: retry handles transient provider errors; fallback handles "try a cheaper model" or "escalate to a specialist agent" patterns after primary failure or alongside retry exhaustion.
When to use fallbacks
| Scenario | Primary | Fallback |
|---|---|---|
| Model tier degradation | GPT-4 class agent | Faster mini model |
| Specialist escalation | General support agent | Domain expert agent |
| Tool-heavy vs text-only | Agent with tools | Text-only summarizer |
Fallback is not a substitute for Graph workflows routing. It activates on step failure, not on conditional output.
Workflow configuration
In this layout, step 010 primary agent 020 falls back to step 012 (agent 022) on qualifying failure. Step 011 has no fallback. The fallback step's order value still participates in linear sort when the fallback path is not taken; when fallback activates, the engine runs the fallback step's agent in place of terminal failure.
Both primary and fallback agents must be defined in the run's agents array.
Agent definitions for primary and fallback
See Defining agents and Provider configuration.
Trace sequence
When fallback activates:
If the fallback step also fails and has no further fallback, the workflow terminal state is Failed with the last error_code (for example StepExecutionFailed or ProviderError per Error codes).
Combining with retry
Workflow or step retry may run before fallback triggers. Typical flow: transient error → RetryAttempted → success, or RetryExhausted → fallback if configured.
Step-level retry_policy on the primary step overrides or merges per engine rules; validate behavior in Validation and testing with exec_config.test.
Test mode for fallback paths
Drive primary failure without live LLM:
Expect StepFallbackActivated then completion with fallback output.
Graph workflows
Fallback steps work on graph-backed steps referenced by nodes. Failure at a node step may activate that step's fallback_step_id before the scheduler evaluates outgoing edges. Test graph + fallback combinations in CI; edge routing after fallback depends on which step id completed.
Examples
Resilience samples under examples/ demonstrate fallback patterns alongside retry. Compare with Recovery and resume for run-level persistence, not step-level alternate agents.