mirror of
https://github.com/hwchase17/langchain.git
synced 2026-03-18 11:07:36 +00:00
## Summary When invoking a tool with a `ToolCall`, the `tool_call_id` is extracted but was **not forwarded** to callback handlers in `on_tool_start`. This made it impossible for callback handlers to correlate tool executions with the original LLM tool calls. This fix adds `tool_call_id=tool_call_id` to both: - Sync `run()` method's `on_tool_start` call - Async `arun()` method's `on_tool_start` call ## Changes - **`libs/core/langchain_core/tools/base.py`**: Added `tool_call_id` parameter to `on_tool_start` calls (2 lines) - **`libs/core/tests/unit_tests/test_tools.py`**: Added 6 comprehensive tests covering: - Sync tool invocation via `invoke()` - Async tool invocation via `ainvoke()` - `tool_call_id` is `None` when invoked without a ToolCall - Empty string `tool_call_id` edge case - Direct `run()` method - Direct `arun()` method ## Test plan - [x] All 147 existing tests pass - [x] 6 new tests added and passing - [x] Linting passes Fixes #34168 --- This PR was developed with AI assistance (Claude). --------- Co-authored-by: Mason Daugherty <github@mdrxy.com> Co-authored-by: Mason Daugherty <mason@langchain.dev>