a2ui について
A2UI Development Skill は、AI エージェントがクライアントへインタラクティブな UI をストリーミングする A2UI v0.8 準拠コードの作成を支援します。メッセージ構造、データバインディング、コンポーネント、ユーザーイベントを扱います。
主な機能
- 01A2UI v0.8 メッセージの生成
- 02ID 参照によるフラットなコンポーネント構成
- 03JSON Pointer パスによるデータバインディング
- 04標準のレイアウト・表示・入力コンポーネント
- 05ユーザー操作とエラーメッセージのパターン
活用シーン
- 01エージェント向けインタラクティブフォームの作成
- 02UI フィールドとアプリケーション状態の連携
- 03複数サーフェスや段階的レンダリングの構築
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ kobe4cn/ a2ui_skills --skill a2uiインストール後、Claude Code で/a2uiを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
README.mdexamples/modal.mdform.mdmulti-surface.mdstreaming.mdbooking-flow.mdlist.mdreference/api-integration.mdagent-prompting.mdcatalog-negotiation.mdcomponents.mdstreaming.mddata-binding.mdschema.mdsurfaces.md詳細
A2UI 開発スキル
このスキルは、AI エージェントがクライアントにストリーミングできる、リッチでインタラクティブなユーザーインターフェースを構築するための、A2UI(Agent to UI)プロトコル準拠のコード生成を支援します。
プロトコルバージョン
このスキルは、A2UI プロトコル v0.8(安定版リリース)を対象としています。
標準カタログ ID:https://github.com/google/A2UI/blob/main/specification/0.8/json/standard_catalog_definition.json
主な概念
1. メッセージの種類
A2UI は、JSONL ストリームで次の 4 種類のメッセージを使用します。
| メッセージ | 目的 |
|---|---|
surfaceUpdate | UI コンポーネントを定義または更新します |
dataModelUpdate | アプリケーションの状態を設定または更新します |
beginRendering | レンダリング開始をクライアントに通知します |
deleteSurface | UI サーフェスを削除します |
2. 隣接リストモデル
コンポーネントは、入れ子のツリーではなく、ID 参照を使ったフラットなリストとして定義します。
{"surfaceUpdate": {"surfaceId": "main", "components": [
{"id": "root", "component": {"Column": {"children": {"explicitList": ["header", "content"]}}}},
{"id": "header", "component": {"Text": {"text": {"literalString": "Welcome"}, "usageHint": "h1"}}},
{"id": "content", "component": {"Text": {"text": {"path": "/user/name"}}}}
]}}
3. データバインディング(BoundValue)
値をバインドするパターンは 3 種類あります。
// Literal only - static value
{"literalString": "Hello"}
// Path only - dynamic from data model
{"path": "/user/name"}
// Both - initialization shorthand (sets default AND binds)
{"path": "/form/email", "literalString": "[email protected]"}
4. スタイル設定
beginRendering で外観をカスタマイズします。
{"beginRendering": {
"surfaceId": "main",
"root": "root",
"styles": {
"font": "Roboto",
"primaryColor": "#1976D2"
}
}}
| プロパティ | 説明 |
|---|---|
font | 基本フォントファミリー |
primaryColor | テーマカラー(16 進数形式 #RRGGBB) |
標準カタログのコンポーネント
レイアウトコンポーネント
Row-distributionとalignmentを指定する水平コンテナーColumn-distributionとalignmentを指定する垂直コンテナーList-direction(垂直/水平)を指定するスクロール可能なリストCard- 単一のchildを持つマテリアルカードのラッパーTabs-tabItems配列を使ったタブナビゲーションModal-entryPointChildとcontentChildを持つダイアログDivider-axis(水平/垂直)を指定する区切り線
表示コンポーネント
Text-usageHint(h1-h5、caption、body)を指定するテキスト表示。シンプルな Markdown に対応しています。Image-url、fit、usageHintを指定する画像Icon- 標準セットのアイコン(コンポーネントリファレンスを参照)Video-urlを指定するビデオプレーヤーAudioPlayer-urlとdescriptionを指定するオーディオプレーヤー
入力コンポーネント
Button-childとactionを指定するクリック可能なボタンTextField-labelとtextFieldTypeを指定するテキスト入力フィールドCheckBox-labelとvalueを指定する切り替えコントロールDateTimeInput-enableDate/enableTimeを指定する日付/時刻ピッカーMultipleChoice-optionsとmaxAllowedSelectionsを指定する選択コントロールSlider-minValue/maxValueを指定する範囲入力コントロール
コンポーネントのウェイト
Row/Column 内のコンポーネントで weight を使うと、フレックスレイアウトを設定できます。
{"id": "sidebar", "weight": 1, "component": {"Column": {...}}},
{"id": "main", "weight": 3, "component": {"Column": {...}}}
A2UI メッセージの生成
基本的な流れ
surfaceUpdateでコンポーネントを定義しますdataModelUpdateでデータを設定しますbeginRenderingでレンダリングを開始します
完全な例:シンプルなフォーム
{"surfaceUpdate": {"surfaceId": "booking", "components": [
{"id": "root", "component": {"Column": {"children": {"explicitList": ["title", "name_field", "date_field", "submit_btn"]}}}},
{"id": "title", "component": {"Text": {"text": {"literalString": "Book a Table"}, "usageHint": "h2"}}},
{"id": "name_field", "component": {"TextField": {"label": {"literalString": "Your Name"}, "text": {"path": "/form/name"}}}},
{"id": "date_field", "component": {"DateTimeInput": {"value": {"path": "/form/date"}, "enableDate": true}}},
{"id": "submit_btn", "component": {"Button": {"child": "submit_text", "action": {"name": "submit_booking", "context": [{"key": "name", "value": {"path": "/form/name"}}, {"key": "date", "value": {"path": "/form/date"}}]}}}},
{"id": "submit_text", "component": {"Text": {"text": {"literalString": "Confirm Booking"}}}}
]}}
{"dataModelUpdate": {"surfaceId": "booking", "contents": [{"key": "form", "valueMap": [{"key": "name", "valueString": ""}, {"key": "date", "valueString": ""}]}]}}
{"beginRendering": {"surfaceId": "booking", "root": "root"}}
イベント処理
ユーザーアクション
ユーザーが操作(ボタンのクリックなど)を行うと、クライアントは userAction を送信します。
{
"userAction": {
"name": "submit_booking",
"surfaceId": "booking",
"sourceComponentId": "submit_btn",
"timestamp": "2025-01-01T10:00:00Z",
"context": {"name": "John Doe", "date": "2025-01-15"}
}
}
エラー報告
クライアントは error メッセージを使ってエラーを報告します。
{
"error": {
"type": "RENDER_ERROR",
"message": "Component 'user_card' references missing child",
"surfaceId": "main",
"componentId": "user_card",
"timestamp": "2025-01-01T10:30:05Z"
}
}
ベストプラクティス
- 一意の ID:各コンポーネントには、サーフェス内で一意の
idが必要です - フラットな構造:親子関係には ID 参照を使用します
- データの分離:UI 構造は
surfaceUpdateに、動的な値はdataModelUpdateに保持します - パスの規約:パスには JSON Pointer 形式(例:
/user/profile/name)を使用します - 段階的なレンダリング:必要なコンポーネントを定義した後に
beginRenderingを送信します - サーフェスのクリーンアップ:フローが完了したら
deleteSurfaceを使用します
リファレンスドキュメント
基本リファレンス
- コンポーネントリファレンス - 16 個すべてのコンポーネントとそのプロパティ
- データバインディングガイド - BoundValue のパターンとテンプレート
- API 統合 - イベント処理とバックエンド接続
- スキーマリファレンス - 検証用 JSON Schema
高度なトピック
- カタログネゴシエーション - 複数のカタログのサポート
- サーフェス管理 - 複数の UI 領域
- ストリーミングとパフォーマンス - 段階的なレンダリング
- エージェントのプロンプト作成 - LLM の統合