Skip to content

fix(uitars): correct message ordering to prevent litellm serialization#943

Open
sudhanshu112233shukla wants to merge 1 commit intotrycua:mainfrom
sudhanshu112233shukla:fix/uitars-litellm-error
Open

fix(uitars): correct message ordering to prevent litellm serialization#943
sudhanshu112233shukla wants to merge 1 commit intotrycua:mainfrom
sudhanshu112233shukla:fix/uitars-litellm-error

Conversation

@sudhanshu112233shukla
Copy link

This change fixes a LiteLLM serialization error encountered when using UI-TARS models with Hugging Face TGI endpoints. The error occurred because the message history was being constructed in the wrong order—placing the current prompt before the historical messages—leading to consecutive user role messages when the history ended with a screenshot. Since the TGI API enforces strict role alternation, this resulted in a deserialization failure. To resolve this, the message construction logic in libs/python/agent/agent/loops/uitars.py was updated to follow the correct order: system message first, followed by the conversation history, and finally the current prompt. Additionally, logic was added to detect and merge consecutive user messages, ensuring that screenshots and text prompts are combined into a single user message when necessary. The fix was verified through compilation checks, AST validation, function signature verification, message-ordering logic checks, integration testing, and simulation testing, all of which passed successfully. This update eliminates the “Failed to deserialize the JSON body” error for UI-TARS models, ensures compatibility with TGI’s strict message format requirements, and introduces no breaking changes to existing functionality.#365

@vercel
Copy link
Contributor

vercel bot commented Jan 31, 2026

@sudhanshu112233shukla is attempting to deploy a commit to the Cua Team on Vercel.

A member of the Team first needs to authorize it.

…n errors

Reordered messages from [System, Prompt, History] to [System, History, Prompt] and added logic to merge consecutive user messages (image + text) to comply with TGI API requirements.
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.

1 participant