Skip to content

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

Closed
pavelgj wants to merge 1 commit into
mainfrom
pj/py-a2ui-messages-key-4nlp08lpxc
Closed

pavelgj wants to merge 1 commit into
mainfrom
pj/py-a2ui-messages-key-4nlp08lpxc

Conversation

@pavelgj

@pavelgj pavelgj commented Nov 6, 2026

Copy link
Copy Markdown
Member

What's new

The Python a2ui part now carries its A2UI messages under the spec's messages key instead of our own 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, 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, but under a key we made up. The spec's own {messages: [...]} wrapper does the same job and is what renderers read.

This keeps the plugins in step:

Writes Reads
Python (this PR) messages messages or envelopes
JS (#7091) messages messages or envelopes
Go (#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 (a Dart client using the genkit_a2ui 0.5 README helpers sends {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

New tests/part_test.py covers the written key, the legacy key, precedence when both are present, the None fallback and a non-list value. The inbound click test runs with both keys. Test helpers read messages, so every existing output test now checks the written key (21 fail without the change). 66 pass; ruff, ty and pyright clean.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the A2UI extension spec's message list wrapper key from envelopes to messages in the Python package, aligning it with Dart, JS, and Go plugins. It maintains backward compatibility by continuing to read the legacy envelopes key if messages is absent or null. Corresponding tests and documentation have been updated and added to verify this behavior. I have no feedback to provide.

@MichaelDoyle

Copy link
Copy Markdown
Contributor

@pavelgj @huangjeff5 heads up — since Python SDK development has moved to https://github.com/genkit-ai/genkit-python, this Python A2UI companion PR (alongside JS #7091 and Go #7092) will need to move over to genkit-ai/genkit-python.

@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 implementation itself looks good and matches Dart/JS/Go (_messages_of handles None explicitly without falling into the Python or empty-list trap, shares validation between is_a2ui_part and envelopes_from_parts, and tests/helpers.py verifies the new messages write key).

Seconding @MichaelDoyle's note to close this here and re-open against genkit-ai/genkit-python (under packages/genkit-a2ui/). Left one small test coverage suggestion inline to fold in when moving it over.

@pavelgj

pavelgj commented Nov 18, 2026

Copy link
Copy Markdown
Member Author

Closing in favor of genkit-ai/genkit-python#150 (with @chrisraygill's extra test cases folded in).

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 python Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants