fix: preserve provider tool call metadata in legacy chat completions - #1023
Open
andreitava-uip wants to merge 4 commits into
Open
fix: preserve provider tool call metadata in legacy chat completions#1023andreitava-uip wants to merge 4 commits into
andreitava-uip wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
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_kwargsduring 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
marked this pull request as draft
August 6, 2026 10:55
|
andreitava-uip
marked this pull request as ready for review
August 6, 2026 15:08
ionut-mihalache-uipath
approved these changes
Aug 6, 2026
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.



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
Testing
uv run pytest tests/chat/test_openai_tool_call_extras.py tests/agent/messages/test_message_utils.py -quv run mypy --config-file pyproject.toml .uv run ruff check .uv run ruff format --check .uv run python scripts/lint_httpx_client.py