Skip to main content
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

to_chat_messages(self, cs: list[Component | CBlock]) -> list[Message]
Convert a linearized chat history into a list of chat messages. Iterates over each element in the context history and converts it to a 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.
Returns:
  • list[Message]: A list of Message objects ready for submission to a chat completion endpoint.