Skip to content

Conversation

@nathannewyen
Copy link

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

  • All 147 existing tests pass
  • 6 new tests added and passing
  • Linting passes

Fixes #34168


This PR was developed with AI assistance (Claude).

When invoking a tool with a ToolCall, the tool_call_id was extracted
but 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 parameter to both sync run() and async
arun() methods' on_tool_start calls.

Fixes langchain-ai#34168
@github-actions github-actions bot added core Related to the package `langchain-core` fix labels Dec 7, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 7, 2025

CodSpeed Performance Report

Merging #34235 will not alter performance

Comparing nathannewyen:fix/34168-tool-call-id-callback (5a5a8c0) with master (80c3970)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 13 untouched
⏩ 21 skipped1

Footnotes

  1. 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.

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

Labels

core Related to the package `langchain-core` fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tool_call_id not passed to on_tool_start callback in BaseTool.run()

1 participant