fix(ai): capture tool calls in reasoning models#292
Merged
Conversation
Contributor
There was a problem hiding this comment.
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:
- A new helper function to convert tool call formats
- Updates to
_convert_message_to_dictto handle tool calls inAIMessageobjects - Comprehensive test coverage with
test_convert_message_to_dict_tool_calls - Version bump from 6.2.1 to 6.2.2
Confidence score: 5/5
- This PR is safe to merge as it fixes a missing functionality without disrupting existing behavior
- The changes are well-tested, isolated to a specific feature, and follow a clear path for format conversion
- Key files to review: callbacks.py - specifically the new conversion function and message dict handling
3 files reviewed, no comments
k11kirky
approved these changes
Jul 22, 2025
9 tasks
a24170b to
938730a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
LangChain passes original tool calls in
additional_kwargsof 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.