feat(plugins): let pre_tool_call hooks block tool calls#5385
Closed
gianfrancopiana wants to merge 1 commit into
Closed
feat(plugins): let pre_tool_call hooks block tool calls#5385gianfrancopiana wants to merge 1 commit into
gianfrancopiana wants to merge 1 commit into
Conversation
47f1a81 to
3c345c9
Compare
teknium1
pushed a commit
that referenced
this pull request
Apr 14, 2026
Plugins can now return {"action": "block", "message": "reason"} from
their pre_tool_call hook to prevent a tool from executing. The error
message is returned to the model as a tool result so it can adjust.
Covers both execution paths: handle_function_call (model_tools.py) and
agent-level tools (run_agent.py _invoke_tool + sequential/concurrent).
Blocked tools skip all side effects (counter resets, checkpoints,
callbacks, read-loop tracker).
Adds skip_pre_tool_call_hook flag to avoid double-firing the hook when
run_agent.py already checked and then calls handle_function_call.
Salvaged from PR #5385 (gianfrancopiana) and PR #4610 (oredsecurity).
teknium1
pushed a commit
that referenced
this pull request
Apr 14, 2026
Plugins can now return {"action": "block", "message": "reason"} from
their pre_tool_call hook to prevent a tool from executing. The error
message is returned to the model as a tool result so it can adjust.
Covers both execution paths: handle_function_call (model_tools.py) and
agent-level tools (run_agent.py _invoke_tool + sequential/concurrent).
Blocked tools skip all side effects (counter resets, checkpoints,
callbacks, read-loop tracker).
Adds skip_pre_tool_call_hook flag to avoid double-firing the hook when
run_agent.py already checked and then calls handle_function_call.
Salvaged from PR #5385 (gianfrancopiana) and PR #4610 (oredsecurity).
Contributor
|
Merged via PR #9377. Your implementation was the basis for the salvage — the dual-path blocking design (handle_function_call + _invoke_tool), the skip_pre_tool_call_hook flag, and the get_pre_tool_call_block_message helper were all adapted from your work. Your authorship is preserved in the git commit. Thanks for the thorough contribution! |
19 tasks
hermes-agent-dhabibi
pushed a commit
to hermes-agent-dhabibi/hermes-agent
that referenced
this pull request
Apr 14, 2026
Plugins can now return {"action": "block", "message": "reason"} from
their pre_tool_call hook to prevent a tool from executing. The error
message is returned to the model as a tool result so it can adjust.
Covers both execution paths: handle_function_call (model_tools.py) and
agent-level tools (run_agent.py _invoke_tool + sequential/concurrent).
Blocked tools skip all side effects (counter resets, checkpoints,
callbacks, read-loop tracker).
Adds skip_pre_tool_call_hook flag to avoid double-firing the hook when
run_agent.py already checked and then calls handle_function_call.
Salvaged from PR NousResearch#5385 (gianfrancopiana) and PR NousResearch#4610 (oredsecurity).
ulasbilgen
pushed a commit
to ulasbilgen/hermes-adhd-agent
that referenced
this pull request
May 1, 2026
Plugins can now return {"action": "block", "message": "reason"} from
their pre_tool_call hook to prevent a tool from executing. The error
message is returned to the model as a tool result so it can adjust.
Covers both execution paths: handle_function_call (model_tools.py) and
agent-level tools (run_agent.py _invoke_tool + sequential/concurrent).
Blocked tools skip all side effects (counter resets, checkpoints,
callbacks, read-loop tracker).
Adds skip_pre_tool_call_hook flag to avoid double-firing the hook when
run_agent.py already checked and then calls handle_function_call.
Salvaged from PR NousResearch#5385 (gianfrancopiana) and PR NousResearch#4610 (oredsecurity).
aj-nt
pushed a commit
to aj-nt/hermes-agent
that referenced
this pull request
May 1, 2026
Plugins can now return {"action": "block", "message": "reason"} from
their pre_tool_call hook to prevent a tool from executing. The error
message is returned to the model as a tool result so it can adjust.
Covers both execution paths: handle_function_call (model_tools.py) and
agent-level tools (run_agent.py _invoke_tool + sequential/concurrent).
Blocked tools skip all side effects (counter resets, checkpoints,
callbacks, read-loop tracker).
Adds skip_pre_tool_call_hook flag to avoid double-firing the hook when
run_agent.py already checked and then calls handle_function_call.
Salvaged from PR NousResearch#5385 (gianfrancopiana) and PR NousResearch#4610 (oredsecurity).
02356abc
pushed a commit
to 02356abc/hermes-agent
that referenced
this pull request
May 14, 2026
Plugins can now return {"action": "block", "message": "reason"} from
their pre_tool_call hook to prevent a tool from executing. The error
message is returned to the model as a tool result so it can adjust.
Covers both execution paths: handle_function_call (model_tools.py) and
agent-level tools (run_agent.py _invoke_tool + sequential/concurrent).
Blocked tools skip all side effects (counter resets, checkpoints,
callbacks, read-loop tracker).
Adds skip_pre_tool_call_hook flag to avoid double-firing the hook when
run_agent.py already checked and then calls handle_function_call.
Salvaged from PR NousResearch#5385 (gianfrancopiana) and PR NousResearch#4610 (oredsecurity).
gweeteve
pushed a commit
to gweeteve/hermes-agent
that referenced
this pull request
Jun 2, 2026
Plugins can now return {"action": "block", "message": "reason"} from
their pre_tool_call hook to prevent a tool from executing. The error
message is returned to the model as a tool result so it can adjust.
Covers both execution paths: handle_function_call (model_tools.py) and
agent-level tools (run_agent.py _invoke_tool + sequential/concurrent).
Blocked tools skip all side effects (counter resets, checkpoints,
callbacks, read-loop tracker).
Adds skip_pre_tool_call_hook flag to avoid double-firing the hook when
run_agent.py already checked and then calls handle_function_call.
Salvaged from PR NousResearch#5385 (gianfrancopiana) and PR NousResearch#4610 (oredsecurity).
Egavasyug
pushed a commit
to Egavasyug/hermes-agent
that referenced
this pull request
Jun 10, 2026
Plugins can now return {"action": "block", "message": "reason"} from
their pre_tool_call hook to prevent a tool from executing. The error
message is returned to the model as a tool result so it can adjust.
Covers both execution paths: handle_function_call (model_tools.py) and
agent-level tools (run_agent.py _invoke_tool + sequential/concurrent).
Blocked tools skip all side effects (counter resets, checkpoints,
callbacks, read-loop tracker).
Adds skip_pre_tool_call_hook flag to avoid double-firing the hook when
run_agent.py already checked and then calls handle_function_call.
Salvaged from PR NousResearch#5385 (gianfrancopiana) and PR NousResearch#4610 (oredsecurity).
14 tasks
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.
What does this PR do?
This adds a simple plugin policy hook for tool calls.
A
pre_tool_callhook can now block a tool call by returning:{"action":"block","message":"..."}This works for both:
model_toolsrun_agentIf a tool is blocked, Hermes now returns a clean JSON error and skips execution side effects like:
Related Issue
No tracked issue for this specific change.
Note: PR #4610 works on the same problem. This PR covers the same basic hook-blocking feature, but also applies it to direct agent-level tools and prevents side effects before blocked calls.
Type of Change
Changes Made
hermes_cli/plugins.pyto read the supportedpre_tool_callblock resultmodel_tools.handle_function_call()to stop blocked calls cleanlyrun_agent.pyso the same blocking behavior also applies to agent-level toolsmodel_tools, andrun_agentpathsHow to Test
Run:
pytest -q tests/test_plugins.py tests/test_model_tools.py tests/test_run_agent.pyConfirm all tests pass.
Optional: register a test
pre_tool_callhook that returns:{"action":"block","message":"blocked by policy"}and confirm the tool returns a JSON error without running.
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
Validated locally:
pytest -q tests/test_plugins.py tests/test_model_tools.py tests/test_run_agent.py264 passedLocal full-suite note:
pytest tests/ -q -xfails on bothmainand this branch with the same unrelated failure intests/gateway/test_matrix_voice.py, so I am not claiming a clean local full-suite pass from this machine. CI should be the full-branch signal for this PR.AI assistance
This PR was implemented with AI assistance using GPT-5.4 xhigh.