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
12 changes: 8 additions & 4 deletions samples/agent/adk/contact_lookup/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@
from tools import get_contact_info
from a2ui.core.schema.constants import VERSION_0_8, VERSION_0_9, A2UI_OPEN_TAG, A2UI_CLOSE_TAG
from a2ui.core.schema.manager import A2uiSchemaManager
from a2ui.core.parser.parser import parse_response
from a2ui.core.parser.parser import parse_response, ResponsePart
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The import of ResponsePart is unused in this file and can be removed.

Suggested change
from a2ui.core.parser.parser import parse_response, ResponsePart
from a2ui.core.parser.parser import parse_response

from a2ui.basic_catalog.provider import BasicCatalog
from a2ui.a2a import (
get_a2ui_agent_extension,
parse_response_to_parts,
stream_response_to_parts,
)

Expand Down Expand Up @@ -357,13 +358,16 @@ async def token_stream():

if is_valid:
logger.info(
"--- ContactAgent.stream: Response is valid. Task complete (Attempt"
f" {attempt}). ---"
"--- ContactAgent.stream: Response is valid. Sending final response"
f" (Attempt {attempt}). ---"
)
final_parts = parse_response_to_parts(
final_response_content, fallback_text="OK."
)
Comment on lines +364 to 366
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using fallback_text="OK." will cause the agent to return "OK." instead of the actual response when running in text-only mode (i.e., when ui_version is None). In text-only mode, parse_response will fail to find A2UI tags and raise a ValueError, causing parse_response_to_parts to return the fallback text.

You should use final_response_content as the fallback text to ensure the full response is preserved in non-UI scenarios.

Suggested change
final_parts = parse_response_to_parts(
final_response_content, fallback_text="OK."
)
final_parts = parse_response_to_parts(
final_response_content, fallback_text=final_response_content
)


yield {
"is_task_complete": True,
"parts": [],
"parts": final_parts,
}
return # We're done, exit the generator

Expand Down
10 changes: 7 additions & 3 deletions samples/agent/adk/restaurant_finder/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@
from tools import get_restaurants
from a2ui.core.schema.constants import VERSION_0_8, VERSION_0_9, A2UI_OPEN_TAG, A2UI_CLOSE_TAG
from a2ui.core.schema.manager import A2uiSchemaManager
from a2ui.core.parser.parser import parse_response
from a2ui.core.parser.parser import parse_response, ResponsePart
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The import of ResponsePart is unused in this file and can be removed.

Suggested change
from a2ui.core.parser.parser import parse_response, ResponsePart
from a2ui.core.parser.parser import parse_response

from a2ui.basic_catalog.provider import BasicCatalog
from a2ui.core.schema.common_modifiers import remove_strict_validation
from a2ui.a2a import (
get_a2ui_agent_extension,
parse_response_to_parts,
stream_response_to_parts,
)

Expand Down Expand Up @@ -326,13 +327,16 @@ async def token_stream():

if is_valid:
logger.info(
"--- RestaurantAgent.stream: Response is valid. Task complete"
"--- RestaurantAgent.stream: Response is valid. Sending final response"
f" (Attempt {attempt}). ---"
)
final_parts = parse_response_to_parts(
final_response_content, fallback_text="OK."
)
Comment on lines +333 to +335
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using fallback_text="OK." will cause the agent to return "OK." instead of the actual response when running in text-only mode (i.e., when ui_version is None). In text-only mode, parse_response will fail to find A2UI tags and raise a ValueError, causing parse_response_to_parts to return the fallback text.

You should use final_response_content as the fallback text to ensure the full response is preserved in non-UI scenarios.

Suggested change
final_parts = parse_response_to_parts(
final_response_content, fallback_text="OK."
)
final_parts = parse_response_to_parts(
final_response_content, fallback_text=final_response_content
)


yield {
"is_task_complete": True,
"parts": [],
"parts": final_parts,
}
return # We're done, exit the generator

Expand Down
Loading