Does A2UI Support Python? A Complete Guide to the A2UI Python SDK

Yes, A2UI offers comprehensive Python support through a first-class SDK located in agent_sdks/python/ that enables developers to generate, parse, validate, and transmit A2UI UI payloads.

The Google A2UI repository provides a complete Python implementation that allows developers to build agents capable of creating structured user interface definitions. This Python SDK handles everything from schema management to payload repair, making it straightforward to integrate A2UI capabilities into existing Python-based agent workflows.

Python SDK Architecture and Key Components

The A2UI Python SDK is organized into several focused modules under agent_sdks/python/src/a2ui/. Each component handles a specific aspect of the A2UI workflow, from schema validation to protocol bridging.

Core Schema Management with A2uiSchemaManager

The A2uiSchemaManager class in agent_sdks/python/src/a2ui/core/schema/manager.py serves as the central hub for schema operations. It loads A2UI JSON schemas for specific specification versions, manages component catalogs, and builds system prompts for LLMs.

Key capabilities include:

  • Loading server-to-client and common-types schemas for versions like "0.9"
  • Combining schemas with selected catalogs for validation
  • Rendering complete schemas as LLM instructions
  • Validating UI payloads against loaded schemas

A2A Protocol Bridge

The agent_sdks/python/src/a2ui/a2a.py module provides essential bridging functions between A2UI and the A2A (Agent-to-Agent) protocol. This allows A2UI payloads to be transmitted within standard A2A message parts.

Key functions include:

  • create_a2ui_part(): Wraps A2UI JSON into an A2A Part with MIME type application/json+a2ui
  • is_a2ui_part(): Detects A2UI content by checking MIME types
  • get_a2ui_agent_extension(): Exposes the A2UI AgentExtension header for capability negotiation

Response Parsing and Payload Repair

LLM outputs often contain mixed content with embedded A2UI JSON blocks. The agent_sdks/python/src/a2ui/core/parser/parser.py module handles extraction and sanitization.

The parse_response() function:

  • Extracts <a2ui-json> blocks from raw LLM text
  • Sanitizes extracted JSON
  • Applies the payload fixer to repair common LLM errors like missing commas or stray backticks

The agent_sdks/python/src/a2ui/core/parser/payload_fixer.py module automatically repairs malformed JSON before deserialization, handling syntax errors that LLMs frequently introduce.

Working with A2UI in Python: Practical Examples

The following examples demonstrate common workflows using the A2UI Python SDK.

Creating and Wrapping A2UI Payloads

To generate an A2UI payload and prepare it for transmission via A2A:

from a2ui.a2a import create_a2ui_part

# Define the A2UI UI payload structure

a2ui_payload = {
    "beginRendering": {
        "surfaceId": "main",
        "root": "root-card"
    },
    "components": {
        "root-card": {
            "type": "Card",
            "children": ["title", "body"]
        },
        "title": {"type": "Text", "value": "Hello from Python!"},
        "body": {"type": "Text", "value": "This UI was generated by a Python agent."}
    }
}

# Wrap in an A2A Part for transmission

a2ui_part = create_a2ui_part(a2ui_payload)

The create_a2ui_part function constructs an A2A Part with the MIME type application/json+a2ui, ensuring compatibility with A2A transports.

Detecting A2UI Content in Incoming Messages

When receiving A2A messages, use the detection utilities to identify A2UI payloads:

from a2ui.a2a import is_a2ui_part, get_a2ui_datapart

def handle_part(part):
    if is_a2ui_part(part):
        data_part = get_a2ui_datapart(part)
        a2ui_json = data_part.data  # The raw A2UI dictionary

        
        # Process the UI payload or pass to renderer

        print("Received A2UI payload:", a2ui_json)
    else:
        # Handle standard text parts

        print("Text:", part.root.text)

The is_a2ui_part function checks for the specific MIME type, while get_a2ui_datapart safely extracts the data payload.

Parsing Mixed LLM Responses

LLM outputs often combine conversational text with A2UI JSON blocks. Extract structured data using the response parser:

from a2ui.core.parser.parser import parse_response
from a2ui.a2a import create_a2ui_part

llm_output = """
Sure! Here is the UI you requested:

<a2ui-json>
{
  "beginRendering": {"surfaceId":"main","root":"root"},
  "components": {
    "root": {"type":"Card","children":["title"]},
    "title": {"type":"Text","value":"Welcome!"}
  }
}
</a2ui-json>

Let me know if you'd like any changes.
"""

parts = []
for resp in parse_response(llm_output):
    if resp.a2ui_json:
        parts.append(create_a2ui_part(resp.a2ui_json))
    if resp.text:
        parts.append(resp.text)  # plain conversational text

The parse_response function handles extraction, JSON sanitization, and automatic repair of common LLM syntax errors via the integrated payload fixer.

Validating Payloads Against Schemas

Ensure A2UI payloads conform to the specification using the schema manager:

from a2ui.core.schema.manager import A2uiSchemaManager
from a2ui.core.schema.catalog import CatalogConfig
from a2ui.basic_catalog.provider import BasicCatalog

# Configure the catalog

catalog_cfg = CatalogConfig(
    name="basic",
    provider=BasicCatalog(),
    examples_path="specification/v0_9/json/catalogs/minimal",
)

# Initialize the schema manager

schema_mgr = A2uiSchemaManager(
    version="0.9",
    catalogs=[catalog_cfg],
    accepts_inline_catalogs=False,
)

# Validate a UI payload

ui_payload = {...}  # your A2UI JSON

catalog = schema_mgr.get_selected_catalog()
catalog.validate(ui_payload)  # raises if invalid

The A2uiSchemaManager loads the appropriate schemas for the specified version and manages catalog validation.

Key Source Files for Python Support

The following files in the google/A2UI repository implement the Python SDK:

File Role in Python Support
agent_sdks/python/src/a2ui/a2a.py Bridges A2UI with the A2A protocol through create_a2ui_part, is_a2ui_part, and get_a2ui_agent_extension.
agent_sdks/python/src/a2ui/core/schema/manager.py Implements A2uiSchemaManager for loading schemas, managing catalogs, and building LLM system prompts.
agent_sdks/python/src/a2ui/core/parser/parser.py Contains parse_response for extracting and sanitizing A2UI JSON blocks from LLM output.
agent_sdks/python/src/a2ui/core/parser/payload_fixer.py Repairs malformed JSON syntax common in LLM-generated content.
agent_sdks/python/src/a2ui/core/schema/catalog.py Defines A2uiCatalog for component validation and schema enforcement.
agent_sdks/python/README.md Documentation for building, testing, and using the Python SDK.
samples/agent/adk/restaurant_finder Working example of a Python agent using A2UI for UI generation.

These files collectively provide a pure Python implementation with no external binary dependencies, tested using pytest.

Summary

  • A2UI provides first-class Python support through a comprehensive SDK located in agent_sdks/python/.
  • The SDK is pure Python with no binary dependencies and uses standard tooling like pytest for testing.
  • Core components include A2uiSchemaManager for schema handling, a2a.py for protocol bridging, and parse_response for LLM output processing.
  • Complete workflow support enables generating A2UI payloads, wrapping them in A2A parts, parsing mixed LLM responses, and validating against JSON schemas.
  • Working examples are available in the samples/ directory, demonstrating real-world agent integration.

Frequently Asked Questions

Does A2UI require any external binary dependencies for Python?

No. The A2UI Python SDK is implemented as pure Python code with no external binary dependencies. You can install and run it using standard Python tooling, and the test suite runs with pytest using uv run pytest as documented in agent_sdks/python/README.md.

Can I use A2UI Python SDK with any LLM framework?

Yes. The SDK is framework-agnostic regarding LLM providers. While the repository includes sample agents built with the Agent Development Kit (ADK) such as the Restaurant Finder demo in samples/agent/adk/restaurant_finder, the core SDK components like A2uiSchemaManager and parse_response can be integrated with any Python-based LLM client or framework.

How does A2UI handle malformed JSON from LLMs?

The SDK includes a robust recovery mechanism. When parsing LLM responses via parse_response in agent_sdks/python/src/a2ui/core/parser/parser.py, the system automatically invokes the payload fixer from payload_fixer.py to repair common LLM JSON errors such as missing commas, stray backticks, and unclosed brackets before attempting deserialization.

Where can I find working examples of A2UI Python agents?

The repository includes ready-to-run sample agents in the samples/ directory. Specifically, the Restaurant Finder demo located at samples/agent/adk/restaurant_finder demonstrates a complete agent workflow using the Python SDK to generate and manage A2UI payloads. Additionally, the agent_sdks/python/README.md file provides build instructions and testing guidance for the SDK itself.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →