fix(core): add tool_call_id to on_tool_error event data #33731
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.
Add
tool_call_idtoon_tool_errorevent dataSummary
This PR addresses issue #33597 by adding
tool_call_idto theon_tool_errorcallback event data. This enables users to link tool errors to specific tool calls in stateless agent implementations, which is essential for building OpenAI-compatible APIs and tracking tool execution flows.Problem
When streaming events using
astream_eventswithversion="v2", theon_tool_errorevent only included the error and input data, but lacked thetool_call_id. This made it difficult to:run_idis not sufficientSolution
The fix adds
tool_call_idpropagation through the callback chain:tool_call_idto callbacks: UpdatedBaseTool.run()andBaseTool.arun()to passtool_call_idto bothon_tool_startandon_tool_errorcallbacks_AstreamEventsCallbackHandlerto storetool_call_idin run info duringon_tool_starton_tool_errorhandler to extract and includetool_call_idin the event dataChanges
libs/core/langchain_core/tools/base.py:tool_call_idtoon_tool_startin both sync and async methodstool_call_idtoon_tool_errorwhen errors occurlibs/core/langchain_core/tracers/event_stream.py:tool_call_idin run info duringon_tool_starttool_call_idfrom kwargs or run info inon_tool_errortool_call_idin theon_tool_errorevent dataTesting
The fix was verified by:
tool_call_idappears inon_tool_errorevent data when calling tools directlycreate_agentto ensuretool_call_idis present in error events during agent executionBackward Compatibility
tool_call_idis optional (can beNone)Related Issues
Fixes #33597