Skip to content

Commit 3eb5cf5

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` angular client successfully connected to the `contact_multiple_surfaces` agent and rendered the response correctly.
1 parent 53d3da0 commit 3eb5cf5

4 files changed

Lines changed: 63 additions & 908 deletions

File tree

samples/agent/adk/contact_multiple_surfaces/a2ui_examples.py

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

2020
import jsonschema
21-
from a2ui_schema import A2UI_SCHEMA
21+
from a2ui.core.validator import A2uiValidator
2222

2323
logger = logging.getLogger(__name__)
2424

@@ -34,11 +34,12 @@
3434

3535
FLOOR_PLAN_FILE = "floor_plan.json"
3636

37-
def load_examples(base_url: str = "http://localhost:10004") -> str:
37+
def load_examples(validator: A2uiValidator, base_url: str = "http://localhost:10004") -> str:
3838
"""
3939
Loads, validates, and formats the UI examples from JSON files.
4040
4141
Args:
42+
validator: The validator to use for validation.
4243
base_url: The base URL to replace placeholder URLs with.
4344
(Currently examples have http://localhost:10004 hardcoded,
4445
but we can make this dynamic if needed).
@@ -47,15 +48,6 @@ def load_examples(base_url: str = "http://localhost:10004") -> str:
4748
A string containing all formatted examples for the prompt.
4849
"""
4950

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-
5951
examples_dir = Path(os.path.dirname(__file__)) / "examples"
6052
formatted_output = []
6153

@@ -68,12 +60,11 @@ def load_examples(base_url: str = "http://localhost:10004") -> str:
6860
# content = content.replace("{{BASE_URL}}", base_url)
6961

7062
# 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}")
63+
try:
64+
data = json.loads(content)
65+
validator.validate(instance=data)
66+
except (json.JSONDecodeError, jsonschema.ValidationError) as e:
67+
logger.warning(f"Example {filename} validation failed: {e}")
7768

7869
formatted_output.append(f"---BEGIN {curr_name}---")
7970
# Handle examples that include user/model text

0 commit comments

Comments
 (0)