Skip to main content
Build a refund-review workflow with a read step and an approval-gated write step. The write only creates a simulated receipt in memory; it never contacts a payment service. Compare both outcomes before connecting a real application action.

Get the project

Download the complete TypeScript project, extract it, and run npm install in its directory. The archive includes this source, package.json, tsconfig.json, and a README. To start manually in an empty directory:

Follow the execution

The Workflow defines the sequence. workflowDriver connects its steps to the harness. The runtime grants only the two named steps; an execution policy requires approval specifically for submission. The host supplies the decision. Save as harness-workflow.ts:
harness-workflow.ts

Run both outcomes

The first run logs a denied approval and zero submissions. Its terminal reason is workflow_step_failed. The second logs an approved decision, a completed result, one submission, and a state containing simulated-refund:order-42. A denied step is visible in the result; the caller decides whether that outcome should fail a larger job. In the downloaded project, npm run check verifies types and npm start -- --approve runs the approved path.

Adapt it to your application

The command-line flag is a demonstration decision, not an authentication or approval UI. Move operator decisions into the host’s approval integration before exposing the workflow to users.

Troubleshoot and clean up

  • Step denied before the callback: check the exact workflow:<step-name> grant; permission and approval are separate decisions.
  • Invalid input: the driver accepts only the declared order ID field. It does not let the caller patch eligible or receipt into trusted state.
  • Budget exhausted after adding a limit: test the actual driver accounting. This fixed two-step example forbids model calls but leaves the aggregate tool-call budget unset; a function-step count is not a promise of identical budget consumption.
  • Unknown payment outcome after adapting it: do not treat cancellation as a rollback. Follow recovery before retrying.
The program closes the session’s resources and the host-owned ApprovalManager in finally. It creates no persistent data. Next, add model-backed research or learn durable approvals.