New to Agent Workflow? Start with the Tutorial for a progressive introduction. This page is a complete reference of all examples.
@Agent, @ExceptionHandler, AgentRegistry, and more.
Setup
All examples share thisChatClient factory:
1. Sequential Pipeline
Chain steps into a pipeline β each stepβs output flows into the next.2. Branch (Predicate Routing)
Route to different steps based on a classification result..strip().toLowerCase() on the classify output is important β LLMs sometimes return trailing whitespace or mixed case.
3. Loop (Repeat Until Output)
Iterate until a quality threshold is met. This is the most complex primitive β LLM score parsing needs care.Key finding: GPT-4.1 returns clean decimal numbers every time with the βReply with ONLY a decimal numberβ prompt. The regex fallback never fires β but itβs there for safety with other models.
4. Parallel (Fan-Out)
Run steps concurrently, collect results into a list.5. Error Recovery
Route exceptions to a recovery step instead of failing the workflow.recovery, whose output flows into finalStep as if riskyStep had succeeded. The workflow continues β it doesnβt crash.
6. Decision (LLM-Routed)
Let the LLM choose which step to execute. Unlikebranch() (predicate-based), decision() gives the LLM a menu of labeled options.
7. Gate (Quality Checkpoint)
Evaluate output quality and route to pass or fail paths.8. Supervisor (Autonomous Delegation)
The LLM autonomously selects which sub-agent to invoke each iteration.9. Sub-workflow Composition
AWorkflow implements Step β nest one workflow inside another. Context writes from the inner workflow propagate back to the outer automatically.
.then(), .branch(), .otherwise(), .onPass(), .onFail(), and .parallel(). Nesting is unlimited.
Testing Strategy
These examples demonstrate the assertion pattern for LLM-backed tests:- Shape, not exact equality β
isNotBlank(),hasSize(2), correct type - Content signals β expected keywords present (e.g., βdoctorβ for medical routing)
- Routing correctness β branch/gate took the right path
- Convergence β loops terminate within bounds
- Low temperature (0.3) β reduces variance for test stability