|
| 1 | +# A2UI Custom Components & Multiple Surfaces Guide |
| 2 | + |
| 3 | +This guide explains how the **Contact Client** and **Contact Multiple Surfaces Agent** work in tandem to deliver rich, custom user interfaces beyond the standard A2UI library. |
| 4 | + |
| 5 | +## Architecture Overview |
| 6 | + |
| 7 | +Unlike standard A2UI agents that rely solely on the core component library, this sample demonstrates a **Client-First Extension Model**: |
| 8 | + |
| 9 | +1. **Client Defines Components**: The web client (`contact` sample) defines custom components (`OrgChart`, `WebFrame`) and their schemas. |
| 10 | +2. **Inline Catalog Negotiation**: When the client connects to the agent, it sends these schemas in its connection handshake (Client Event) under `metadata.inlineCatalog`. |
| 11 | +3. **Agent Adaptation**: The agent (`contact_multiple_surfaces`) dynamically reads this catalog and injects the schema into the LLM's system prompt (via `[SYSTEM]` messages). |
| 12 | +4. **Rich Rendering**: The LLM can then instruct the client to render these custom components. |
| 13 | + |
| 14 | +## Key Features |
| 15 | + |
| 16 | +### 1. Multiple Surfaces |
| 17 | +The agent manages multiple distinct UI areas ("surfaces") simultaneously: |
| 18 | +- **`contact-card`**: The main profile view validation. |
| 19 | +- **`org-chart-view`**: A side-by-side organizational chart. |
| 20 | +- **`location-surface`**: A transient modal/overlay for map views. |
| 21 | + |
| 22 | +### 2. Custom Components |
| 23 | + |
| 24 | +#### `OrgChart` |
| 25 | +A custom LitElement component created in the client that renders a hierarchical view. |
| 26 | +- **Schema**: Defined in `samples/client/lit/contact/ui/custom-components`. |
| 27 | +- **Usage**: The agent sends a JSON structure matching the schema, and the client renders it natively. |
| 28 | + |
| 29 | +#### `WebFrame` (Iframe Component) |
| 30 | +A powerful component that allows embedding external web content or local static HTML files within the A2UI interface. |
| 31 | +- **Usage in Sample**: Used to render the "Office Floor Plan". |
| 32 | +- **Security**: Uses standard iframe sequencing and sandbox attributes. |
| 33 | +- **Interactivity**: Can communicate back to the parent A2UI application (e.g., clicking a desk on the map triggers an A2UI action `chart_node_click`). |
| 34 | + |
| 35 | +## How to Run in Tandem |
| 36 | + |
| 37 | +1. **Start the Agent**: |
| 38 | + ```bash |
| 39 | + cd samples/agent/adk/contact_multiple_surfaces |
| 40 | + uv run . |
| 41 | + ``` |
| 42 | + *Runs on port 10004.* |
| 43 | + |
| 44 | +2. **Start the Client**: |
| 45 | + ```bash |
| 46 | + cd samples/client/lit/contact |
| 47 | + npm run dev |
| 48 | + ``` |
| 49 | + *Configured to connect to localhost:10004.* |
| 50 | + |
| 51 | +## Flow Example: "View Location" |
| 52 | + |
| 53 | +1. **User Trigger**: User clicks "Location" on a profile card. |
| 54 | +2. **Action**: Client sends standard A2UI action `view_location`. |
| 55 | +3. **Agent Response**: Agent detects the intent and returns a message to render the `location-surface`. |
| 56 | +4. **Component Payload**: |
| 57 | + ```json |
| 58 | + { |
| 59 | + "WebFrame": { |
| 60 | + "url": "http://localhost:10004/static/floorplan.html?data=...", |
| 61 | + "interactionMode": "interactive" |
| 62 | + } |
| 63 | + } |
| 64 | + ``` |
| 65 | +5. **Rendering**: Client receives the message, creates the surface, and instantiates the `WebFrame` component, loading the static HTML map served by the agent. |
0 commit comments