Approvals
Approvals
Tools registered with crux.WithApprovalNeeded(true) (plus the filesystem and
network tools that change things, and MCP tools not marked read-only) don’t run
until a human decides.
crux.RegisterTool("refund", "Refund an order",
func(ctx context.Context, in struct {
OrderID string `json:"order_id"`
}) (string, error) {
return "refunded " + in.OrderID, nil
}, crux.WithApprovalNeeded(true))
answer, err := session.Run(ctx, "Refund order 42")
for errors.Is(err, crux.ErrApprovalNeeded) {
for _, call := range session.PendingApprovals() {
fmt.Printf("%s wants %s(%s)\n", call.Agent, call.Name, call.Args)
if userSaysYes(call) {
err = session.Approve(ctx, call.ID)
} else {
err = session.Reject(ctx, call.ID, "not allowed")
}
if err != nil { ... }
}
answer, err = session.Resume(ctx)
}Runreturnscrux.ErrApprovalNeededafter recording the calls. Other calls from the same turn still run.PendingApprovals()returns the waiting calls, including those made by subagents;call.Agentnames the agent.Approvelets the call run on the nextResume.Rejecttells the model the reason, or that the user declined.- Decide every pending call, then call
Resume. - With a persistent store, approvals survive restarts: reopen the session with
WithSessionID, thenPendingApprovals,ApproveandResume. crux.CLIasks for approvals interactively.