ChatFormatter for converting context histories to chat-message lists.
ChatFormatter is the standard formatter used by mellea’s legacy backends. Its
to_chat_messages method linearises a sequence of Component and CBlock
objects into Message objects with user, assistant, or tool roles,
handling ModelOutputThunk responses, image attachments, and parsed structured
outputs. Concrete backends call this formatter when preparing input for a chat
completion endpoint.
Classes
CLASS ChatFormatter
Formatter used by Legacy backends to format Contexts as Messages.
Methods:
FUNC to_chat_messages
Message with an appropriate role. ModelOutputThunk instances are
treated as assistant responses, while all other Component and
CBlock objects default to the user role. Image attachments and
parsed structured outputs are handled transparently.
Args:
cs: The linearized sequence of context components and code blocks to convert.
- list[Message]: A list of
Messageobjects ready for submission to a chat completion endpoint.