Sequential pipeline
Steps run one after another. Each step receives the previous step’s output via{{.previous}}.
{{.input}}— the original input passed toSequential{{.previous}}— the output of the preceding step- The template argument is optional. Omitting it passes the previous step’s output verbatim.
- Step failures wrap the step name:
step "write": ...
Parallel fan-out
All agents run concurrently. Results are collected when all finish.Parallel always returns all results — a failed branch never cancels siblings.
ParallelResults convenience methods:
| Method | Description |
|---|---|
.Get(name) | Returns the ParallelResult for a branch and whether it was found. |
.FirstError() | Returns the first non-nil branch error, or nil if all succeeded. |
.Outputs() | Returns map[string]string of branch name → output for successful branches only. |
for _, r := range results loops still compile — ParallelResults is []ParallelResult.
Router
ARouter dispatches a message to one of several named agents. Useful for building supervisor patterns where different agents handle different types of requests.
Function-based routing
Pick the route with your own logic — zero LLM overhead:LLM-based routing
Let a supervisor agent decide which route to use. The supervisor receives the input and a formatted list of available agents:Default route
Set a fallback route that is used when the picker returns an unrecognised name:WithDefault is chainable and returns *Router. If the default route name itself is not registered, the error falls through normally.
Behaviour
- Session namespacing — each route runs under
sessionID:routeName, so agents maintain independent history across calls. - LLM response normalisation — the supervisor response is trimmed, lowercased, and stripped of quotes to handle common LLM formatting quirks.
- Supervisor session — the LLM supervisor always uses the fixed session
router:supervisorso routing decisions don’t pollute conversation history. - Unknown route error — returns a clear error listing available route names (skipped when a valid default route is set).
Combining patterns
Router composes naturally with Sequential and Parallel:Conditional branching
Run different agents depending on a predicate applied to the input:sessionID:if and sessionID:else so each branch maintains independent memory.
Passing nil as the else-agent returns the original input unchanged when the predicate is false.
Loops
Repeatedly run an agent while a condition holds, up to a maximum iteration count:- The condition function receives the current iteration index (0-based) and the latest output.
- Each iteration runs under session
sessionID:loop-Nfor isolated history. - When
maxIteris exhausted the loop exits with the last output (no error). - Context cancellation propagates immediately from the inner agent call.
Streaming
UseRunStream for real-time output: