Build a report workflow with three steps: generate a draft, wait for user approval, and publish. The first invocation generates the draft and pauses. A second invocation submits your decision and prints the report.
Local functions stand in for a real Skill, and console output stands in for an external publishing service. No model credentials are required. You can replace these functions with your Agent and tools afterward.
Prepare a project
Run these commands in an empty directory:
See installation and public entry points for supported Node.js versions. For an unreleased SDK candidate, install the npm tarball provided by the maintainer; an older npm release may lack these entry points. The example uses .mjs and does not require changing the project’s module configuration.
Create the workflow
Save this code as report.mjs:
You will see approval-required and a pending Wait containing the draft proposal, Wait ID, proposal hash, and available choices. The report-state directory stores the Run. Repeating the command reads the same Run and waits for the same approval without generating another draft.
Submit the current user decision
Append the following code to report.mjs. It submits approval only when you explicitly pass —approve. In a product, collect the user’s decision on the current proposal through your UI; see user approvals.
Inspect the draft from the first invocation. Once you have decided to publish, run:
The output includes Report about SDK integration and completed, indicating that the declared path has finished. This example prints a report; when connecting a real publishing service, also verify its actual response. Starting the completed Run again does not republish. Do not pass —approve again, because there is no pending proposal.
Inspect results and start another task
At the end of the script, runtime.inspect(‘report-1’) reads the Run. The value at run.outputs.publish.value contains { published: true }, and run.actions retains actual actions and results. A new report needs a new runId, such as report-2. Changing input while retaining the old ID triggers consistency checks.
Replace execute with actual Skill or tool calls and return their real results. Handler keys match step ref values; type matches the action kind.
parseInput validates current input and upstream outputs before passing a business object to execute. TypeScript infers types within that handler; persisted JSON between steps still needs a Schema or validator.
Provide credentials through a host closure or the current execution environment. Do not put tokens in Workflow definitions, Run input, outputs, or approval proposals. When a disconnected operation has an uncertain result, reconcile the original action before executing an external operation again. Last modified on October 22, 2026