fix(core): pass tool_call_id to on_tool_start callback #34235
+264
−0
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
When invoking a tool with a
ToolCall, thetool_call_idis extracted but was not forwarded to callback handlers inon_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_idto both:run()method'son_tool_startcallarun()method'son_tool_startcallChanges
libs/core/langchain_core/tools/base.py: Addedtool_call_idparameter toon_tool_startcalls (2 lines)libs/core/tests/unit_tests/test_tools.py: Added 6 comprehensive tests covering:invoke()ainvoke()tool_call_idisNonewhen invoked without a ToolCalltool_call_idedge caserun()methodarun()methodTest plan
Fixes #34168
This PR was developed with AI assistance (Claude).