fix(hooks): fire post_tool_call hook for built-in tools (closes #12922)#12928
Closed
wpsl5168 wants to merge 1 commit into
Closed
fix(hooks): fire post_tool_call hook for built-in tools (closes #12922)#12928wpsl5168 wants to merge 1 commit into
wpsl5168 wants to merge 1 commit into
Conversation
…#12922) The post_tool_call plugin hook was silently bypassed for built-in tools that short-circuit handle_function_call: todo, memory, session_search, clarify, delegate_task, context-engine helpers, and memory-provider tools. Plugins relying on the hook (e.g. external memory backends syncing state via memory_tool calls) never observed these tool invocations. Fix: - model_tools.handle_function_call: add skip_post_tool_call_hook parameter, mirroring the existing skip_pre_tool_call_hook escape hatch - run_agent: introduce _fire_post_tool_call_hook helper and invoke it in every built-in branch of _invoke_tool (concurrent path) and in _execute_tool_calls_sequential, with finally blocks for delegate_task and memory provider tools so failures still emit the hook - Registry-routed tools (else branch) keep firing the hook exactly once via handle_function_call - no double-fire Tests (5 new, all pass): - parametrised test confirms post_tool_call fires for todo/memory/clarify - session_search with no DB still fires hook on error path - web_search still fires hook exactly once (no duplication) - 296/296 existing run_agent + model_tools tests still green Closes NousResearch#12922
2de0ba0 to
3637719
Compare
This was referenced May 9, 2026
3 tasks
Collaborator
|
Closing as obsolete — the centralized
Discovered while reviewing #22345 which originally cited this PR as a dependency — turns out the central firing was added in a later refactor and the dependency is satisfied. |
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.
Summary
Fix for #12922 —
post_tool_callplugin hook was silently bypassed for built-in tools that short-circuithandle_function_call:todo,memory,session_search,clarify,delegate_task, context-engine helpers, and memory-provider tools.This broke external memory backends (and any plugin auditing tool calls) that subscribe to
post_tool_callto mirror agent state —memoryoperations in particular went completely unobserved.Changes
model_tools.pyskip_post_tool_call_hook=Falseparameter tohandle_function_call, mirroring the existingskip_pre_tool_call_hookescape hatch. Lets the agent loop tell the dispatcher "I will fire the hook myself".run_agent.py_fire_post_tool_call_hook(...)that swallows hook exceptions (consistent withmodel_toolsbehaviour)._invoke_tool(concurrent path)._execute_tool_calls_sequentialfor every short-circuited built-in branch:todo,session_search,memory(agent-loop),clarify— fired right afterfunction_resultis setdelegate_task— fired infinallyso failures still emit the hookfinallyblockelsebranch /handle_function_callpath) keep firing the hook exactly once via the dispatcher — no double-fire.Tests
5 new tests in
tests/run_agent/test_run_agent.py:_invoke_toolfirespost_tool_callexactly once fortodo,memory,clarifywith correcttool_name/args/result/tool_call_idpayload.session_searchwith no DB still fires the hook on its error path.web_search(registry-routed) fires the hook exactly once — guards against double-fire regression.Full regression run: 296/296 passing in
tests/run_agent/+tests/test_model_tools.py.Observed Impact
In our setup (custom OpenHippo memory plugin syncing Hermes' built-in
memorytool calls into a SQLite-backed long-term store), this bug caused 0 of 22 real memory entries to sync. After the fix lands, plugins receive the hook for every memory mutation as documented.Notes
skip_post_tool_call_hookparameter defaults toFalse, preserving existing callers._fire_post_tool_call_hook) — internal-only refactor.