Skip to content

refactor: Ap2 demo cleanup#52

Merged
jorellis merged 4 commits intogoogle-agentic-commerce:mainfrom
jorellis:ap2-demo-cleanup
Nov 12, 2025
Merged

refactor: Ap2 demo cleanup#52
jorellis merged 4 commits intogoogle-agentic-commerce:mainfrom
jorellis:ap2-demo-cleanup

Conversation

@jorellis
Copy link
Collaborator

This standardizes our agent-to-agent (A2A) communication in the ap2-demo by refactoring the client agent to use the official RemoteA2aAgent from the Google ADK.

Core Changes & Impact
A2A Protocol Compliance: Ensures the AP2 demo strictly adheres to the latest A2A specification by utilizing the official ADK implementation for remote agent discovery and invocation.

Reduced Boilerplate (Maintainability): Eliminates two custom, high-maintenance files:

_remote_agent_connection.py

_task_store.py

Idiomatic ADK Setup: client_agent/agent.py is updated to instantiate RemoteA2aAgent instances and pass them as tools to the orchestrator agent, following the recommended pattern for multi-agent composition.

Dependency Update: Updates uv.lock and pyproject.toml to reflect necessary ADK dependencies.

This is a clean, structural improvement that future-proofs the demo.

@jorellis jorellis requested a review from a team as a code owner November 10, 2025 23:55
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jorellis, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the ap2-demo by integrating the official RemoteA2aAgent from the Google ADK. This change streamlines agent-to-agent communication, making it more robust and compliant with the A2A protocol. By adopting the ADK's recommended patterns, the demo's architecture is simplified, and custom, high-maintenance components are eliminated, leading to a cleaner and more future-proof implementation.

Highlights

  • Standardized A2A Communication: The ap2-demo now uses the official RemoteA2aAgent from the Google ADK, ensuring compliance with the latest Agent-to-Agent (A2A) specification.
  • Reduced Boilerplate: Two custom files, _remote_agent_connection.py and _task_store.py, have been removed, simplifying the codebase and improving maintainability.
  • Idiomatic ADK Setup: The client_agent/agent.py file has been updated to instantiate RemoteA2aAgent instances and pass them as tools to the orchestrator agent, following recommended multi-agent composition patterns.
  • Dependency Management: uv.lock and pyproject.toml have been updated to reflect the necessary ADK dependencies, including moving pytest and pytest-asyncio to development dependencies.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a great refactoring that significantly improves the ap2-demo. By replacing the custom A2A communication logic with the official RemoteA2aAgent from the ADK, the code is now more maintainable, less boilerplate, and follows the recommended idiomatic patterns for multi-agent systems. The removal of _remote_agent_connection.py and _task_store.py is a major cleanup. The updated agent instructions are also much clearer and more direct for the LLM. I have a couple of suggestions to further improve code clarity and robustness.

Comment on lines 28 to 40
# Create RemoteA2aAgent instances for each remote agent.
remote_agents = []
for address in REMOTE_AGENT_ADDRESSES:
# The server exposes the agent card at a path relative to the agent's RPC endpoint.
agent_card_url = f"{address}/.well-known/agent-card.json"
agent_name = address.split("/")[-1]
remote_agents.append(
RemoteA2aAgent(
name=agent_name,
agent_card=agent_card_url,
httpx_client=async_client,
)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This loop to initialize the remote agents can be made more concise and robust. Using a list comprehension is more idiomatic Python for creating a list from an iterable. Additionally, using urllib.parse.urlparse to extract the agent name from the address is more reliable than split('/'), as it correctly handles variations in URL structure (e.g., with or without a trailing slash).

# Create RemoteA2aAgent instances for each remote agent.
remote_agents = [
    RemoteA2aAgent(
        name=urlparse(address).path.split("/")[-1],
        agent_card=f"{address}/.well-known/agent-card.json",
        httpx_client=async_client,
    )
    for address in REMOTE_AGENT_ADDRESSES
]

Comment on lines +152 to +157
# The RemoteA2aAgent returns a DataPart, which serializes to `{'data': ...}`.
# We need to unwrap the actual mandate from inside the 'data' key.
unwrapped_mandate = cart_mandate.get("data", cart_mandate)
cart_data = unwrapped_mandate.get(
"ap2.mandates.CartMandate", unwrapped_mandate
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The logic for unwrapping the nested cart_data is a bit dense. While it correctly handles the expected structure, using a more descriptive intermediate variable name would improve readability and make the data flow easier to follow, especially when debugging.

Suggested change
# The RemoteA2aAgent returns a DataPart, which serializes to `{'data': ...}`.
# We need to unwrap the actual mandate from inside the 'data' key.
unwrapped_mandate = cart_mandate.get("data", cart_mandate)
cart_data = unwrapped_mandate.get(
"ap2.mandates.CartMandate", unwrapped_mandate
)
# The RemoteA2aAgent returns a DataPart, which serializes to a dict
# like `{'data': {'ap2.mandates.CartMandate': {...}}}`.
# We need to unwrap the actual mandate from these nested keys.
data_part_content = cart_mandate.get("data", cart_mandate)
cart_data = data_part_content.get(
"ap2.mandates.CartMandate", data_part_content
)

kunalsekhriG
kunalsekhriG previously approved these changes Nov 11, 2025
…f the remote agents, async_client and client_agent_imp
@jorellis jorellis merged commit 6db2a01 into google-agentic-commerce:main Nov 12, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants