Skip to content

refactor(go/plugins/a2ui)!: carry A2UI messages under the spec's messages key - #7092

Merged
pavelgj merged 2 commits into
mainfrom
pj/go-a2ui-messages-key-5l38renjb9
Nov 19, 2026
Merged

pavelgj merged 2 commits into
mainfrom
pj/go-a2ui-messages-key-5l38renjb9

Conversation

@pavelgj

@pavelgj pavelgj commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

What's new

The a2ui part now carries its A2UI messages under the spec's messages key instead of our own envelopes:

{
  "data": { "messages": [ { "version": "v0.9", "createSurface": { "surfaceId": "tokyo-weather", "catalogId": "..." } } ] },
  "metadata": { "mimeType": "application/a2ui+json" }
}

newPart writes "messages". IsPart and EnvelopesFromParts accept either key, so parts written before this change (persisted sessions, older agents) are still read:

for _, env := range a2ui.EnvelopesFromParts(msg.Content) {
	// works for {"messages": [...]} and the older {"envelopes": [...]}
}

IsPart now also requires the value to be a list, matching the JS plugin; before, any value under envelopes made a part count as a2ui.

Why

The A2UI extension spec puts the message list directly in a data part's data. Genkit requires data to be an object (Dart expects a map), so we wrapped the list, but under a key we made up. The spec already has a wrapper for exactly this, the { messages: [...] } payload, which renderer SDKs read as-is. Using it means one less Genkit-specific shape between an agent and a renderer.

This keeps the plugins in step across languages: Genkit Dart made the same change in genkit-ai/genkit-dart#710, and the JS plugin gets it in #7091. Until all three ship, a newer agent and an older client disagree on the key, which is why every reader accepts both.

Writes Reads
Go (this PR) messages messages or envelopes
JS (#7091) messages messages or envelopes
Dart (genkit-ai/genkit-dart#710) messages messages or envelopes

Breaking Changes

The plugin is experimental (exp), but code that reads the part's data map directly needs updating:

// before
raw, _ := part.Data.(map[string]any)["envelopes"].([]any)

// after
envs := a2ui.EnvelopesFromParts([]*ai.Part{part})

Code that uses EnvelopesFromParts needs no change.

Not in this PR

  • Dropping the envelopes fallback. Reading it costs nothing and keeps old sessions replaying; it can go once the plugin leaves exp.
  • Renaming EnvelopesFromParts or the Envelope type. Only the wire key changes.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@chrisraygill chrisraygill left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "messages" rename and shared messagesOf helper look clean. Found two edge cases in messagesOf and some missing test cases inline.

(Coordination note: go/samples/basic-middleware/a2ui pairs with js/testapps/a2ui/web / @genkit-ai/a2ui/client, so #7091 should merge before or alongside this.)

Comment thread go/plugins/a2ui/exp/part.go Resolved
Comment thread go/plugins/a2ui/exp/part_test.go Resolved
@pavelgj
pavelgj merged commit c841c51 into main Nov 19, 2026
24 checks passed
@pavelgj
pavelgj deleted the pj/go-a2ui-messages-key-5l38renjb9 branch November 19, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation go

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants