Repository navigation
Expose the resolved tool identity to native pre-execution hooks #5011
AgentTanuki
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
A
BEFORE_TOOLhook can deny a name, but onpraisonaiagents==1.7.4it cannot identify the actual callable selected by a per-call tool override. I encountered this while evaluating an optional per-agent Agent Guild preflight integration that observes an operator-approved remote endpoint before delegating. A check against endpoint A must not be reused when the actual call goes to endpoint B.The native
execute_tool_async(..., tools_override=[...])entry point firesBEFORE_TOOLbefore it resolves the override. Its input includestool_name, arguments and agent/session metadata, but no selected callable or effective override list. The genericextrafield is empty in this dispatch. Looking atagent.toolsin the callback does not help: it remains the agent's original inventory.Here is a minimal reproduction with local functions. It makes no model or network request:
The same gap was reproduced using two loopback MCP endpoints and the published PraisonAI
MCPclient andHTTPStreamMCPTool, without replacing SDK functions or wrapping the tool. The hook observed A once; the native asynchronous override called B once and A zero times. Both endpoints and the observation service were synthetic local fixtures. Direct native sync/async deny controls and full deterministic model-turn deny controls prevented all protected calls. Allowed full model turns encountered a separate HTTP MCP thread/transport limitation, so those are not claimed as successful end-to-end remote calls.The invocation correlation added in #4023 supplies a tool-call ID. This proposal concerns the actual callable or capability selected for that invocation.
Could the existing native hook contract expose a resolved, immutable tool identity after effective tool selection and before invocation? An optional context value for Python callbacks could identify the actual selected callable or a stable capability binding. Command-hook serialization should receive only a redacted descriptor, without client objects, credentials, or raw transport configuration. The core should invoke that same resolved target afterward; if middleware changes the target, it should be resolved and gated again. Existing denial composition and the no-hook fast path should remain intact.
Suggested regressions: native sync and async dispatch; ordinary and run-scoped inventories; same-name collisions and aliases; replacement between setup and execution; denial before any tool side effect; existing-denial precedence; no credential serialization; and a full agent turn against deterministic loopback model/MCP fixtures. This needs no mandatory vendor or HTTP-client dependency in the core. The endpoint observer would remain an optional, explicitly configured integration.
Validation used Python 3.12.14 and
praisonaiagents==1.7.4. Its MCP extra currently admits MCP 2, while the runtime imports a v1 Streamable HTTP API; the MCP reproduction therefore usedmcp==1.30.0. This compatibility constraint is separate from the hook-context request. Published PraisonAI SDK, MCP migration guidance.All reactions