fix: provide ToolContext for local tool hooks#3430
Open
pragnyanramtha wants to merge 1 commit into
Open
Conversation
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
Provides
ToolContextto lifecycle hooks for built-in local tool calls that have concrete tool call IDs.Function/custom tools already expose
context.tool_call_idthroughToolContext, but built-in local tools such asLocalShellTool,ShellTool,ComputerTool, andApplyPatchToolpassed a plainRunContextWrappertoon_tool_start/on_tool_end. This made it difficult to correlate start/end hook calls for metrics when tool calls run concurrently.This PR keeps public hook signatures unchanged and constructs a
ToolContextonly for hook callbacks. Executor request contexts remain the existingRunContextWrappervalues.Test plan
Passed:
uv run pytest tests/test_computer_action.py tests/test_local_shell_tool.py tests/test_shell_tool.py tests/test_apply_patch_tool.py(67 passed)make format-checkmake lintuv run mypy src/agents/run_internal/tool_actions.py src/agents/lifecycle.py tests/test_computer_action.py tests/test_local_shell_tool.py tests/test_shell_tool.py tests/test_apply_patch_tool.pyuv run pyright src/agents/run_internal/tool_actions.py src/agents/lifecycle.py tests/test_computer_action.py tests/test_local_shell_tool.py tests/test_shell_tool.py tests/test_apply_patch_tool.pygit diff --checkAttempted repo-wide checks:
make typecheckdid not complete because the local environment is missing optional dependencies/stubs such asnumpy,litellm,temporalio,sqlalchemy, andboto3, plus existing Python 3.11/runtime typing issues unrelated to this patch.make testsreached the broader suite but failed on missing optional extras/imports such assqlalchemy,litellm,numpy, andrunloop_api_client.Issue number
Fixes #1849
Checks
make lintandmake format