**Structural Suggestion: MessageCleaner
Utility to Minimize Ad-hoc Handling**
#6180
SongChiYoung
started this conversation in
Feature suggestions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
💡 Structural Suggestion:
MessageCleaner
Utility to Minimize Ad-hoc HandlingWhile resolving #6167 and implementing the fix in #6168, I ran into a pattern that might be worth exploring more broadly — especially as model-specific quirks become more common.
Right now, we're beginning to see small but vendor-specific tweaks (e.g., trimming whitespace for Claude, merging multiple system messages for Gemini/Anthropic) that can be hard to isolate cleanly within per-message transformers. If left unstructured, these could slowly accumulate into ad-hoc logic inside
ModelClient.create()
or similar places.To avoid that, I’d like to propose a minimal utility-based pattern that lets us chain cleanups while keeping the core architecture untouched.
✅ Suggested Structure
.merge_system_message()
: Merges multipleSystemMessage
s — same logic from FIX: Anthropic and Gemini could take multiple system message #6118.rstrip_last_assistant()
: Trims trailing whitespace from the finalAssistantMessage
(fixes Claude errors).get_messages()
: Returns the cleaned message listThis design keeps the flow declarative and avoids altering any core interfaces like
ModelClient
.✨ Benefits
.remove_empty_messages()
,.sanitize_names()
, etc.client.create(messages=...)
usage🔍 Example Implementation
If this feels like a reasonable direction, I’d be happy to open a PR to get the ball rolling.
That said, it's small enough that we could even just keep it as an internal helper for now.
Thanks again for your time and consideration! 🙏
Beta Was this translation helpful? Give feedback.
All reactions