Human in the Loop
Human in the Loop
Pause sensitive tool calls until your application approves them.
Human-in-the-loop workflows use hooks to pause a tool call before it runs. Your app receives an approval request, decides whether the tool may run, then returns the decision to Anvia.
Use this for actions such as refunds, account changes, outbound messages, production deployments, or any tool call that should be reviewed before execution.
Runtime Shape
import { createHook, requireApproval } from "@anvia/core";
const approvalHook = createHook({
onToolCall({ toolName }) {
if (toolName === "refund_order") {
return requireApproval({
reason: "Refunds require staff approval.",
});
}
},
});
const response = await agent
.prompt("Refund order A-100.")
.withHook(approvalHook)
.withToolApprovalHandler(handleApproval)
.send();The hook decides that approval is required. The approval handler owns the product-specific approval workflow.
Flow
- The model asks to call a tool.
onToolCall(...)runs before the tool executes.- The hook returns
requireApproval(...). - Anvia creates a pending approval request.
- Your approval handler returns
approved,rejected, ortimed_out. - Anvia either runs the tool or sends the rejection or timeout message back to the model.
What Anvia Owns
| Anvia owns | Your app owns |
|---|---|
| detecting the tool call | choosing which tools need approval |
| creating the approval request shape | showing UI, sending notifications, or waiting on a queue |
| running the tool after approval | deciding who can approve |
| returning rejection or timeout text to the model | storing audit records |
