Skip to content

Conversation

@Madhuram99
Copy link

Description

Fixes the OpenAI message adapters to properly handle tool calls in LangChain 1.0+. The adapters were only checking additional_kwargs for tool call information, but LangChain 1.0 moved tool calls to dedicated attributes (tool_calls and tool_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_kwargs for backward compatibility with pre-1.0 versions.

Changes made:

  1. convert_message_to_dict() - Now checks AIMessage.tool_calls attribute before additional_kwargs
  2. _convert_message_chunk() - Now checks AIMessageChunk.tool_call_chunks attribute before additional_kwargs

Both 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:

  • AIMessage with tool_calls attribute (LangChain 1.0+)
  • AIMessageChunk with tool_call_chunks attribute (streaming, LangChain 1.0+)
  • Backward compatibility with additional_kwargs (pre-1.0)
  • All message types (Human, System, AI, Function, Tool, Chat)
  • Edge cases (empty content, multiple tools, missing fields)
  • Integration tests for ChatCompletion and Completions classes

Run tests with:

make format
make lint
make test

All tests passing ✅

Checklist

@github-actions github-actions bot added the fix label Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAI message adapters missing implementation for AIMessage.tool_calls

1 participant