Run an order-review pipeline
Use the supported Node runtime. In an empty directory, install the matching core package and a TypeScript runner:review-order.ts:
review-order.ts
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.
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
- Step contracts and generated Workflow API.
- Time travel for explicit checkpoints and forks; external effects remain external.
- Queue workers for work that outlives an HTTP request.
- Authenticated hosting for exposing registered application behavior.