Repository navigation
feat(core): pluggable tool call interceptors for per-invocation validation, rewriting, and audit - #3657
Merged
Conversation
…alidation, rewriting, and audit
jujn
approved these changes
Oct 20, 2026
This was referenced Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #3653
Summary
Adds a Toolkit-layer, per-invocation extension point over tool arguments, as specified in #3653. It runs after schema validation and preset merging and before the dispatch record and real execution, so it sees the exact arguments the tool would receive — plus the caller identity — and decides what actually executes.
ToolCallInterceptor— onion-style hook withorder()-based chain assembly (same convention asMiddlewareBase#order()). Supported actions: allow, policy deny (DENIEDresult, auto-recorded as adenieddecision), reject as invalid (ToolResultBlock.error), argument rewrite (may override presets), audit, and suspend for HITL (ToolSuspendException).ToolInvocation— immutable call snapshot: tool name, resolvedAgentTool(metadata dispatch such asisReadOnly()), preset-merged input (null-tolerant, key order preserved), runtime context, and agent identity (agentId/agentName, null on agentless direct calls). Copy-on-write rewriting viawithInput.ToolkitConfig— build-time registration:interceptor(...)appends (repeatable),interceptors(List)replaces;List.copyOfdefensive copy; interceptors propagate automatically viaToolkit#copy()(harness subagents).ToolExecutor#executeCore, covering all locally executed channels: agent acting batches (Toolkit#callTools, with timeout/retry/scheduling as today), directToolkit#callToolcalls, MCP tools including runtime-registered ones, and subagent toolkits. External tools (externalTool=true/SchemaOnlyTool) short-circuit tosuspendedbefore the chain, as today.Session-record integrity: the
tool/dispatchrecord moved to the end of the chain, so it always captures the arguments that actually executed; denied calls leave no misleadingallowed/dispatchrecord.With no interceptors registered (the default),
executeCorekeeps its existing code path unchanged — the public API change is purely additive (two new types plus aToolkitConfigoption); no existing signature, serialized state, or event payload is modified.Docs: new "Tool call interceptors" section in
docs/v2(EN & ZH)building-blocks/tool.md, plus layering guidance cross-referenced frompermission-system.mdandmiddleware.md.