Skip to content

fix message serialization in Mellea #1030

Closed

Description

@jakelorocco

We are utilizing our Message class both as a regular component and as a way to serialize our components into chat messages inference engines understand.

We need to

  1. Fix our backend serialization pipeline so that we aren't printing Messages twice due to document handling
  2. Add infrastructure for better message serialization (either from components directly or utilizing an intermediate message representation). This will allow use to write custom serialization when required (ie for tool results, etc...).

Related is allowing components to specify roles: #377. Presumably anything else that can be serialized as a chat message to an inference provider might be worth allowing components to expose (ie images?).

Activity

  1. added
    bug
    on May 19, 2026
  2. added
    area/backends
    area/stdlib
    area/tools
    enhancement
    area/component
    and removed on May 20, 2026
  3. added
    p2
    on Jun 18, 2026
  4. jakelorocco commented on Jul 17, 2026

    @jakelorocco
    ContributorAuthor

    Related to: #1405 and #1201

  5. added
    p1
    and removed
    p2
    on Jul 17, 2026
  6. jakelorocco commented on Jul 17, 2026

    @jakelorocco
    ContributorAuthor

    We should also investigate serializing mots as the initial incoming message.

  7. psschwei commented on Jul 20, 2026

    @psschwei
    Contributor

    We should also investigate serializing mots as the initial incoming message.

    I hacked around on this a little bit this morning. Came up with one possible way that this could work, although I didn't go too far on it, so there's probably a number of holes that need plugging.

    Step 1 — Widen the API + add a role override

    Let session.act/act/aact accept a ModelOutputThunk, and add a role override to the mot→Message conversion so a computed mot can be the initial incoming message with an explicit role.

    • The downstream path already works (parsed_repr → message_to_openai_message, including reasoning replay and tool_calls).
    • Guard that the incoming mot is computed above generate_walk (backend.py:362) — otherwise an uncomputed head mot triggers a spurious self-generation.
    • Confirm behavior under the default RejectionSamplingStrategy (a mot-action does not take the strategy is None fast path).

    Step 2 — Make Message._parse the canonical mot serializer

    Use provider-native raw.response recovery instead of the lossy string fallback.

    • Also change the base.py:1169 dispatch so a mot-action gets a real parse path — this is not free; without it the follow-on turn's parsed_repr degrades to a raw string.

    Step 3 — Generalize: let any component declare its role

    Add role to format_for_llm/TemplateRepresentation so components (not just mots) declare their role, retiring the positional guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area/backendsarea/componentarea/stdlibarea/toolsbugenhancementp1

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions