Skip to content

refactor(a2ui)!: carry A2UI messages under the spec's messages key - #150

Merged
pavelgj merged 1 commit into
mainfrom
pj/py-a2ui-messages-key-4nlp08lpxc
Nov 19, 2026
Merged

pavelgj merged 1 commit into
mainfrom
pj/py-a2ui-messages-key-4nlp08lpxc

Conversation

@pavelgj

@pavelgj pavelgj commented Nov 18, 2026

Copy link
Copy Markdown
Member

Moved from genkit-ai/genkit#7118 following the Python SDK repository split (includes the review test additions from @chrisraygill).

What's new

The Python genkit-a2ui part now carries its A2UI messages under the spec's messages key instead of envelopes, matching the Dart, JS, and Go plugins:

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

a2ui_part writes {"messages": [...]}. is_a2ui_part and envelopes_from_parts read either key, so parts written before this change (persisted sessions, older clients) still work. messages wins when both are present (including {"messages": []}), and a messages that is present but None falls back to envelopes. Calling code is unchanged:

envelopes = envelopes_from_parts(response.message.content)

Why

The A2UI extension spec puts the message list in a data part's data. Genkit needs data to be an object, so we wrapped the list, previously under a custom envelopes key. The spec's own {messages: [...]} wrapper does the same job and is what renderers read.

This keeps the plugins aligned across languages:

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

It also means user actions from a client on the new key (for example a Dart client using the genkit_a2ui README helpers sending {messages: [{version, action}]}) reach the model as [UI action ...] lines instead of a bare [UI].

Breaking Changes

The package is experimental, but code that reads part.data['envelopes'] directly must switch to envelopes_from_parts(...) (or read messages). Code that uses envelopes_from_parts needs no change.

Not in this PR

  • Dropping the envelopes fallback. Reading it is free and keeps old sessions replaying.
  • Renaming envelopes_from_parts or other identifiers. Only the wire key changes.
  • The Express output format the Dart plugin moved to. Python still uses fenced JSON blocks.

Testing

tests/part_test.py covers the written key, legacy envelopes reads, precedence when both keys are present (including empty messages: []), None fallback, non-list values under either key, and wrong/missing mimeType / text-part negative cases. The inbound click test runs with both keys. Test helpers read messages, so every existing output test checks the written key. 68 pass; ruff and ty clean.

@pavelgj
pavelgj merged commit 3165c78 into main Nov 19, 2026
20 checks passed
@pavelgj
pavelgj deleted the pj/py-a2ui-messages-key-4nlp08lpxc branch November 19, 2026 17:25
@huangjeff5 huangjeff5 mentioned this pull request Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants