这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@jorellis
Copy link
Collaborator

This PR introduces the following changes to the adk_merchant_agent.py:

  • Feature: The process_payment function now returns a structured PaymentReceipt artifact upon successful transaction settlement, providing a comprehensive record of the payment.

@jorellis jorellis requested a review from a team as a code owner November 18, 2025 01:39
@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 primarily focuses on enhancing payment processing by introducing a PaymentReceipt artifact for successful transactions and significantly refactoring the agent-to-agent communication architecture. The client agent now interacts with remote agents through a more structured AgentTool mechanism, streamlining the orchestration logic. Additionally, dependency management has been refined, and the server's agent card creation process has been updated to be asynchronous and more robust.

Highlights

  • PaymentReceipt Artifact: The process_payment function in adk_merchant_agent.py now returns a structured PaymentReceipt artifact upon successful transaction settlement, providing a comprehensive record of the payment.
  • Refactored Agent Interaction: The client agent's interaction with remote agents has been significantly refactored, moving from direct send_message calls to utilizing RemoteA2aAgent instances wrapped as AgentTools. This simplifies the orchestrator's logic and improves modularity.
  • Updated Client Agent SOP: The root_instruction for the client agent has been revised to reflect the new agent interaction pattern, including explicit steps for handling signed mandates and cart mandates via dedicated tools.
  • Dependency Management Refinement: Development dependencies like pytest and pytest-asyncio have been correctly moved from direct dependencies to dev dependencies in pyproject.toml, and related packages like iniconfig and pluggy were removed from uv.lock. mypy has also been added for static type checking.
  • Asynchronous Agent Card Creation: The server-side agent card creation (create_agent_card) is now an asynchronous operation, leveraging AgentCardBuilder for more robust and configurable agent card generation.
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 introduces a significant and valuable refactoring of the agent interaction logic, moving towards a more robust and maintainable design by leveraging RemoteA2aAgent, AgentTool, and other ADK utilities. The introduction of the PaymentReceipt artifact is also a great feature, providing structured confirmation of transactions.

My review includes a few key points:

  • Fixing a type error in payment nonce generation that was hidden by a type: ignore.
  • Improving error handling during agent initialization to ensure it fails fast if the wallet is unavailable.
  • Suggestions to replace hardcoded values (magic numbers and strings) with constants for better readability and maintainability.

Comment on lines +219 to +221
logger.error(f"Could not connect to mock wallet to get address: {e}")
# Handle the error appropriately, maybe by preventing initialization
return
Copy link
Contributor

Choose a reason for hiding this comment

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

high

If fetching the wallet address fails, the function logs an error and then returns, allowing the agent initialization to continue. This will cause self._wallet_address to be None, and any subsequent tool that relies on it (like pay_for_cart) will fail later with a less clear error. It's better to fail fast during initialization if a critical component like the wallet is unavailable.

Suggested change
logger.error(f"Could not connect to mock wallet to get address: {e}")
# Handle the error appropriately, maybe by preventing initialization
return
logger.error(f"Could not connect to mock wallet to get address: {e}")
# Prevent agent from starting without a wallet address.
raise RuntimeError("Failed to initialize wallet connection.") from e

valid_after=valid_after,
valid_before=valid_before,
nonce="0x" + os.urandom(32).hex(),
nonce="0x" + os.urandom(32).hex(), # type: ignore[arg-type]
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The type: ignore[arg-type] here is hiding an underlying type mismatch. The get_transfer_with_auth_typed_data function expects nonce to be of type bytes, but it's being passed a hex string. This could lead to signing or transaction errors down the line. The correct approach is to pass the raw bytes directly from os.urandom(32).

Suggested change
nonce="0x" + os.urandom(32).hex(), # type: ignore[arg-type]
nonce=os.urandom(32),

Comment on lines +130 to +135
"amount": {"currency": "USDC", "value": price_in_usd},
}
],
"total": {
"label": "Total",
"amount": {"currency": "USD", "value": price_in_usd},
"amount": {"currency": "USDC", "value": price_in_usd},
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 currency is hardcoded as 'USDC'. To improve maintainability and avoid magic strings, it's better to define this as a constant at the top of the file (e.g., _CURRENCY = "USDC") and use it in all relevant places.

).get("id")
payment_id = f"payment_{uuid.uuid4()}"
price_in_usd = (
f"{int(auth_dict.get("value")) / 1000000:.2f}"
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 value 1000000 is used to convert the price from its smallest unit, assuming 6 decimal places for USDC. This is a 'magic number'. It would be more readable and maintainable to define this as a named constant (e.g., _USDC_DECIMALS = 1_000_000) or at least use underscores for readability.

Suggested change
f"{int(auth_dict.get("value")) / 1000000:.2f}"
f"{int(auth_dict.get("value")) / 1_000_000:.2f}"

agent=self.create_agent(),
rpc_url=url,
capabilities=capabilities,
agent_version="5.0.0",
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 agent_version is hardcoded. It's good practice to define version strings as constants, typically at the module or class level (e.g., _AGENT_VERSION = "5.0.0"), to make them easier to find and update.

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.

1 participant