Skip to main content
A tool that needs approval doesn’t run until a person decides. While the run waits, Restate suspends the invocation, at the latest after the inactivity timeout of one minute by default. A wait of days doesn’t keep the invocation running in your service, and the wait has no default time limit.

Require approval for a tool

Mark the tool with needsApproval: true:
When the model calls the tool, Restate Harness:
  1. Calls onApproval with an ApprovalRequest, so your code can publish the request.
  2. Waits on a durable signal for the decision.
  3. Runs the tool if the decision is true. If the decision is false, the tool doesn’t run, and the model receives a denied result.
Publish each request to your review system from onApproval. Wrap the notification in restate.run so Restate journals it. The review system calls approve when the reviewer makes a decision:
notifyReviewer stands for your review system’s notification API. Use invocationId and signalName together as an idempotency key for the notification, since a crash before Restate journals its result can cause it to be sent again. Each approval request has its own signal name, so the review system can return decisions independently when several tool calls need approval. The review system sends the decision to approve, using the invocationId and signalName from the notification:
An ApprovalRequest contains: If the agent runs in a Virtual Object, make approve a shared handler, so the decision doesn’t wait for the object’s lock, which the waiting run holds. You can also set onApproval on the agent definition. If both the agent and the run set it, Restate Harness calls both.

Conditional approval

Pass a generator function to needsApproval to require approval only for some calls:

Timeouts

onHumanApproval replaces the built-in wait and returns the decision. Any onApproval handlers still publish the request first. To deny a request that nobody answers in time, race the signal against a timer:
The review system sends its decision to the same approve handler shown above. You can also use onHumanApproval to call an approval service with restate.client instead of waiting for a signal.

Let the model ask for approval

humanApprovalTool lets the model ask a yes or no question:
onApproval receives the request, with the model’s question in question. The tool runs in the background: the model receives a pending result, and the decision in a later step. To block a specific tool until a person approves it, use needsApproval on that tool. A tool’s before guardrail or the agent’s beforeTool hook can also ask for approval with yield* ctx.approve(input, {question, details}), where ctx is the hook’s second argument. approve returns the decision, so return a rejection when it returns false. See Guardrails.