Skip to content

fix: preserve provider tool call metadata in legacy chat completions - #1023

Open
andreitava-uip wants to merge 4 commits into
mainfrom
fix/legacy-openai-tool-call-metadata
Open

fix: preserve provider tool call metadata in legacy chat completions#1023
andreitava-uip wants to merge 4 commits into
mainfrom
fix/legacy-openai-tool-call-metadata

Conversation

@andreitava-uip

@andreitava-uip andreitava-uip commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Why

BYOM models exposed through an OpenAI V1-compatible Chat Completions API may return provider-specific tool-call metadata that must be included in subsequent requests. The legacy client currently drops these fields during the LangChain message round trip, causing multi-turn tool execution to fail for providers that require them.

Summary

  • preserve provider-specific top-level fields on OpenAI-compatible tool calls
  • restore preserved fields when conversation history is sent through Chat Completions
  • retain message metadata when agent flows replace or modify tool calls
  • support non-streaming, streaming, and multiple tool calls

Testing

  • uv run pytest tests/chat/test_openai_tool_call_extras.py tests/agent/messages/test_message_utils.py -q
  • uv run mypy --config-file pyproject.toml .
  • uv run ruff check .
  • uv run ruff format --check .
  • uv run python scripts/lint_httpx_client.py

Copilot AI review requested due to automatic review settings August 6, 2026 10:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes multi-turn tool execution for BYOM/OpenAI-compatible Chat Completions providers by preserving provider-specific (non-standard) tool-call fields through the LangChain message conversion round trip, and reattaching them when sending subsequent requests.

Changes:

  • Capture and persist non-standard, provider-specific top-level tool-call fields into AIMessage.additional_kwargs during completion/chunk conversion.
  • Restore preserved tool-call fields into the outgoing Chat Completions request payload (including multiple tool calls).
  • Ensure agent flows that replace tool calls keep additional_kwargs, and add coverage for non-streaming + streaming scenarios.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/chat/test_openai_tool_call_extras.py Adds regression tests validating tool-call extras survive round trips, reordering, streaming chunk merge, and final-chunk behavior.
src/uipath_langchain/chat/_legacy/openai.py Implements storage/restoration of provider-specific tool-call fields via a mixin on the legacy OpenAI chat client.
src/uipath_langchain/agent/messages/message_utils.py Preserves additional_kwargs when replacing tool calls to avoid losing stored tool-call extras.

@andreitava-uip
andreitava-uip marked this pull request as draft August 6, 2026 10:55
@sonarqubecloud

sonarqubecloud Bot commented Aug 6, 2026

Copy link
Copy Markdown

@andreitava-uip
andreitava-uip marked this pull request as ready for review August 6, 2026 15:08
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.

3 participants