Skip to main content

Basic Workflow

A simple linear pipeline that fetches data, processes it, and formats the output. Each step returns a partial state patch that’s merged into the running state.

Agent Steps

Use AgentStep to embed an LLM agent inside a workflow step. The inputFrom function maps workflow state to the agent’s input, and the agent’s output is stored as <stepName>_output on the state.

Conditional Branching

A step with a condition function only executes its nested steps when the condition returns true. This enables if/else-style branching based on runtime state.

Parallel Steps

A step with a parallel array runs multiple sub-steps concurrently, then merges all their state patches. Use this when steps are independent and can execute simultaneously.

Retry Policy

Configure automatic retries with exponential backoff for steps that call unreliable external services. The retry policy applies to all steps in the workflow.

Workflow with State

Typed state flows between steps, providing full type safety. Each step returns a partial patch that’s shallow-merged into the running state, so steps can build on each other’s output.

Complex Pipeline

A multi-stage content generation pipeline: research, outline, draft, review, and publish. Each stage is an AgentStep that passes its output forward through the state.

Workflow with Human Review

Pause the workflow at a specific step for human approval before continuing. The human review step calls an external system (Slack, email, dashboard) and blocks until a response is received.

Error Handling

Use try/catch inside function steps for fine-grained error handling. Combine with the workflow-level retryPolicy as a safety net, and use conditional steps to handle failures gracefully.

Workflow Registration

Workflows auto-register in the global registry by default. Use the registry to list them, run them by name, or pass them to the transport layer’s serve() function for HTTP access.