Repository navigation
[Fix] Preserve tool-result image ownership - #2
Closed
silencelamb wants to merge 3 commits into
Closed
silencelamb wants to merge 3 commits into
silencelamb wants to merge 3 commits into
Conversation
Keep Anthropic tool images with their tool_call_id and preserve surrounding user content order. Align GLM-5.3 multimodal tool results before both prompt rendering and media collection, and support Responses image outputs with grouped parallel calls. Add protocol, HTTP/SSE, and shared preprocessing regressions and update English/Chinese documentation.
Add streaming and non-streaming Chat HTTP tests with real image decoding and shared tool-result ordering. Clarify that the model-specific fix targets GLM-5.3-Flash and distinguish three-protocol preprocessing tests from HTTP endpoint tests.
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.
Motivation
Parallel tool results can return images in a different order from the assistant's tool calls. LMDeploy currently loses their ownership in two places:
tool_use_id.Responses additionally rejects images inside
function_call_outputand emits consecutive parallel calls as separate assistant messages.Modification
tool_call_id, preserving internal block order. Flush ordinary user content before each tool result so surrounding text and images keep their original position.function_call_output.outputtext/image arrays through the existing image converter, and group consecutivefunction_callitems into one assistant call group.The model-specific gate matches
Glm5NextForConditionalGeneration, the multimodal architecture used by GLM-5.3-Flash. Plain GLM-5.3 usesGlmMoeDsaForCausalLMand does not enter this ordering path.BC-breaking (Optional)
No new dependency requirements or public request fields. Tool images now stay attached to their tool result instead of becoming standalone user messages. Text-only tool-result formatting is preserved; consecutive Responses calls are correctly grouped as one parallel invocation.
Use cases (Optional)
Replay screenshot tools whose results arrive in reverse order, or return multiple images and surrounding text from each tool. Chat, Messages, and Responses use the same multimodal preparation path. Responses examples are included in the updated documentation.
Validation
python -m pytest tests/test_lmdeploy/serve -q). HTTP/SSE tests use fake generation; shared preprocessing tests decode real image data.git diff --checkpassed.The PR1 base now also includes 150 shared user-image regressions; they pass together with the PR2 tool-image tests.
Three-endpoint coverage
/v1/chat/completions/v1/messages/v1/responsestests/test_lmdeploy/serve/test_tool_images.pyparameterizesprotocoloverchat,messages, andresponses. Its main matrix has 36 cases (3 protocols × 6 permutations × 2 image counts). These are conversion/shared-preprocessing tests, not HTTP requests. Additional tests cover ambiguous IDs, partial groups, mixed text/image results, non-GLM templates, and user/round boundaries.HTTP/SSE regression locations:
tests/test_lmdeploy/serve/openai/chat_completions/test_chat_tool_images.py.tests/test_lmdeploy/serve/anthropic/test_endpoints.py::test_http_tool_result_images_keep_their_ids_and_content_order.tests/test_lmdeploy/serve/openai/responses/test_images.py::test_http_tool_images_preserve_parallel_calls_and_result_ownership.Dependency and review scope
This is PR2, based on the Responses user-image commit in InternLM/lmdeploy#5043. This fork PR targets
feat/responses-image-inputso its diff contains only the tool-image changes. Submit the incremental fix upstream after PR1 merges.Checklist