Skip to content

Commit c3a13e8

Browse files
authored
Enable npm run demo:all that adds deps, builds and runs the restaurant and contact agent along with the shell app (#278)
1 parent 5945f86 commit c3a13e8

File tree

5 files changed

+389
-9
lines changed

5 files changed

+389
-9
lines changed

samples/agent/adk/contact_lookup/a2ui_examples.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
{ "id": "call_text_column", "component": { "Column": { "children": { "explicitList": ["call_primary_text", "call_secondary_text"]} , "distribution": "start", "alignment": "start"} } } ,
9494
{ "id": "info_row_4", "component": { "Row": { "children": { "explicitList": ["call_icon", "call_text_column"]} , "distribution": "start", "alignment": "start"} } } ,
9595
{ "id": "info_rows_column", "weight": 1, "component": { "Column": { "children": { "explicitList": ["info_row_1", "info_row_2", "info_row_3", "info_row_4"]} , "alignment": "stretch"} } } ,
96-
{ "id": "button_1_text", "component": { "Text": { "text": { "literalString": "Follow"} } } } , { "id": "button_1", "component": { "Button": { "child": "button_1_text", "primary": true, "action": { "name": "follow_profile"} } } } ,
96+
{ "id": "button_1_text", "component": { "Text": { "text": { "literalString": "Follow"} } } } , { "id": "button_1", "component": { "Button": { "child": "button_1_text", "primary": true, "action": { "name": "follow_contact"} } } } ,
9797
{ "id": "button_2_text", "component": { "Text": { "text": { "literalString": "Message"} } } } , { "id": "button_2", "component": { "Button": { "child": "button_2_text", "primary": false, "action": { "name": "send_message"} } } } ,
9898
{ "id": "action_buttons_row", "component": { "Row": { "children": { "explicitList": ["button_1", "button_2"]} , "distribution": "center", "alignment": "center"} } } ,
9999
{ "id": "link_text", "component": { "Text": { "text": { "literalString": "[View Full Profile](/profile)"} } } } ,
@@ -144,4 +144,19 @@
144144
} }
145145
]
146146
---END ACTION_CONFIRMATION_EXAMPLE---
147-
"""
147+
148+
---BEGIN FOLLOW_SUCCESS_EXAMPLE---
149+
[
150+
{ "beginRendering": { "surfaceId": "contact-card", "root": "success_card"} },
151+
{ "surfaceUpdate": {
152+
"surfaceId": "contact-card",
153+
"components": [
154+
{ "id": "success_icon", "component": { "Icon": { "name": { "literalString": "check_circle"}, "size": 48.0, "color": "#4CAF50"} } } ,
155+
{ "id": "success_text", "component": { "Text": { "text": { "literalString": "Successfully Followed"}, "usageHint": "h2"} } } ,
156+
{ "id": "success_column", "component": { "Column": { "children": { "explicitList": ["success_icon", "success_text"]} , "alignment": "center"} } } ,
157+
{ "id": "success_card", "component": { "Card": { "child": "success_column"} } }
158+
]
159+
} }
160+
]
161+
---END FOLLOW_SUCCESS_EXAMPLE---
162+

samples/agent/adk/contact_lookup/agent_executor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ async def execute(
9191

9292
if ui_event_part:
9393
logger.info(f"Received a2ui ClientEvent: {ui_event_part}")
94-
action = ui_event_part.get("actionName")
94+
# Fix: Check both 'actionName' and 'name'
95+
action = ui_event_part.get("name")
9596
ctx = ui_event_part.get("context", {})
9697

9798
if action == "view_profile":
@@ -108,6 +109,9 @@ async def execute(
108109
contact_name = ctx.get("contactName", "Unknown")
109110
query = f"USER_WANTS_TO_MESSAGE: {contact_name}"
110111

112+
elif action == "follow_contact":
113+
query = "ACTION: follow_contact"
114+
111115
elif action == "view_full_profile":
112116
contact_name = ctx.get("contactName", "Unknown")
113117
query = f"USER_WANTS_FULL_PROFILE: {contact_name}"
@@ -173,7 +177,7 @@ async def execute(
173177
"Received a single JSON object. Creating a DataPart."
174178
)
175179
final_parts.append(create_a2ui_part(json_data))
176-
180+
177181
except json.JSONDecodeError as e:
178182
logger.error(f"Failed to parse UI JSON: {e}")
179183
final_parts.append(Part(root=TextPart(text=json_string)))

samples/agent/adk/contact_lookup/prompt_builder.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ def get_ui_prompt(base_url: str, examples: str) -> str:
7676
a. You MUST call the `get_contact_info` tool with the specific name.
7777
b. This will return a single contact. You MUST use the `CONTACT_CARD_EXAMPLE` template.
7878
79-
- **For handling actions (e.g., "USER_WANTS_TO_EMAIL: ..."):**
80-
a. You MUST use the `ACTION_CONFIRMATION_EXAMPLE` template.
81-
b. Populate the `dataModelUpdate.contents` with a confirmation title and message (e.g., title: "Email Drafted", message: "Drafting an email to Alex Jordan...").
79+
- **For handling actions (e.g., "follow_contact"):**
80+
a. You MUST use the `FOLLOW_SUCCESS_EXAMPLE` template.
81+
b. This will render a new card with a "Successfully Followed" message.
82+
c. Respond with a text confirmation like "You are now following this contact." along with the JSON.
8283
8384
{formatted_examples}
8485

0 commit comments

Comments
 (0)