Skip to content

Comments

fix(ai): capture tool calls in reasoning models#292

Merged
skoob13 merged 2 commits intomasterfrom
fix/reasoning-models-tool-calls
Jul 23, 2025
Merged

fix(ai): capture tool calls in reasoning models#292
skoob13 merged 2 commits intomasterfrom
fix/reasoning-models-tool-calls

Conversation

@skoob13
Copy link
Contributor

@skoob13 skoob13 commented Jul 22, 2025

Problem

LangChain passes original tool calls in additional_kwargs of a message for all models except for reasoning models, so they're not captured for OpenAI o* models.

Changes

Added tool calls for reasoning models by converting LangChain's shape to original OpenAI shape.

@skoob13 skoob13 requested review from a team, Radu-Raicea and k11kirky July 22, 2025 16:20
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Summary

This PR fixes a critical gap in tool call capture functionality for OpenAI reasoning models in the LangChain integration. Previously, tool calls were only being captured from additional_kwargs, but LangChain handles tool calls differently for reasoning models. The change adds a new conversion function _convert_lc_tool_calls_to_oai that transforms LangChain's tool call format into OpenAI's expected format, ensuring consistent tool call capture across all model types.

The changes include:

  1. A new helper function to convert tool call formats
  2. Updates to _convert_message_to_dict to handle tool calls in AIMessage objects
  3. Comprehensive test coverage with test_convert_message_to_dict_tool_calls
  4. Version bump from 6.2.1 to 6.2.2

Confidence score: 5/5

  1. This PR is safe to merge as it fixes a missing functionality without disrupting existing behavior
  2. The changes are well-tested, isolated to a specific feature, and follow a clear path for format conversion
  3. Key files to review: callbacks.py - specifically the new conversion function and message dict handling

3 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

@skoob13 skoob13 force-pushed the fix/reasoning-models-tool-calls branch from a24170b to 938730a Compare July 23, 2025 09:48
@skoob13 skoob13 merged commit 5a52af6 into master Jul 23, 2025
10 checks passed
@skoob13 skoob13 deleted the fix/reasoning-models-tool-calls branch July 23, 2025 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants