Skip to main content

A2UI (Agent-to-User Interface)

PraisonAI integrates with the official Google A2UI protocol via the optional a2ui-agent-sdk package — not a reimplemented copy in core.
Install the optional extra: pip install praisonaiagents[a2ui]

Overview

A2UI lets agents send declarative JSON describing UI components. Clients render using trusted component catalogs (React, Flutter, Lit, etc.) from the A2UI renderers. For most web apps, structured output or AG-UI is simpler. Use A2UI when you need a portable UI spec across multiple renderers. See also: Generative UI overview

Quick start

Facade API

from praisonaiagents.ui import A2UI

# Wrap payload for A2A transport
part = A2UI.create_part({"createSurface": {"surfaceId": "main", "catalogId": "..."}})

# Build LLM system prompt with schema + examples
prompt = A2UI.system_prompt(
    role_description="You are a helpful assistant that returns rich UI.",
    ui_description="Use cards and buttons from the basic catalog.",
)

Agent tool

from praisonaiagents import Agent
from praisonaiagents.tools.a2ui_tools import send_a2ui_messages

agent = Agent(name="assistant", tools=[send_a2ui_messages])

Low-level adapter

from praisonaiagents.ui.a2ui.adapter import (
    create_a2ui_part,
    parse_a2ui_response,
    get_schema_manager,
    generate_a2ui_system_prompt,
)

Generative UI flow (Google SDK)

  1. get_schema_manager() — load JSON schemas and catalog
  2. generate_a2ui_system_prompt() — inject schema into LLM instructions
  3. Agent returns A2UI JSON (via tool or structured output)
  4. parse_a2ui_response() — validate and split text vs UI parts
  5. create_a2ui_part() — wrap for A2A (application/json+a2ui)
  6. External renderer draws the UI
Reference: agent_sdks/python

A2A integration

Sync message/send responses include an A2UI DataPart when the agent’s last tool result uses application/json+a2ui. Streaming A2A over message/stream still returns text-only artifacts today.
from praisonaiagents.ui.a2ui import create_a2ui_part, is_a2ui_part

part = create_a2ui_part({"createSurface": {"surfaceId": "main", "catalogId": "..."}})
assert is_a2ui_part(part)

Tool argument shapes

send_a2ui_messages accepts common LLM formats (minimal unwrap in core; full normalisation belongs in your UI layer):
InputAccepted
List of message dictsYes
JSON string of a listYes
{"messages": [...]} dictYes
Single message dictYes (wrapped in a list)
For version fields and surface inference, see Integrate A2UI with Your Frontend and PraisonAIUI a2ui_utils.