Skip to content

Conversation

@yashwantbezawada
Copy link

Fixes #33970

Problem

The get_buffer_string() function was still using the deprecated function_call field from additional_kwargs. Modern AI providers (OpenAI, Anthropic, Gemini, etc.) now use the tool_calls attribute instead, which meant tool call information couldn't be output for messages from these providers.

Solution

Updated get_buffer_string() in libs/core/langchain_core/messages/utils.py to:

  • Prioritize tool_calls over the deprecated function_call
  • Maintain backward compatibility with legacy function_call format
  • Ensure tool call information is correctly included in buffer strings

Changes

  • Modified get_buffer_string() to check for tool_calls first, then fall back to function_call
  • Added two new tests:
    • test_get_buffer_string_with_tool_calls() - tests modern tool_calls format
    • test_get_buffer_string_tool_calls_priority() - verifies tool_calls takes priority
  • Kept existing test_get_buffer_string_with_function_call() to ensure backward compatibility

Testing

Verified the fix works correctly with:

  • ✅ Modern tool_calls format
  • ✅ Legacy function_call format (backward compatibility)
  • ✅ Priority behavior (tool_calls takes precedence when both are present)

All changes are in the langchain-core package as specified in the issue.

Fixes langchain-ai#33970

The get_buffer_string() function was still using the deprecated
function_call field from additional_kwargs. Modern AI providers
(OpenAI, Anthropic, Gemini, etc.) now use the tool_calls attribute
instead, causing tool call information to not be output.

Changes:
- Updated get_buffer_string() to prioritize tool_calls over function_call
- Maintained backward compatibility with legacy function_call format
- Added tests for tool_calls and priority behavior

The fix ensures tool call information is correctly included in
buffer strings while maintaining compatibility with older code.
@github-actions github-actions bot added the core Related to the package `langchain-core` label Nov 15, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 15, 2025

CodSpeed Performance Report

Merging #33984 will not alter performance

Comparing yashwantbezawada:fix-get-buffer-string-tool-calls (078c660) with master (8a3bb73)

⚠️ 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`

Projects

None yet

1 participant