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 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 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 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 []func(context.Context, *message.FunctionCallContent) (bool, error)
// 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 Rule ¶
type Rule struct {
ToolName string `json:"toolName"`
Arguments map[string]string `json:"arguments"`
}
Rule is a standing approval rule. If Arguments is nil, all invocations of the named tool are auto-approved. Otherwise only invocations with an exact argument map match are auto-approved. A non-nil empty Arguments map matches only calls with no arguments.