Require approval for a tool
Mark the tool withneedsApproval: true:
- Calls
onApprovalwith anApprovalRequest, so your code can publish the request. - Waits on a durable signal for the decision.
- Runs the tool if the decision is
true. If the decision isfalse, the tool doesn’t run, and the model receives a denied result.
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:
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 toneedsApproval 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:
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.