Skip to content

.NET: [Bug]: TextContent.AdditionalProperties dropped by AsAGUIEventStreamAsync for TEXT_MESSAGE_START/TEXT_MESSAGE_CONTENT events #4923

@joelfransson

Description

@joelfransson

Description

When A2A agents send TextPart with metadata (e.g., textContentType: "Markdown"), Part.ToAIContent() correctly stores the metadata in TextContent.AdditionalProperties. However, AsAGUIEventStreamAsync creates TextMessageStartEvent and TextMessageContentEvent with only MessageId, Role, and DeltaAdditionalProperties is silently dropped.

This means the AG-UI client has no way to know how to render the text (Markdown, code, plain text, etc.) from the standard event stream.

The AG-UI protocol supports this

The @ag-ui/core Zod schemas use "passthrough" mode, meaning extra properties on any event are preserved and valid. Adding a metadata field to TEXT_MESSAGE_START / TEXT_MESSAGE_CONTENT events is fully compatible with the AG-UI protocol specification.

Reproduction

  1. Create an A2A agent that returns text with metadata:

    {
      "parts": [{
        "type": "text",
        "text": "Hello world",
        "metadata": { "textContentType": "Markdown" }
      }]
    }
  2. Use MapAGUI to expose the orchestrator as an AG-UI endpoint.

  3. Observe the SSE output:

    data: {"type":"TEXT_MESSAGE_START","messageId":"msg-1","role":"assistant"}
    

    The textContentType metadata is missing.

Expected behavior

AdditionalProperties from TextContent should be forwarded as extra properties on the SSE event JSON, since the AG-UI protocol's passthrough schemas allow it:

data: {"type":"TEXT_MESSAGE_START","messageId":"msg-1","role":"assistant","textContentType":"Markdown"}

Or alternatively, as a nested metadata field:

data: {"type":"TEXT_MESSAGE_START","messageId":"msg-1","role":"assistant","metadata":{"textContentType":"Markdown"}}

Root cause

In ChatResponseUpdateAGUIExtensions.AsAGUIEventStreamAsync, the TextMessageStartEvent is constructed with only two properties:

new TextMessageStartEvent
{
    MessageId = chatResponse.MessageId,
    Role = chatResponse.Role.Value
};

TextContent.AdditionalProperties from the ChatResponseUpdate.Contents is never read or forwarded.

Similarly, TextMessageContentEvent only copies MessageId and Delta:

new TextMessageContentEvent
{
    MessageId = chatResponse.MessageId,
    Delta = textContent.Text
};

Code Sample

Error Messages / Stack Traces

Package Versions

Microsoft.Agents.AI.Hosting.AGUI.AspNetCore: 1.0.0-preview.260121.1 and 1.0.0-preview.260311.1

.NET Version

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions