Simplify role handling in prepare_multimodal_messages#5508
Merged
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
qgallouedec
approved these changes
Apr 10, 2026
qgallouedec
left a comment
Member
There was a problem hiding this comment.
looks good, I'm sure it's on your radar, but tool could contain images now
Member
Author
Yes, @qgallouedec, I think that tool images are already in-lined (not using image placeholders). A somehow related enhancement is addressed in: |
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.
Simplify role handling in
prepare_multimodal_messages.Follow-up to:
This PR simplifies and consolidates the logic in the
prepare_multimodal_messagesfunction for handling different message roles. The main change is that the preparation of message content for theassistant,system, andtoolroles is now handled together, reducing code duplication and improving maintainability.Changes
Refactoring and logic simplification:
assistant,system, andtoolmessage roles into a single code block, reducing repeated code for preparing message content as a list of text entries.systemrole at the top of the function, as it is now handled together with the other roles.Note
Low Risk
Low risk refactor that consolidates per-role branching without changing the public API; main risk is subtle differences in how string
contentis wrapped for non-userroles.Overview
Simplifies
prepare_multimodal_messagesby consolidating thesystem,assistant, andtoolrole handling into a single branch that wraps stringcontentinto structured[{"type": "text", ...}]blocks.Keeps the
user-role logic for injecting image placeholders before the first user message, while reducing duplicated role-specific code paths.Reviewed by Cursor Bugbot for commit ac41714. Bugbot is set up for automated code reviews on this repo. Configure here.