fix(core): add tool_call_id to on_tool_error event data#33731
Conversation
Merging this PR will improve performance by 15.54%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | WallTime | test_import_time[tool] |
599.7 ms | 519 ms | +15.54% |
| ⚡ | WallTime | test_import_time[CallbackManager] |
541.2 ms | 484.9 ms | +11.6% |
| ⚡ | WallTime | test_import_time[PydanticOutputParser] |
594.1 ms | 539.5 ms | +10.13% |
| ⚡ | WallTime | test_import_time[RunnableLambda] |
544.7 ms | 493.4 ms | +10.41% |
| ⚡ | WallTime | test_import_time[HumanMessage] |
292.9 ms | 258.5 ms | +13.32% |
| ⚡ | WallTime | test_import_time[InMemoryRateLimiter] |
188.9 ms | 171.5 ms | +10.18% |
| ⚡ | WallTime | test_import_time[Runnable] |
568.7 ms | 507.3 ms | +12.1% |
Comparing Shreyanshsingh23:add-tool-call-id-to-on-tool-error (4f522b7) with master (e261924)
Footnotes
-
21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
|
Hey Eugene Yurtsev (@eyurtsev), should I go ahead and make changes in my code to solve this conflict or you are looking to do? Jusk asking before going ahead. |
|
Waiting for this feature |
|
on_tool_start and on_tool_end events also need |
|
Shreyansh Singh Gautam (@Shreyanshsingh23) would you mind resolving the conflict? |
tool_call_id to on_tool_error event data
Add tool_call_id parameter to on_tool_error callback events to enable linking tool errors to specific tool calls in stateless agent implementations. - Pass tool_call_id to on_tool_start and on_tool_error callbacks in BaseTool - Store tool_call_id in event stream handler run info - Include tool_call_id in on_tool_error event data Fixes langchain-ai#33597
Refactor the on_tool_error callback to utilize a structured event object for improved clarity and maintainability. This change includes the addition of tool_call_id to the event data, enhancing the linkage of tool errors to specific tool calls. - Updated the on_tool_error method to create a structured event object - Included tool_call_id in the event data This change builds on the previous addition of tool_call_id to enhance error tracking in stateless agent implementations.
2119bf3 to
de3b262
Compare
2ef2388
into
langchain-ai:master
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