Skip to content

Commit 6541a67

Browse files
authored
Re-enable the change: Upgrade A2UI examples to v0.9 schema (google#759)
* Revert "Revert "feat: Upgrade A2UI examples to v0.9 schema (google#751)" (google#758)" This reverts commit ebad279. * Update component_gallery sample * Update contact_multiple_surfaces sample * Update the mcp_calculator sample
1 parent 69c76b0 commit 6541a67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+7121
-185
lines changed

.github/workflows/python_samples_build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ jobs:
5151
working-directory: samples/agent/adk
5252
run: uv run pyink --check .
5353

54+
- name: Validate Sample Examples
55+
run: |
56+
PYTHONPATH=agent_sdks/python/src uv run --project agent_sdks/python pytest -vv samples/agent/adk/tests/test_examples_validation.py
57+
5458
- name: Build contact_lookup
5559
working-directory: samples/agent/adk/contact_lookup
5660
run: uv build .

samples/agent/adk/component_gallery/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from starlette.middleware.cors import CORSMiddleware
2929
from starlette.staticfiles import StaticFiles
3030
from dotenv import load_dotenv
31-
from a2ui.core.schema.constants import VERSION_0_8
31+
from a2ui.core.schema.constants import VERSION_0_8, VERSION_0_9
3232

3333

3434
from agent_executor import ComponentGalleryExecutor
@@ -51,7 +51,7 @@
5151
def main(host, port):
5252
try:
5353
extensions = []
54-
for v in [VERSION_0_8]:
54+
for v in [VERSION_0_8, VERSION_0_9]:
5555
extensions.append(get_a2ui_agent_extension(v))
5656
capabilities = AgentCapabilities(
5757
streaming=True,

samples/agent/adk/component_gallery/agent.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import logging
1818
from collections.abc import AsyncIterable
19-
from typing import Any
19+
from typing import Any, Optional
2020
import json
2121

2222
from a2a.types import DataPart, Part, TextPart
@@ -37,14 +37,18 @@ class ComponentGalleryAgent:
3737
def __init__(self, base_url: str):
3838
self.base_url = base_url
3939

40-
async def stream(self, query: str, session_id: str) -> AsyncIterable[dict[str, Any]]:
40+
async def stream(
41+
self, query: str, session_id: str, active_ui_version: Optional[str]
42+
) -> AsyncIterable[dict[str, Any]]:
4143
"""Streams the gallery or responses to actions."""
4244

43-
logger.info(f"Stream called with query: {query}")
45+
logger.info(
46+
f"Stream called with query: {query} and active_ui_version: {active_ui_version}"
47+
)
4448

4549
# Initial Load or Reset
4650
if "WHO_ARE_YOU" in query or "START" in query: # Simple trigger for initial load
47-
gallery_json = get_gallery_json()
51+
gallery_json = get_gallery_json(active_ui_version)
4852
yield {
4953
"is_task_complete": True,
5054
"parts": parse_response_to_parts(

samples/agent/adk/component_gallery/agent_executor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ async def execute(self, context: RequestContext, event_queue: EventQueue) -> Non
3737
query = "START" # Default start
3838
ui_event_part = None
3939

40-
try_activate_a2ui_extension(context, self._agent_card)
40+
active_ui_version = try_activate_a2ui_extension(context, self._agent_card)
41+
logger.info(f"Active UI version: {active_ui_version}")
4142

4243
if context.message and context.message.parts:
4344
for part in context.message.parts:
@@ -63,7 +64,7 @@ async def execute(self, context: RequestContext, event_queue: EventQueue) -> Non
6364

6465
updater = TaskUpdater(event_queue, task.id, task.context_id)
6566

66-
async for item in self.agent.stream(query, task.context_id):
67+
async for item in self.agent.stream(query, task.context_id, active_ui_version):
6768
final_parts = item["parts"]
6869

6970
await updater.update_status(

0 commit comments

Comments
 (0)