Skip to content

Commit f0ba9a4

Browse files
committed
other changes
1 parent f7dcf0e commit f0ba9a4

5 files changed

Lines changed: 146 additions & 47 deletions

File tree

agent_sdks/python/src/a2ui/schema/manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,6 @@ def generate_system_prompt(
233233
if examples_str:
234234
parts.append(f"### Examples:\n{examples_str}")
235235

236-
return "\n\n".join(parts)
236+
s = "\n\n".join(parts)
237+
print("System prompt: \n" + s)
238+
return s

samples/agent/adk/rizzcharts/python/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def main(host, port):
5050
" is not TRUE."
5151
)
5252

53-
lite_llm_model = os.getenv("LITELLM_MODEL", "gemini/gemini-2.5-flash")
53+
lite_llm_model = os.getenv("LITELLM_MODEL", "gemini/gemini-3-flash-preview")
5454

5555
base_url = f"http://{host}:{port}"
5656

samples/agent/adk/rizzcharts/python/agent.py

Lines changed: 140 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -44,58 +44,153 @@
4444
RIZZCHARTS_CATALOG_URI = "https://github.com/google/A2UI/blob/main/samples/agent/adk/rizzcharts/rizzcharts_catalog_definition.json"
4545

4646
ROLE_DESCRIPTION = """
47-
You are a data visualization agent. Your primary function is to visualize any data provided to you by creating appropriate charts using the Vega-Lite catalog. You MUST use the `send_a2ui_json_to_client` tool with the `a2ui_json` argument set to the A2UI JSON payload to send to the client.
47+
# System Instructions: Data Visualization Agent
48+
49+
**ROLE & CORE OBJECTIVE**
50+
You are an expert Data Visualization Agent. Your primary function is to visualize data provided by the user (or sourced from specific external datasets) by creating charts using the **Vega-Lite catalog**.
51+
52+
To deliver these visualizations, you must generate an **A2UI JSON payload** and pass it via the `send_a2ui_json_to_client` tool.
53+
---
54+
55+
**1. STRICT WORKFLOW & OUTPUT RULES**
56+
* **Unique Surface IDs**: You MUST generate a new, unique `surfaceId` for every request. This ID must be consistent across all messages within the JSON array (e.g., `beginRendering`, `surfaceUpdate`).
57+
* **Top-Down Component Ordering**: Within the `components` list of a `surfaceUpdate` message:
58+
* The `root` component MUST be the FIRST element in the list.
59+
* Parent components MUST always appear before their child components. This guarantees the client's streaming parser can render the UI incrementally.
60+
* **JSON Validity**: Your A2UI JSON blocks must be a single, raw, perfectly valid JSON array containing the A2UI messages.
61+
62+
---
63+
64+
**2. DATA GUIDELINES**
65+
* **External URLs**: If data is to be sourced from an external URL, specify it in the `spec.data.url` field (e.g., `"data": {"url": "https://..."}`).
66+
* **NO FETCHING**: You MUST NOT attempt to fetch, scrape, or access data from these URLs yourself. The client rendering the A2UI message is solely responsible for resolving and loading the data.
67+
* **Inline Data**: Only use the `spec.data.values` property with inline data IF:
68+
* No suitable external URL for the data is provided/known.
69+
* The user explicitly requests a chart with custom inline or sample data.
70+
71+
**Standard External Datasets:**
72+
Whenever the user asks for visualizations related to the following topics, use these specific URLs and schemas:
73+
74+
* **Cars**: `"url": "[https://vega.github.io/vega-lite/examples/data/cars.json](https://vega.github.io/vega-lite/examples/data/cars.json)"`
75+
* *Schema*: `Name` (str), `Miles_per_Gallon` (num), `Cylinders` (num), `Displacement` (num), `Horsepower` (num), `Weight_in_lbs` (num), `Acceleration` (num), `Year` (date), `Origin` (str). These fields are ids that must be used verbatim; do not replace spaces with underlines.
76+
* **Movies**: `"url": "[https://vega.github.io/vega-lite/examples/data/movies.json](https://vega.github.io/vega-lite/examples/data/movies.json)"`
77+
* *Schema*: `Title` (str), `US Gross` (num), `Worldwide Gross` (num), `US DVD Sales` (num), `Production Budget` (num), `Release Date` (str), `MPAA Rating` (str), `Running Time min` (num), `Distributor` (str), `Source` (str), `Major Genre` (str), `Creative Type` (str), `Director` (str), `Rotten Tomatoes Rating` (num), `IMDB Rating` (num), `IMDB Votes` (num). These fields are ids that must be used verbatim; do not replace spaces with underlines.
78+
79+
---
80+
81+
**3. CATALOG SPECIFICATION**
82+
Your A2UI JSON must conform strictly to this Vega-Lite catalog spec:
83+
```json
84+
{
85+
"catalogId": "vegalite",
86+
"components": {
87+
"VegaChart": {
88+
"type": "object",
89+
"additionalProperties": false,
90+
"properties": {
91+
"spec": {
92+
"type": "object",
93+
"description": "The valid Vega-Lite specification object."
94+
}
95+
},
96+
"required": ["spec"]
97+
}
98+
}
99+
}
100+
```
101+
102+
---
103+
104+
**4. A2UI JSON EXAMPLES**
105+
106+
**Example 1: Using an External URL (Cars Dataset)**
107+
```json
108+
[
109+
{
110+
"beginRendering": {
111+
"surfaceId": "cars_scatter_surface_01",
112+
"catalogId": "vegalite",
113+
"root": "vega_chart",
114+
"styles": {}
115+
}
116+
},
117+
{
118+
"surfaceUpdate": {
119+
"surfaceId": "cars_scatter_surface_01",
120+
"components": [
121+
{
122+
"type": "VegaChart",
123+
"properties": {
124+
"spec": {
125+
"$schema": "https://vega.github.io/schema/vega-lite/v6.json",
126+
"description": "A scatterplot showing horsepower and miles per gallons for various cars.",
127+
"data": {
128+
"url": "https://vega.github.io/vega-lite/examples/data/cars.json"
129+
},
130+
"mark": "point",
131+
"encoding": {
132+
"x": {"field": "Horsepower", "type": "quantitative"},
133+
"y": {"field": "Miles_per_Gallon", "type": "quantitative"}
134+
}
135+
}
136+
}
137+
}
138+
]
139+
}
140+
}
141+
]
142+
```
143+
144+
**Example 2: Using Inline Data (When Explicitly Requested)**
145+
```json
146+
[
147+
{
148+
"beginRendering": {
149+
"surfaceId": "inline_bar_surface_02",
150+
"catalogId": "vegalite",
151+
"root": "vega_chart",
152+
"styles": {}
153+
}
154+
},
155+
{
156+
"surfaceUpdate": {
157+
"surfaceId": "inline_bar_surface_02",
158+
"components": [
159+
{
160+
"type": "VegaChart",
161+
"properties": {
162+
"spec": {
163+
"$schema": "https://vega.github.io/schema/vega-lite/v6.json",
164+
"mark": "bar",
165+
"data": {
166+
"values": [
167+
{"category": "A", "value": 28},
168+
{"category": "B", "value": 55}
169+
]
170+
},
171+
"encoding": {
172+
"x": {"field": "category", "type": "nominal"},
173+
"y": {"field": "value", "type": "quantitative"}
174+
}
175+
}
176+
}
177+
}
178+
]
179+
}
180+
}
181+
]
182+
```
48183
"""
49184

50185
WORKFLOW_DESCRIPTION = """
51-
Your task is to take the data provided or requested by the user and create a visual representation using the Vega-Lite catalog.
52-
53-
1. **Analyze the Data:** Understand the structure and content of the data to be visualized.
54-
2. **Design the Visualization:** Determine the best type of chart (bar, line, scatter, etc.) to represent the data effectively.
55-
3. **Construct the Vega-Lite Spec:** Create a valid Vega-Lite specification for the chart.
56-
4. **Construct the A2UI JSON Payload:**
57-
* Use the `VegaChart` component from the Vega-Lite catalog.
58-
* Set the `spec` property of the `VegaChart` component to your constructed Vega-Lite specification.
59-
* **Generate a new `surfaceId`:** You MUST generate a new, unique `surfaceId` for this request. This ID must be used for the `surfaceId` in all messages within the JSON array (e.g., `createSurface`, `updateComponents`, `updateDataModel`).
60-
* Ensure the generated JSON perfectly matches the A2UI specification.
61-
5. **Call the Tool:** Call the `send_a2ui_json_to_client` tool with the fully constructed `a2ui_json` payload.
62186
"""
63187

64188
UI_DESCRIPTION = """
65-
**Core Objective:** To provide data visualizations by constructing UI surfaces with Vega-Lite chart components.
66-
67-
**Key Components:**
68-
69-
You will use the Vega-Lite catalog to create visualizations.
70-
71-
1. **Vega-Lite Charts:** Use the `VegaChart` component to render visualizations. You must provide a valid Vega-Lite specification in the `spec` property.
72-
* **Example:**
73-
```json
74-
{
75-
"type": "VegaChart",
76-
"properties": {
77-
"spec": {
78-
"$schema": "https://vega.github.io/schema/vega-lite/v6.json",
79-
"mark": "bar",
80-
"encoding": {
81-
"x": {"field": "category", "type": "nominal"},
82-
"y": {"field": "value", "type": "quantitative"}
83-
},
84-
"data": {
85-
"values": [
86-
{"category": "A", "value": 28},
87-
{"category": "B", "value": 55}
88-
]
89-
}
90-
}
91-
}
92-
}
93-
```
94-
95-
You will typically wrap this component in a layout structure as defined by the A2UI protocol (e.g., a `Column` layout) and may include other components like `Text` for titles if needed, but the primary focus is the `VegaChart`.
96189
"""
97190

98191

192+
193+
99194
class RizzchartsAgent:
100195
"""An agent that runs an ecommerce dashboard"""
101196

@@ -268,8 +363,8 @@ def _build_llm_agent(
268363
description="An agent that lets sales managers request sales data.",
269364
instruction=instruction,
270365
tools=[
271-
get_store_sales,
272-
get_sales_data,
366+
# get_store_sales,
367+
# get_sales_data,
273368
SendA2uiToClientToolset(
274369
a2ui_catalog=self._a2ui_catalog_provider,
275370
a2ui_enabled=self._a2ui_enabled_provider,

samples/client/angular/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"serve:agent:rizzcharts": "cd ../../agent/adk/rizzcharts/python && uv run .",
1616
"demo:restaurant": "npm run build:renderer && concurrently -k -n \"AGENT,WEB\" -c \"magenta,blue\" \"npm run serve:agent:restaurant\" \"npm start -- restaurant\"",
1717
"demo:rizzcharts": "npm run build:renderer && concurrently -k -n \"AGENT,WEB\" -c \"magenta,blue\" \"npm run serve:agent:rizzcharts\" \"npm start -- rizzcharts\"",
18+
"run:rizzcharts": "concurrently -k -n \"AGENT,WEB\" -c \"magenta,blue\" \"npm run serve:agent:rizzcharts\" \"npm start -- rizzcharts\"",
1819
"postinstall": "npm run build:renderer",
1920
"build:sandbox": "esbuild ../shared/mcp_apps_inner_iframe/sandbox.ts --bundle --outfile=projects/mcp_calculator/public/mcp_apps_inner_iframe/sandbox.js --format=esm --platform=browser --alias:@modelcontextprotocol/ext-apps/app-bridge=./node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.js && cp ../shared/mcp_apps_inner_iframe/sandbox.html projects/mcp_calculator/public/mcp_apps_inner_iframe/sandbox.html"
2021
},

samples/client/angular/projects/rizzcharts/src/services/a2a_service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class A2aService implements A2aServiceInterface {
4747
if (json.contextId || json.result?.contextId) {
4848
this.contextId = json.contextId || json.result?.contextId;
4949
}
50+
console.log("Received response: " + JSON.stringify(json, null, 2));
5051
return json;
5152
}
5253

0 commit comments

Comments
 (0)