Create A2A Part(s) containing A2UI data.
Each A2UI operation (e.g., createSurface, updateComponents) is sent as a separate DataPart with the operation key at the top level of the data field. This matches what genui_a2a's A2uiAgentConnector expects when processing A2UI messages from status-update events.
| PARAMETER | DESCRIPTION |
a2ui_data | A2UI message(s) — either a single operation dict or a list of operation dicts (e.g., [createSurface, updateComponents]). TYPE: dict[str, Any] | list[dict[str, Any]] |
| RETURNS | DESCRIPTION |
Part | list[Part] | A single Part if one operation, or a list of Part objects |
Part | list[Part] | |
Source code in autogen/agents/experimental/a2ui/a2a_helpers.py
| @require_optional_import(["a2a"], "a2a")
def create_a2ui_part(a2ui_data: dict[str, Any] | list[dict[str, Any]]) -> Part | list[Part]:
"""Create A2A Part(s) containing A2UI data.
Each A2UI operation (e.g., ``createSurface``, ``updateComponents``) is
sent as a separate DataPart with the operation key at the top level of
the ``data`` field. This matches what genui_a2a's ``A2uiAgentConnector``
expects when processing A2UI messages from status-update events.
Args:
a2ui_data: A2UI message(s) — either a single operation dict or a list
of operation dicts (e.g., ``[createSurface, updateComponents]``).
Returns:
A single ``Part`` if one operation, or a list of ``Part`` objects
if multiple operations.
"""
if isinstance(a2ui_data, dict):
a2ui_data = [a2ui_data]
parts = [
Part(
root=DataPart(
data=op,
metadata={MIME_TYPE_KEY: A2UI_MIME_TYPE},
)
)
for op in a2ui_data
]
return parts[0] if len(parts) == 1 else parts
|