Documentation
¶
Overview ¶
Package toolapproval provides middleware that manages human-in-the-loop tool approval with support for "don't ask again" standing rules.
When an inner agent returns tool calls that require approval, this middleware surfaces approval requests one at a time to the caller. The caller may approve or deny individual calls, and optionally indicate that a tool (or a tool with specific arguments) should always be approved in the future for the lifetime of the session.
Standing approval rules and queued requests are persisted across turns using the agent.Session.
Index ¶
Constants ¶
const ( // DefaultMaxAutoApprovalIterations is the default safety cap for how many // times the inner agent is re-invoked in a single run when every surfaced // approval request is auto-approved. DefaultMaxAutoApprovalIterations = 40 )
Variables ¶
This section is empty.
Functions ¶
func AllToolsAutoApprovalRule ¶ added in v0.1.1
func AllToolsAutoApprovalRule(context.Context, *ToolAutoApprovalRuleContext) (bool, error)
AllToolsAutoApprovalRule approves every tool call. Only use this rule when every registered tool is trusted.
func New ¶
func New(cfg Config) agent.Middleware
New creates a tool-approval middleware that wraps agent runs with human-in-the-loop approval management.
Types ¶
type AutoApprovalRule ¶ added in v0.1.1
type AutoApprovalRule func(context.Context, *ToolAutoApprovalRuleContext) (bool, error)
AutoApprovalRule decides whether a tool call should be auto-approved without prompting the caller.
type Config ¶
type Config struct {
// AutoApprovalRules is an optional list of heuristic functions evaluated after
// standing rules (derived from prior user approvals) but before surfacing the
// approval request to the caller. Each rule receives the tool call together
// with the current run context and returns (approved, error). Returning
// approved=true auto-approves the request. Rules are evaluated in order; the
// first returning approved=true causes the request to be auto-approved
// without prompting the caller. Returning an error fails the current run.
AutoApprovalRules []AutoApprovalRule
// MaxAutoApprovalIterations is the safety cap for how many times the inner
// agent is re-invoked in a single run when every surfaced approval request
// is auto-approved. When nil, DefaultMaxAutoApprovalIterations is used.
MaxAutoApprovalIterations *int
}
Config configures tool-approval middleware behavior.
type ToolAutoApprovalRuleContext ¶ added in v0.1.1
type ToolAutoApprovalRuleContext struct {
// FunctionCall is the tool call that requires approval.
FunctionCall *message.FunctionCallContent
// Agent is the agent that initiated the current run when the middleware is
// executed through [agent.Agent]. It is nil when unavailable.
Agent *agent.Agent
// Session is the session associated with the current run, if any.
Session *agent.Session
// RequestMessages are the original request messages passed to the current
// run, before the middleware injects any collected approval responses.
RequestMessages []*message.Message
// Options are the run options supplied to the current invocation.
Options []agent.Option
}
ToolAutoApprovalRuleContext provides the tool call and surrounding run metadata for an auto-approval rule evaluation.