Skip to main content
New to Agent Workflow? Start with the Tutorial for a progressive introduction. This page is a complete reference of all examples.
Every example below is a real integration test from workflow-dsl-examples. All pass against GPT-4.1 with temperature 0.3. See also the Annotation Model example for @Agent, @ExceptionHandler, AgentRegistry, and more.

Setup

All examples share this ChatClient factory:

1. Sequential Pipeline

Chain steps into a pipeline β€” each step’s output flows into the next.
Three LLM calls in sequence: write a story, rewrite for audience, rewrite for style.

2. Branch (Predicate Routing)

Route to different steps based on a classification result.
The .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.
Both LLM calls execute concurrently. Results are ordered to match step order.

5. Error Recovery

Route exceptions to a recovery step instead of failing the workflow.
The exception routes to 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. Unlike branch() (predicate-based), decision() gives the LLM a menu of labeled options.
The DSL generates a routing prompt from the option names. GPT-4.1 returns clean single-word labels β€” no parsing issues.

7. Gate (Quality Checkpoint)

Evaluate output quality and route to pass or fail paths.
GPT-4.1 typically produces quality text, so this usually routes to APPROVED. The gate becomes more interesting with weaker models or harder tasks.

8. Supervisor (Autonomous Delegation)

The LLM autonomously selects which sub-agent to invoke each iteration.
The supervisor generates a routing prompt from agent names and descriptions. Each iteration, the LLM picks the most appropriate agent for the current state of the text. Terminates after 3 iterations.

9. Sub-workflow Composition

A Workflow implements Step β€” nest one workflow inside another. Context writes from the inner workflow propagate back to the outer automatically.
Sub-workflows can be used anywhere a step is accepted: .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

Run the Examples

Each module runs against real GPT-4.1 calls. See the tutorial for a guided walkthrough.