fix(community): Handle AIMessage.tool_calls and AIMessageChunk.tool_call_chunks for LangChain 1.0 compatibility #421
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.
Description
Fixes the OpenAI message adapters to properly handle tool calls in LangChain 1.0+. The adapters were only checking
additional_kwargsfor tool call information, but LangChain 1.0 moved tool calls to dedicated attributes (tool_callsandtool_call_chunks), causing tool calls to be silently dropped during conversion.This PR updates the conversion functions to check the new attributes first, then fall back to
additional_kwargsfor backward compatibility with pre-1.0 versions.Changes made:
convert_message_to_dict()- Now checksAIMessage.tool_callsattribute beforeadditional_kwargs_convert_message_chunk()- Now checksAIMessageChunk.tool_call_chunksattribute beforeadditional_kwargsBoth functions maintain 100% backward compatibility with pre-1.0 LangChain versions.
Closes #414
Issue
Fixes #414 - OpenAI message adapters missing implementation for AIMessage.tool_calls
Dependencies
No new dependencies added.
Testing
Added comprehensive test suite with 36 tests covering:
tool_callsattribute (LangChain 1.0+)tool_call_chunksattribute (streaming, LangChain 1.0+)additional_kwargs(pre-1.0)Run tests with:
make format make lint make testAll tests passing ✅
Checklist
fix(community): {DESCRIPTION}make format,make lint, andmake test- all passing