Repository navigation
feat(python/adk,a2a): run async macros in ADK toolset and A2A part helpers - #4535
jacobsimionato wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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.
4307e7c to
91d724d
Compare
91d724d to
3cd6857
Compare
…ocessor for async macros Signed-off-by: Jacob Simionato <jsimionato@google.com>
3cd6857 to
4cab3a4
Compare
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 anA2uiRequestProcessor(the per-request object that holds the catalogs, the inference format and itsParser) as aMacroExpanderstage in its transformer pipeline. The ADK (Agent Development Kit) and A2A (Agent-to-Agent) integration packages still parsed model output with the bareParser, which skips that pipeline. As a result, an ADK agent that calledsend_a2ui_json_to_clientsent 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
SendA2uiToClientToolsetnow awaitsprocessor.aparse_response(...)on every tool call, so sync andasync defmacros 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 theMacroExpanderuseson_error="raise", comes back to the model as a tool error it can correct.a2ui-a2aaddsaparse_content_to_parts, letsparse_content_to_partstake anA2uiRequestProcessoras well as aParser, and letsstream_response_to_partsread the async stream fromprocessor.aopen_stream().A2uiPartConverterraisesRuntimeErroron text that holds A2UI tags, andA2uiEventConverterstops feeding partial events into an A2UI text stream. Plain text in partial events still passes through as it arrives.pyproject.tomlfiles (see breaking change 3).Breaking changes and migration
parse_content_to_partsnow raisesTypeErrorwhenparseris neither aParsernor anA2uiRequestProcessor. Duck-typed stand-ins worked before.parse_content_to_parts,A2uiPartConverteron A2UI text) raiseRuntimeErrorwhen the processor's pipeline has message transformers. Useaparse_content_to_partsor the toolset instead. Only pipelines from this stack are affected.a2ui-adkneedsa2ui-agent-sdk>0.13.0(was>0.10.0) and, for thea2aextra,a2ui-a2a>0.5.0(was>0.4.0).a2ui-a2aneedsa2ui-agent-sdk>0.13.0(was>0.11.0). The strict>follows the existing convention: 0.13.0 is the last SDK release withoutaparse_response.fallback-version(the version a build reports when it finds no release tag) moves to 0.14.0 fora2ui-agent-sdkand 0.6.0 fora2ui-a2a.A2uiPartConverteroutput is unchanged for processors without transformers:processor.parse_responsethen calls the sameParserwith the same state. With a catalog-only pipeline, text A2UI is now checked through that pipeline.New public API
Where to review
pyproject.toml)Start here:
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.python/a2ui_a2a/src/a2ui/a2a/parts.py:_validate_parser_and_state,aparse_content_to_parts, and theAsyncResponseStreambranch instream_response_to_parts.python/a2ui_adk/src/a2ui/adk/a2a/part_converter.pyandevent_converter.py: thehas_message_transformschecks that decide between parsing, raising, and skipping A2UI text streaming.Implementation details
python/a2ui_a2a/src/a2ui/a2a/parts.py:_validate_parser_and_stateraisesTypeErrorfor an unknown parser type. For a processor, it raisesRuntimeErrorin the sync helper whenpipeline.has_message_transformsis true, andA2uiCatalogErrorwhenprocessor.accepts_state(state)is false.aparse_content_to_partsawaitsaparse_responsefor a processor and callsparse_responsefor aParser. Like the sync helper, it logs the error type at warning level (full text only at debug, since it may quote the response) and returnsfallback_textwhen no parts were produced.aparse_content_to_partsis exported froma2ui.a2a.python/a2ui_adk/src/a2ui/adk/send_a2ui_to_client_toolset.py:_parse_payload, which compiled and calledvalidate_payloaddirectly when stateless, is replaced byasync def _aparse_payload. Thevalidate_payloadimport is gone.wrapped=False. Multiple blocks are compiled one by one, rewrapped with closing tags, then checked withparser.unwrapso an unterminated string or comment cannot swallow a synthetic closing tag.A2uiParseError.python/a2ui_adk/src/a2ui/adk/a2a/part_converter.py: a new_parse_text_to_partshelper handles both tool string results and text parts. It passesparser=self._processortoparse_content_to_parts.python/a2ui_adk/src/a2ui/adk/a2a/event_converter.py:can_stream_textrequiresprocessor.format.supports_streamingand no message transforms. Otherwise each partial event goes straight toa2ui_part_converter.convert, so plain text still arrives chunk by chunk and text with A2UI tags raises.tests/conformance/test_adk_extensions.pynow patchesRendererState.check_topologyinstead ofvalidate_payload, for the header-only v0.8beginRenderingfixture.tests/test_send_a2ui_to_client_toolset.pyreplaces the mockedvalidate_payloadassertion with real validation against two v1.0 catalogs, covering both a valid and an invalid payload.a2ui-a2aanda2ui-adkdescribe the async helpers and the toolset-only path for async transformers. Both CHANGELOGs haveUnreleasedentries that list the new floors.Verification
Measured at the stack tip (all 11 commits applied):
This PR adds
python/a2ui_a2a/tests/test_macro_parts.py(sync pruning, async macro lowering, async streaming, andAgentCardadvertising only transport catalogs) andpython/a2ui_adk/tests/integration/test_macros_integration.py(toolset macro self-correction retry, text converters with pruning and async-macro rejection,a2ui_rpc_callbackunder exclusive macro hiding, bound-state multi-turn rollback and concurrent calls, and unterminated, stateless, and v0.9 payloads). It also updatespython/a2ui_adk/tests/test_send_a2ui_to_client_toolset.pyandpython/a2ui_adk/tests/conformance/test_adk_extensions.py.