Skip to main content
Use a Workflow when your application defines the sequence. This example computes an order total and routes larger orders for review. It runs locally without a model, network connection, or order-service side effect.

Run an order-review pipeline

Use the supported Node runtime. In an empty directory, install the matching core package and a TypeScript runner:
Save as review-order.ts:
review-order.ts
Expect totalCents: 5000 and route: "standard". Change quantity to 4; the route becomes review. This is a routing decision, not a human approval or submitted order. Change it to 0 and verify the program exits with an error after inspecting step results. The function-only Workflow owns no model clients or stores to close. If you add Agents, stores, or service clients, the host must close those resources after the workflow settles.

Add a model only where judgment is needed

Host function: pass a configured model and trusted order summary. A named Agent step writes its text to <step-name>_output; declare that field in the state type. The function owns and closes the Agent.
Do not use a model for totals your application can compute exactly. Evaluate whether the drafted reply preserves the trusted facts with the quality-gate pattern.

Choose concurrency and failure behavior

A resolved workflow.run() promise is not by itself proof that every step succeeded. Inspect stepResults; cancellation or other failures can also reject the call. Validate external input before merging it into trusted state.

More patterns