Skip to content

Commit 53244c8

Browse files
committed
Update contact_multiple_surfaces sample
It updates the sample to use the A2uiSchemaManager from the a2ui-agent python SDK. Tested: - [x] The `contact` lit client successfully connected to the `contact_multiple_surfaces` agent and rendered the response correctly.
1 parent 57714b5 commit 53244c8

File tree

8 files changed

+126
-1008
lines changed

8 files changed

+126
-1008
lines changed

a2a_agents/python/a2ui_agent/src/a2ui/inference/schema/manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
)
3838
from .catalog import CustomCatalogConfig, A2uiCatalog
3939
from ...extension.a2ui_extension import INLINE_CATALOGS_KEY, SUPPORTED_CATALOG_IDS_KEY, get_a2ui_agent_extension
40+
from a2a.types import AgentExtension
4041

4142

4243
def _load_basic_component(version: str, spec_name: str) -> Dict:

samples/agent/adk/contact_multiple_surfaces/__main__.py

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
from a2a.server.apps import A2AStarletteApplication
2020
from a2a.server.request_handlers import DefaultRequestHandler
2121
from a2a.server.tasks import InMemoryTaskStore
22-
from a2a.types import AgentCapabilities, AgentCard, AgentSkill
23-
from a2ui.extension.a2ui_extension import get_a2ui_agent_extension
2422
from agent import ContactAgent
2523
from agent_executor import ContactAgentExecutor
2624
from dotenv import load_dotenv
@@ -49,39 +47,18 @@ def main(host, port):
4947
"GEMINI_API_KEY environment variable not set and GOOGLE_GENAI_USE_VERTEXAI is not TRUE."
5048
)
5149

52-
capabilities = AgentCapabilities(
53-
streaming=True,
54-
extensions=[get_a2ui_agent_extension()],
55-
)
56-
skill = AgentSkill(
57-
id="find_contact",
58-
name="Find Contact Tool",
59-
description="Helps find contact information for colleagues (e.g., email, location, team).",
60-
tags=["contact", "directory", "people", "finder"],
61-
examples=["Who is David Chen in marketing?", "Find Sarah Lee from engineering"],
62-
)
63-
6450
base_url = f"http://{host}:{port}"
6551

66-
agent_card = AgentCard(
67-
name="Contact Lookup Agent",
68-
description="This agent helps find contact info for people in your organization.",
69-
url=base_url, # <-- Use base_url here
70-
version="1.0.0",
71-
default_input_modes=ContactAgent.SUPPORTED_CONTENT_TYPES,
72-
default_output_modes=ContactAgent.SUPPORTED_CONTENT_TYPES,
73-
capabilities=capabilities,
74-
skills=[skill],
75-
)
52+
agent = ContactAgent(base_url=base_url, use_ui=True)
7653

77-
agent_executor = ContactAgentExecutor(base_url=base_url)
54+
agent_executor = ContactAgentExecutor(agent=agent)
7855

7956
request_handler = DefaultRequestHandler(
8057
agent_executor=agent_executor,
8158
task_store=InMemoryTaskStore(),
8259
)
8360
server = A2AStarletteApplication(
84-
agent_card=agent_card, http_handler=request_handler
61+
agent_card=agent.get_agent_card(), http_handler=request_handler
8562
)
8663
import uvicorn
8764

samples/agent/adk/contact_multiple_surfaces/a2ui_examples.py

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from pathlib import Path
1919

2020
import jsonschema
21-
from a2ui_schema import A2UI_SCHEMA
2221

2322
logger = logging.getLogger(__name__)
2423

@@ -34,71 +33,6 @@
3433

3534
FLOOR_PLAN_FILE = "floor_plan.json"
3635

37-
def load_examples(base_url: str = "http://localhost:10004") -> str:
38-
"""
39-
Loads, validates, and formats the UI examples from JSON files.
40-
41-
Args:
42-
base_url: The base URL to replace placeholder URLs with.
43-
(Currently examples have http://localhost:10004 hardcoded,
44-
but we can make this dynamic if needed).
45-
46-
Returns:
47-
A string containing all formatted examples for the prompt.
48-
"""
49-
50-
# Pre-parse validator
51-
try:
52-
single_msg_schema = json.loads(A2UI_SCHEMA)
53-
# Examples are typically lists of messages
54-
list_schema = {"type": "array", "items": single_msg_schema}
55-
except json.JSONDecodeError:
56-
logger.error("Failed to parse A2UI_SCHEMA for validation")
57-
list_schema = None
58-
59-
examples_dir = Path(os.path.dirname(__file__)) / "examples"
60-
formatted_output = []
61-
62-
for curr_name, filename in EXAMPLE_FILES.items():
63-
file_path = examples_dir / filename
64-
try:
65-
content = file_path.read_text(encoding="utf-8")
66-
67-
# basic replacement if we decide to template the URL in JSON files
68-
# content = content.replace("{{BASE_URL}}", base_url)
69-
70-
# Validation
71-
if list_schema:
72-
try:
73-
data = json.loads(content)
74-
jsonschema.validate(instance=data, schema=list_schema)
75-
except (json.JSONDecodeError, jsonschema.ValidationError) as e:
76-
logger.warning(f"Example {filename} validation failed: {e}")
77-
78-
formatted_output.append(f"---BEGIN {curr_name}---")
79-
# Handle examples that include user/model text
80-
if curr_name == "ORG_CHART_EXAMPLE":
81-
formatted_output.append("User: Show me the org chart for Casey Smith")
82-
formatted_output.append("Model: Here is the organizational chart.")
83-
formatted_output.append("---a2ui_JSON---")
84-
elif curr_name == "MULTI_SURFACE_EXAMPLE":
85-
formatted_output.append("User: Full profile for Casey Smith")
86-
formatted_output.append("Model: Here is the full profile including contact details and org chart.")
87-
formatted_output.append("---a2ui_JSON---")
88-
elif curr_name == "CHART_NODE_CLICK_EXAMPLE":
89-
formatted_output.append('User: ACTION: chart_node_click (context: clickedNodeName="John Smith") (from modal)')
90-
formatted_output.append("Model: Here is the profile for John Smith.")
91-
formatted_output.append("---a2ui_JSON---")
92-
93-
formatted_output.append(content.strip())
94-
formatted_output.append(f"---END {curr_name}---")
95-
formatted_output.append("") # Newline
96-
97-
except FileNotFoundError:
98-
logger.error(f"Example file not found: {file_path}")
99-
100-
return "\n".join(formatted_output)
101-
10236
def load_floor_plan_example() -> str:
10337
"""Loads the floor plan example specifically."""
10438
examples_dir = Path(os.path.dirname(__file__)) / "examples"

0 commit comments

Comments
 (0)