Skip to content

featherweight.messages

messages

Conversion between the messages of a client (AG-UI) and the messages of the model (LangChain).

The wire format is AG-UI's, the storage format is LangChain's: its chat message histories and stores read and write LangChain messages, and they hold what the model needs on the next request (tool call ids, reasoning with its signature). to_langchain and to_agui keep those exactly.

decoded_size

decoded_size(value: str) -> int

The size in bytes of base64 text once decoded, from its length and its padding: nothing is decoded.

count_attachments

count_attachments(
    messages: Sequence[Message],
) -> tuple[int, int]

The number of media parts (image, document, audio, video) of all the messages, and the decoded size in bytes of their data sources. Every turn sends the whole history, so the attachments of earlier messages count.

to_langchain

to_langchain(
    messages: Sequence[Message],
) -> list[BaseMessage]

A client's history as LangChain messages.

A reasoning message (a thought, with its signature) is attached to the assistant message that follows it, as a reasoning content block, which is how LangChain carries it. An activity message is a UI element, not part of the conversation, and is left out. A user message may carry images, documents, audio and video as inline data: they become LangChain content blocks, in order. Raises ValueError for an attachment that is not inline data (a URL), is not base64 or has no mime type, for content that is not text in any other message, and for tool call arguments that are not JSON.

to_agui

to_agui(messages: Sequence[BaseMessage]) -> list[Message]

LangChain messages as AG-UI messages: what a client shows, or sends back. An assistant message that holds thoughts becomes reasoning messages followed by the assistant message. The inverse of to_langchain.