Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions samples/agent/adk/contact_lookup/a2ui_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
{ "id": "call_text_column", "component": { "Column": { "children": { "explicitList": ["call_primary_text", "call_secondary_text"]} , "distribution": "start", "alignment": "start"} } } ,
{ "id": "info_row_4", "component": { "Row": { "children": { "explicitList": ["call_icon", "call_text_column"]} , "distribution": "start", "alignment": "start"} } } ,
{ "id": "info_rows_column", "weight": 1, "component": { "Column": { "children": { "explicitList": ["info_row_1", "info_row_2", "info_row_3", "info_row_4"]} , "alignment": "stretch"} } } ,
{ "id": "button_1_text", "component": { "Text": { "text": { "literalString": "Follow"} } } } , { "id": "button_1", "component": { "Button": { "child": "button_1_text", "primary": true, "action": { "name": "follow_profile"} } } } ,
{ "id": "button_1_text", "component": { "Text": { "text": { "literalString": "Follow"} } } } , { "id": "button_1", "component": { "Button": { "child": "button_1_text", "primary": true, "action": { "name": "follow_contact"} } } } ,
{ "id": "button_2_text", "component": { "Text": { "text": { "literalString": "Message"} } } } , { "id": "button_2", "component": { "Button": { "child": "button_2_text", "primary": false, "action": { "name": "send_message"} } } } ,
{ "id": "action_buttons_row", "component": { "Row": { "children": { "explicitList": ["button_1", "button_2"]} , "distribution": "center", "alignment": "center"} } } ,
{ "id": "link_text", "component": { "Text": { "text": { "literalString": "[View Full Profile](/profile)"} } } } ,
Expand Down Expand Up @@ -144,4 +144,19 @@
} }
]
---END ACTION_CONFIRMATION_EXAMPLE---
"""

---BEGIN FOLLOW_SUCCESS_EXAMPLE---
[
{ "beginRendering": { "surfaceId": "contact-card", "root": "success_card"} },
{ "surfaceUpdate": {
"surfaceId": "contact-card",
"components": [
{ "id": "success_icon", "component": { "Icon": { "name": { "literalString": "check_circle"}, "size": 48.0, "color": "#4CAF50"} } } ,
{ "id": "success_text", "component": { "Text": { "text": { "literalString": "Successfully Followed"}, "usageHint": "h2"} } } ,
{ "id": "success_column", "component": { "Column": { "children": { "explicitList": ["success_icon", "success_text"]} , "alignment": "center"} } } ,
{ "id": "success_card", "component": { "Card": { "child": "success_column"} } }
]
} }
]
---END FOLLOW_SUCCESS_EXAMPLE---

8 changes: 6 additions & 2 deletions samples/agent/adk/contact_lookup/agent_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ async def execute(

if ui_event_part:
logger.info(f"Received a2ui ClientEvent: {ui_event_part}")
action = ui_event_part.get("actionName")
# Fix: Check both 'actionName' and 'name'
action = ui_event_part.get("name")
ctx = ui_event_part.get("context", {})

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

elif action == "follow_contact":
query = "ACTION: follow_contact"

elif action == "view_full_profile":
contact_name = ctx.get("contactName", "Unknown")
query = f"USER_WANTS_FULL_PROFILE: {contact_name}"
Expand Down Expand Up @@ -173,7 +177,7 @@ async def execute(
"Received a single JSON object. Creating a DataPart."
)
final_parts.append(create_a2ui_part(json_data))

except json.JSONDecodeError as e:
logger.error(f"Failed to parse UI JSON: {e}")
final_parts.append(Part(root=TextPart(text=json_string)))
Expand Down
7 changes: 4 additions & 3 deletions samples/agent/adk/contact_lookup/prompt_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ def get_ui_prompt(base_url: str, examples: str) -> str:
a. You MUST call the `get_contact_info` tool with the specific name.
b. This will return a single contact. You MUST use the `CONTACT_CARD_EXAMPLE` template.

- **For handling actions (e.g., "USER_WANTS_TO_EMAIL: ..."):**
a. You MUST use the `ACTION_CONFIRMATION_EXAMPLE` template.
b. Populate the `dataModelUpdate.contents` with a confirmation title and message (e.g., title: "Email Drafted", message: "Drafting an email to Alex Jordan...").
- **For handling actions (e.g., "follow_contact"):**
a. You MUST use the `FOLLOW_SUCCESS_EXAMPLE` template.
b. This will render a new card with a "Successfully Followed" message.
c. Respond with a text confirmation like "You are now following this contact." along with the JSON.

{formatted_examples}

Expand Down
Loading