Skip to content

[Feature]: [mastra] Export a Mastra → AG-UI message converter (reverse of convertAGUIMessagesToMastra) #2175

Description

@giladnavot

Pre-flight Checklist

  • I have searched existing issues and this hasn't been requested yet.
  • I am using the latest version AG-UI.

Describe the Feature

@ag-ui/mastra exports convertAGUIMessagesToMastra (AG-UI → Mastra), but nothing for the reverse direction: converting stored Mastra messages (MastraDBMessage, the parts-based format returned by Mastra's memory API GET /api/memory/threads/:threadId/messages) into AG-UI Message[].

Use case

Restoring thread history into an AG-UI client (e.g. CopilotKit's CopilotChat) from Mastra Memory. Mastra persists full conversation history in its storage, but any frontend that wants to rehydrate a past thread has to hand-roll the MastraDBMessage → AG-UI conversion — mapping content.parts text parts, tool-invocation parts to toolCalls + tool result messages, reasoning parts, etc. That format is non-trivial and an internal detail of Mastra, so every consumer reimplements a lossy subset (typically text-only).

Context: this is the missing piece in CopilotKit/CopilotKit#1881 (Mastra message history support) — see CopilotKit/CopilotKit#1881 (comment) for a working but hand-rolled restore flow that would collapse to one call with this utility.

Proposed shape

export function convertMastraMessagesToAGUI(messages: MastraDBMessage[]): Message[]

covering text, tool calls/results (so restored transcripts keep their tool-call rendering), and reasoning parts — mirroring how the ai-sdk integration ships converters for both directions.

Happy to contribute a PR if the shape is agreed on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions