Skip to content

fix: provide ToolContext for local tool hooks#3430

Open
pragnyanramtha wants to merge 1 commit into
openai:mainfrom
pragnyanramtha:pragnyan/issue-1849-local-tool-hook-context
Open

fix: provide ToolContext for local tool hooks#3430
pragnyanramtha wants to merge 1 commit into
openai:mainfrom
pragnyanramtha:pragnyan/issue-1849-local-tool-hook-context

Conversation

@pragnyanramtha
Copy link
Copy Markdown

Summary

Provides ToolContext to lifecycle hooks for built-in local tool calls that have concrete tool call IDs.

Function/custom tools already expose context.tool_call_id through ToolContext, but built-in local tools such as LocalShellTool, ShellTool, ComputerTool, and ApplyPatchTool passed a plain RunContextWrapper to on_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 ToolContext only for hook callbacks. Executor request contexts remain the existing RunContextWrapper values.

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-check
  • make lint
  • uv 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.py
  • uv 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.py
  • git diff --check

Attempted repo-wide checks:

  • make typecheck did not complete because the local environment is missing optional dependencies/stubs such as numpy, litellm, temporalio, sqlalchemy, and boto3, plus existing Python 3.11/runtime typing issues unrelated to this patch.
  • make tests reached the broader suite but failed on missing optional extras/imports such as sqlalchemy, litellm, numpy, and runloop_api_client.

Issue number

Fixes #1849

Checks

  • I've added new tests (if relevant)
  • I've added/updated the relevant documentation
  • I've run make lint and make format
  • I've made sure tests pass

@pragnyanramtha pragnyanramtha marked this pull request as ready for review May 16, 2026 04:44
Copilot AI review requested due to automatic review settings May 16, 2026 04:44
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose Tool Call ID to Lifecycle Hooks

2 participants