fix(context): preserve multimodal content during compression - #7857
Closed
qWaitCrypto wants to merge 1 commit into
Closed
qWaitCrypto wants to merge 1 commit into
qWaitCrypto wants to merge 1 commit into
Conversation
Collaborator
|
Thanks for the thorough write-up and the tests! The bugs you identified are real — but the same fix landed on Automated hermes-sweeper review — closing as implemented on main.
If you find any remaining edge cases not covered by the current implementation, feel free to open a new focused issue or PR. |
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.
What does this PR do?
Fixes a
ContextCompressorbug when conversation history contains structured or multimodalcontent(e.g. list-valued message content with text/image blocks).Before this change,
ContextCompressorassumedmsg["content"]was always a string in several compression paths. That caused two problems:TypeError:can only concatenate str (not "list") to strwhen the first tail message had list-valued contentThis patch adds a
_coerce_content_to_text()helper that normalizes structured content to readable text where text is needed, while preserving multimodal list structure when merging a summary into the tail message.Manually verified against real multimodal request shapes from OpenAI-style chat completions, OpenAI-style responses, and an Anthropic-compatible messages endpoint.
Related Issue
No existing issue — discovered during code review of the compression paths.
Type of Change
Changes Made
_coerce_content_to_text()inagent/context_compressor.pyto normalize structured / multimodal message content into readable text for compression logic.agent/context_compressor.pyto use normalized text for summary serialization, tail token estimation, old tool-result pruning, and system-note appending.agent/context_compressor.pyso list-valued multimodal content keeps its original structure by prepending a new text block instead of flattening the whole message into a string.input_imageparts that useurlinstead ofimage_url.tests/agent/test_context_compressor.pyfor:input_image.urlfallback)How to Test
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
cli-config.yaml.exampleif I added/changed config keys — or N/A