Tools + Approvals (Implementation): pipeline + exec approvals
Tools + Approvals (Implementation): pipeline + exec approvals
This is an implementation guide for tool policy and exec approvals.
Entry points (concept):
Code entry points (optional)
src/agents/pi-tools.tssrc/agents/tool-policy-pipeline.tssrc/agents/pi-tools.before-tool-call.tssrc/agents/pi-tool-definition-adapter.tssrc/infra/exec-approvals.tssrc/gateway/exec-approval-manager.tssrc/gateway/server-methods/exec-approval.ts
Two main lines you’re building
- A tool policy pipeline (explainable allow/deny).
- An exec approval state machine (observable two-phase gate).
Tool policy pipeline (five steps)
- owner-only pruning
- layered policy filtering (fixed order)
- schema normalization
before_tool_callinjection (patch/block)- optional abort-signal wrapping
Exec approvals: request → wait → resolve → timeout
Minimum behaviors:
- idempotent
waitDecisionfor the same approval id - timeouts resolve to
null(caller handles explicitly) - short grace retention for resolved entries (two-phase race protection)
Failure modes and troubleshooting
waitDecisioncan’t find an id: verify “register before accepted response” ordering; cross-check Gateway protocol.- Missing after_tool_call audits: ensure failure paths also trigger after_tool_call and it runs fire-and-forget.
Acceptance checks
- Pipeline order is fixed and explainable (“which layer filtered the tool”).
- before_tool_call can patch/block; after_tool_call runs on success and failure.
- Approvals time out and recover (no infinite hangs).
- Adjusted-params tracking is bounded (no unbounded growth under load).