Skip to content

tool_execute_before hook cannot modify tool arguments (mutated args not re-read) #1926

Open

Description

@wgnrai
  • Problem: Extensions hooking tool_execute_before (extensions/python) mutate tool kwargs (e.g., sanitizing or expanding placeholders in tool inputs), but the framework invokes the tool with the ORIGINAL arguments — the mutated kwargs are never re-assigned after the hook completes. This makes argument transformation hooks impossible without core edits.
  • Reproduction: Register a tool_execute_before extension that changes a tool's args; the executed tool receives the pre-hook values.
  • Proposed fix: Re-assign the mutated arguments after the tool_execute_before hook chain runs (one line: tool.args = tool_args / equivalent re-read of hook output). We run this as a local patch in production (fork commit d7ed0ef) since 2026-09 with no regressions.
  • Offer: Happy to open a PR if the direction is accepted.

Activity

  1. Li-john1021 commented on Oct 14, 2026

    @Li-john1021
    Contributor

    你好,我想认领这个问题。

    已核对:tool_execute_before 在 _execute_tool_request / process_tools / execute_tool_call(parallel)三处调用后,未把 hook 可能就地修改过的 tool_args 再写回 tool.args。不少工具(以及 MCP 工具初始 args={})会读 self.args,因此会出现 hook 已改、执行仍用旧值的分叉。

    计划按 issue 建议做最小修复:hook 链结束后补上 tool.args = tool_args,并加回归测试覆盖两条主 dispatch 路径。若已有他人在推进,请告诉我,我这边先停下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions