ToolCall.Approval behaviour (ToolCall v0.4.0)

Copy Markdown

Approval policies and pending approval requests.

A policy is a module implementing check/3; use ToolCall, approval: Policy installs it for every tool in the module, and run/4 with approval: can override it per call. The module option also accepts :granted or :denied as a module-wide decision. check/3 receives the tool IR, the raw argument map and the caller's context, and answers:

  • :approve - invoke the tool;
  • {:deny, reason} - {:error, {:approval_denied, reason}};
  • {:required, reason} - {:pending, %ToolCall.Approval.Request{}}.

This is a mechanism, not a workflow: the application persists the request, shows it to a human, and resumes with ToolCall.run(request.module, request.tool, request.args, approval: :granted, context: request.context). It must use the stored arguments — never model output for an already approved call. There is no storage, timeout, retry or double-execution guard here; the agent runtime or application owns those.

Summary

Functions

Builds a pending approval request.

Types

decision()

@type decision() :: :approve | {:deny, term()} | {:required, term()}

Callbacks

check(t, map, term)

@callback check(ToolCall.IR.Tool.t(), map(), term()) :: decision()

Functions

request(module, tool, args, reason, context)

Builds a pending approval request.

The runner calls this when a policy answers {:required, reason}. A custom dispatcher can use it to build the same serializable shape.