Skip to content

feat(python/adk,a2a): run async macros in ADK toolset and A2A part helpers - #4535

Open
jacobsimionato wants to merge 1 commit into
macros/7-hiding-prompts-examplesfrom
macros/8-adk-a2a-integration
Open

jacobsimionato wants to merge 1 commit into
macros/7-hiding-prompts-examplesfrom
macros/8-adk-a2a-integration

Conversation

@jacobsimionato

@jacobsimionato jacobsimionato commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Earlier PRs in this stack added macros: Python functions, sync or async def, that expand into A2UI components on the server. Macros run inside an A2uiRequestProcessor (the per-request object that holds the catalogs, the inference format and its Parser) as a MacroExpander stage in its transformer pipeline. The ADK (Agent Development Kit) and A2A (Agent-to-Agent) integration packages still parsed model output with the bare Parser, which skips that pipeline. As a result, an ADK agent that called send_a2ui_json_to_client sent unexpanded macro components to the client, and A2A servers had no async way to run macros before converting a response into A2A parts.

Two kinds of pipeline stage matter here. Message transformers, such as MacroExpander, rewrite the model's messages and can be async, so they need the processor's async methods (aparse_response, aopen_stream). Catalog-only stages, such as component pruning, only narrow the catalogs and also work on the synchronous path.

Stack: 11/11 (overview) · previous: #4534 · next: none

Reviewer guide: A2UI Python macros: reviewer guide explains how the whole stack fits together.

Summary

  1. SendA2uiToClientToolset now awaits processor.aparse_response(...) on every tool call, so sync and async def macros expand before validation. When the processor has no renderer state (the client's record of its surfaces), the toolset accepts updates to surfaces created on an earlier turn (assume_unknown_surfaces=True). A macro that raises, when the MacroExpander uses on_error="raise", comes back to the model as a tool error it can correct.
  2. a2ui-a2a adds aparse_content_to_parts, lets parse_content_to_parts take an A2uiRequestProcessor as well as a Parser, and lets stream_response_to_parts read the async stream from processor.aopen_stream().
  3. ADK's part and event converter hooks are synchronous, so text-based A2UI there supports catalog-only pipelines only. With a message-transforming pipeline, A2UI must go through the toolset: A2uiPartConverter raises RuntimeError on text that holds A2UI tags, and A2uiEventConverter stops feeding partial events into an A2UI text stream. Plain text in partial events still passes through as it arrives.
  4. Version bumps and higher dependency floors in three pyproject.toml files (see breaking change 3).
  5. End-to-end tests run real ADK agents and the A2A executor with macro pipelines.

Breaking changes and migration

  1. parse_content_to_parts now raises TypeError when parser is neither a Parser nor an A2uiRequestProcessor. Duck-typed stand-ins worked before.
  2. The sync paths (parse_content_to_parts, A2uiPartConverter on A2UI text) raise RuntimeError when the processor's pipeline has message transformers. Use aparse_content_to_parts or the toolset instead. Only pipelines from this stack are affected.
  3. Dependency floors: a2ui-adk needs a2ui-agent-sdk>0.13.0 (was >0.10.0) and, for the a2a extra, a2ui-a2a>0.5.0 (was >0.4.0). a2ui-a2a needs a2ui-agent-sdk>0.13.0 (was >0.11.0). The strict > follows the existing convention: 0.13.0 is the last SDK release without aparse_response. fallback-version (the version a build reports when it finds no release tag) moves to 0.14.0 for a2ui-agent-sdk and 0.6.0 for a2ui-a2a.

A2uiPartConverter output is unchanged for processors without transformers: processor.parse_response then calls the same Parser with the same state. With a catalog-only pipeline, text A2UI is now checked through that pipeline.

New public API

from a2ui.a2a import aparse_content_to_parts, stream_response_to_parts
from a2ui.adk import SendA2uiToClientToolset
from a2ui.processor import A2uiRequestProcessor
from a2ui.transformers.macros import MacroExpander

# ADK: tool calls now expand macros (AlbumCard is a @macro function).
processor = A2uiRequestProcessor(catalogs=[basic], transformers=[MacroExpander([AlbumCard])])
toolset = SendA2uiToClientToolset(a2ui_enabled=True, a2ui_processor=processor)

# A2A, whole response: runs the pipeline, including async def macros.
parts = await aparse_content_to_parts(llm_text, processor, fallback_text="...")

# A2A, streaming: token_stream is an async iterable of model text chunks.
async for part in stream_response_to_parts(processor.aopen_stream(), token_stream):
    ...

Where to review

Category Files Diff (+/-)
Production 5 +235 / -67
Packaging (pyproject.toml) 3 +9 / -9
Tests 4 +1250 / -11
Docs and changelogs 4 +43 / -11
Total 16 +1537 / -98

Start here:

  1. python/a2ui_adk/src/a2ui/adk/send_a2ui_to_client_toolset.py: _aparse_payload. When a tool call holds several A2UI blocks, each is compiled on its own before they are joined, so a block missing its end cannot hide the next one.
  2. python/a2ui_a2a/src/a2ui/a2a/parts.py: _validate_parser_and_state, aparse_content_to_parts, and the AsyncResponseStream branch in stream_response_to_parts.
  3. python/a2ui_adk/src/a2ui/adk/a2a/part_converter.py and event_converter.py: the has_message_transforms checks that decide between parsing, raising, and skipping A2UI text streaming.
Implementation details
  1. python/a2ui_a2a/src/a2ui/a2a/parts.py:
    1. _validate_parser_and_state raises TypeError for an unknown parser type. For a processor, it raises RuntimeError in the sync helper when pipeline.has_message_transforms is true, and A2uiCatalogError when processor.accepts_state(state) is false.
    2. aparse_content_to_parts awaits aparse_response for a processor and calls parse_response for a Parser. Like the sync helper, it logs the error type at warning level (full text only at debug, since it may quote the response) and returns fallback_text when no parts were produced.
    3. aparse_content_to_parts is exported from a2ui.a2a.
  2. python/a2ui_adk/src/a2ui/adk/send_a2ui_to_client_toolset.py:
    1. The sync _parse_payload, which compiled and called validate_payload directly when stateless, is replaced by async def _aparse_payload. The validate_payload import is gone.
    2. A single block is parsed with wrapped=False. Multiple blocks are compiled one by one, rewrapped with closing tags, then checked with parser.unwrap so an unterminated string or comment cannot swallow a synthetic closing tag.
    3. An empty payload or a result with no A2UI messages raises A2uiParseError.
  3. python/a2ui_adk/src/a2ui/adk/a2a/part_converter.py: a new _parse_text_to_parts helper handles both tool string results and text parts. It passes parser=self._processor to parse_content_to_parts.
  4. python/a2ui_adk/src/a2ui/adk/a2a/event_converter.py: can_stream_text requires processor.format.supports_streaming and no message transforms. Otherwise each partial event goes straight to a2ui_part_converter.convert, so plain text still arrives chunk by chunk and text with A2UI tags raises.
  5. Test harness changes:
    1. tests/conformance/test_adk_extensions.py now patches RendererState.check_topology instead of validate_payload, for the header-only v0.8 beginRendering fixture.
    2. tests/test_send_a2ui_to_client_toolset.py replaces the mocked validate_payload assertion with real validation against two v1.0 catalogs, covering both a valid and an invalid payload.
  6. READMEs for a2ui-a2a and a2ui-adk describe the async helpers and the toolset-only path for async transformers. Both CHANGELOGs have Unreleased entries that list the new floors.
Verification

Measured at the stack tip (all 11 commits applied):

  1. Full Python suite passes (6027 passed).
  2. mypy is clean (283 source files).
  3. 56 conformance goldens are valid.
  4. Prettier and pyink are clean on every commit, and every commit has a DCO sign-off.

This PR adds python/a2ui_a2a/tests/test_macro_parts.py (sync pruning, async macro lowering, async streaming, and AgentCard advertising only transport catalogs) and python/a2ui_adk/tests/integration/test_macros_integration.py (toolset macro self-correction retry, text converters with pruning and async-macro rejection, a2ui_rpc_callback under exclusive macro hiding, bound-state multi-turn rollback and concurrent calls, and unterminated, stateless, and v0.9 payloads). It also updates python/a2ui_adk/tests/test_send_a2ui_to_client_toolset.py and python/a2ui_adk/tests/conformance/test_adk_extensions.py.

@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 introduces support for asynchronous macros and transformer pipelines across the A2A and ADK packages. Key changes include updating parse_content_to_parts to accept A2uiRequestProcessor, adding the asynchronous aparse_content_to_parts function, and extending stream_response_to_parts to support AsyncResponseStream. In the ADK package, A2uiPartConverter and SendA2uiToClientToolset are updated to route through the processor's parsing methods (parse_response and aparse_response respectively) to ensure both synchronous and asynchronous macros execute correctly before transport validation. Comprehensive unit and integration tests have been added to verify these changes. I have no further feedback to provide as no review comments were submitted.

@jacobsimionato jacobsimionato changed the title feat(python/adk,a2a): route ADK and A2A helpers through A2uiRequestProcessor for macro support feat(python/adk,a2a): route helpers through A2uiRequestProcessor Dec 2, 2026
@jacobsimionato
jacobsimionato force-pushed the macros/8-adk-a2a-integration branch from 4307e7c to 91d724d Compare December 2, 2026 23:17
@jacobsimionato
jacobsimionato removed this pull request from stack #4536 December 2, 2026 23:18
@jacobsimionato
jacobsimionato removed this pull request from stack #4552 December 3, 2026 12:03
@jacobsimionato
jacobsimionato force-pushed the macros/8-adk-a2a-integration branch from 91d724d to 3cd6857 Compare December 3, 2026 12:04
@jacobsimionato
jacobsimionato marked this pull request as ready for review December 3, 2026 12:04
@jacobsimionato
jacobsimionato removed this pull request from stack #4563 December 3, 2026 12:06
@jacobsimionato jacobsimionato changed the title feat(python/adk,a2a): route helpers through A2uiRequestProcessor feat(python/adk,a2a): run async macros in ADK toolset and A2A part helpers Dec 3, 2026
…ocessor for async macros

Signed-off-by: Jacob Simionato <jsimionato@google.com>
@jacobsimionato
jacobsimionato force-pushed the macros/8-adk-a2a-integration branch from 3cd6857 to 4cab3a4 Compare December 3, 2026 12:24

This branch has not been deployed

No deployments
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.

1 participant