Anvia
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

  1. The model asks to call a tool.
  2. onToolCall(...) runs before the tool executes.
  3. The hook returns requireApproval(...).
  4. Anvia creates a pending approval request.
  5. Your approval handler returns approved, rejected, or timed_out.
  6. Anvia either runs the tool or sends the rejection or timeout message back to the model.

What Anvia Owns

Anvia ownsYour app owns
detecting the tool callchoosing which tools need approval
creating the approval request shapeshowing UI, sending notifications, or waiting on a queue
running the tool after approvaldeciding who can approve
returning rejection or timeout text to the modelstoring audit records
  1. Tool Approval
  2. Approval Handlers
  3. Hooks