Class: WorkflowBuilder
Defined in: packages/agentos/src/orchestration/builders/WorkflowBuilder.ts:201
Fluent builder for deterministic DAG workflows.
Steps are appended in declaration order and connected sequentially. Branch and parallel primitives fan out and automatically rejoin at the next declared step.
Call .compile() to validate the graph (must be acyclic) and obtain a
CompiledWorkflow ready for invoke(), stream(), or resume().
Constructors
Constructor
new WorkflowBuilder(
name):WorkflowBuilder
Defined in: packages/agentos/src/orchestration/builders/WorkflowBuilder.ts:220
Parameters
name
string
Human-readable workflow name.
Returns
WorkflowBuilder
Methods
branch()
branch(
condition,routes):this
Defined in: packages/agentos/src/orchestration/builders/WorkflowBuilder.ts:318
Append a conditional branch to the workflow.
The condition function is evaluated at runtime against GraphState and must
return one of the keys of routes. Each route becomes its own branch node; all
branches become the collective tail that the next declared step connects from.
Parameters
condition
(state) => string
Routing function; return value must match a key in routes.
routes
Record<string, StepConfig>
Map of route key → step config for each branch arm.
Returns
this
compile()
compile(
options?):CompiledWorkflow
Defined in: packages/agentos/src/orchestration/builders/WorkflowBuilder.ts:367
Compile the workflow into an executable CompiledWorkflow.
Compilation steps:
- Validate that
.input()and.returns()schemas were declared. - Lower each
InternalStepintoGraphNode+GraphEdgeIR objects, threadingtailNodeIdsto connect steps sequentially. - Connect all final tail nodes to
END. - Run
GraphCompiler.compile()to produce aCompiledExecutionGraph. - Run
GraphValidator.validate()with{ requireAcyclic: true }— throws on cycle. - Wrap in a
CompiledWorkflowwith aGraphRuntimebacked by the given store.
Parameters
options?
Optional compilation options.
checkpointStore?
Custom checkpoint persistence backend; defaults to InMemoryCheckpointStore.
deps?
NodeExecutorDeps
Runtime-execution dependencies forwarded to the underlying
NodeExecutor. Wire in toolOrchestrator for tool nodes,
loopController + providerCall for gmi nodes,
extensionExecutor for extension nodes, etc. Without these, the
matching node types fail with success: false.
See
WorkflowRuntimeDeps
Returns
Throws
When .input() or .returns() was not called.
Throws
When the compiled graph contains a cycle (should never happen via this API).
input()
input(
schema):this
Defined in: packages/agentos/src/orchestration/builders/WorkflowBuilder.ts:236
Declare the input schema for this workflow.
Accepts a Zod schema or any plain object; the value is forwarded to
GraphCompiler which lowers it to JSON Schema via lowerZodToJsonSchema.
Parameters
schema
any
Input schema (Zod instance or plain JSON Schema object).
Returns
this