fix(agents): patch _run in ToolInterceptor to ensure interrupt triggering (#753)

Fixes #752

* fix(agents): patch _run in ToolInterceptor to ensure interrupt triggering

* Update the code with review comments
This commit is contained in:
Willem Jiang
2025-12-10 22:15:08 +08:00
committed by GitHub
parent 84c449cf79
commit ec99338c9a
2 changed files with 76 additions and 0 deletions

View File

@@ -159,6 +159,13 @@ class ToolInterceptor:
# Use object.__setattr__ to bypass Pydantic validation
logger.debug(f"Attaching intercepted function to tool '{safe_tool_name}'")
object.__setattr__(tool, "func", intercepted_func)
# Also ensure the tool's _run method is updated if it exists
if hasattr(tool, '_run'):
logger.debug(f"Also wrapping _run method for tool '{safe_tool_name}'")
# Wrap _run to ensure interception is applied regardless of invocation method
object.__setattr__(tool, "_run", intercepted_func)
return tool
@staticmethod