Skip to content

Pause for approval

You will make the refund agent ask a person before it moves money. The run ends with a signed request that you can store as JSON, and any process with the key can resume it. You need this when a write must not run unattended.

The gate is an interceptor. It asks a person before any refund_create call and allows everything else:

refund-approval.ts
/** The gate: every refund waits for a person, and nothing else is gated. */
const gate: Interceptors = {
beforeToolCall: ({ tool }) =>
tool === "refund_create" ? { decision: "ask", reason: "A refund moves money." } : { decision: "allow" },
};

Start the run with a signer, which signs each request. The default signer holds a random key that lives only in its own process, so another process rejects its signatures. Pass hmacSigner() over a key ring you store, so any process that holds the key can verify the request.

When the result’s stop reason is awaiting_approval, save result.context with your own store. It holds the pending requests and the input each one signs. Show the person that input, not the model’s arguments, because the gate or a repair step may have changed them.

Pass the stored context and one resolution for each request to continueRun(). This function resumes the refund run:

refund-approval.ts
/** Resumes a paused run from its stored context, with the person's answer to each request. */
export function resumeRefund(deps: RefundDeps, context: Context, resolutions: readonly Resolution[]): Run {
return continueRun(context, { ...refundOptions(deps), resolutions });
}

The SDK checks each resolution against its signature before the call runs. A resolution that fails its check runs nothing, and the call asks again.

Next, test your agents offline.

These docs are licensedCC BY 4.0. Thelicence text is in the repository.