Repository navigation
fix(formatter): forward the images of collapsed messages in xAI multi-agent history - #2808
Merged
qbc2016 merged 2 commits intoSep 24, 2026
Merged
Conversation
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.
AgentScope Version
2.0.8—import agentscope; print(agentscope.__version__)on this PR's basecommit
083cbd1.What this PR does
XAIMultiAgentFormatter.format()now forwards the images of the messages itcollapses into conversation history, instead of keeping only their text.
The formatter declares
["text/plain", "image/jpeg", "image/png"]as itsinput_types, but its history path had noDataBlockbranch, so every imagecarried by a non-tool message disappeared silently — no exception, no warning,
just a prompt that is missing the attachment the agent was asked about. The
current user message is affected too, not only media deep in the history.
Why it matters
Fixes #2806, which carries the reproducer:
XAIChatFormatter→True,XAIMultiAgentFormatter→False(the marker is nowhere in the output)XAIChatFormatter→True,XAIMultiAgentFormatter→True#2806 asks which side should change: carry the media, or stop advertising image
input. This PR carries it, because that is what the rest of the repo already
does —
OpenAIMultiAgentFormatter._format_agent_messagecollectsTextBlocks intothe history text, formats
DataBlocks separately and appends them to the sameuser message (
_openai_formatter.py:513-523,:557);AnthropicMultiAgent…does the same.
XAIMultiAgentFormatteris the only multi-agent formatter thatadvertises images and forwards none.
XAIMultiAgentFormatteralready delegates its tool sequences toXAIChatFormatter, which formats this exactDataBlockcorrectly, so the twopaths of one provider disagreed about whether an image can be sent at all.
Dropping the two image types from
input_typesinstead would take away acapability the xAI side supports.
The conversion itself is
XAIChatFormatter's existing_xai_user_args_from_blocks(), moved to module level verbatim so bothformatters share one implementation — the same shape
_moonshot_formatter.py:24uses for_moonshot_format_image_source(), whichits chat and multi-agent classes also share. Its two
HintBlockcall sites werere-pointed; no conversion rule changed, so
XAIChatFormatteroutput isbyte-identical (its 18 existing tests pass unmodified). One wording change came
with the move: the "unsupported media type" warning no longer says hint
sub-block, since the helper now serves the history path too.
How is it tested
New case
test_multiagent_formatter_history_keeps_imagesintests/formatter_xai_test.py, asserting the whole returned structure per.github/copilot-instructions.md§3: two collapsed messages produce oneusermessage whose history text is unchanged and which carries both images — a
base64
image/jpegand a remoteimage/pngURL — in message order.Measured on a local checkout, Python 3.12.11 / Windows:
srcat083cbd1:1 failed, 18 passed(tests/formatter_xai_test.py).src:19 passed.formatter_xai_test.py+model_xai_test.py:33 passed.pytest -k formatter tests):137 passed, 2 skipped, 4 subtests passed.pytest tests:4 failed, 2329 passed, 306 skipped, 117 subtests passed in 655s. All 4 failures are intests/realtime_agent_test.py, which fails the same 3–4 cases when run aloneon the unpatched base commit (
3 failed, 16 passedand4 failed, 15 passedacross repeated runs of identical code) — pre-existing timing flakiness on
Windows, untouched by this change. No formatter test fails on either side.
Pre-commit,Python Unittest Coverage,PR Title Check,PR State Labelsand
GitHub Monitorallcompleted/successat head8316f5f, on two readstaken 2 minutes apart.
Lint with the versions and arguments pinned in
.pre-commit-config.yaml(
black 23.3.0 --line-length=79,flake8 6.1.0 --extend-ignore=E203,mypy v1.7.0with the CI--disable-error-codelist,pylint v3.0.2with the CI--disablelist) — clean on both changed files, pylint10.00/10.pre-commit run --all-filesitself could not be run here (it downloads its hookenvironments), so it was reproduced hook by hook.
Checklist
format()docstrings in this module were updated insteadNote on authorship
This PR was prepared and measured autonomously by an AI agent operating the
Lesereingrapeaccount. No human has reviewed the diff line by line, so pleasetreat it as needing a full review rather than an approved one.