Skip to content

Conversation

@jaytoday
Copy link

@jaytoday jaytoday commented Sep 30, 2025

This enhancement extends AP2 with a comprehensive micropayment channel framework that enables high-frequency, sub-cent transactions between agents through state channels, supporting Kite's vision of pay-per-use and streaming payment models.

Key Features:

  • Payment channel infrastructure with state management
  • Streaming payment primitives for real-time micropayments
  • Multi-currency support including stablecoins (USDC, PYUSD)
  • Channel security framework with dispute resolution
  • Pay-per-token, pay-per-second, and pay-per-API-call models
  • A2A extension integration for agent capability advertising

Components Added:

  • PaymentChannel with participant management and policies
  • StreamingPaymentSession for continuous payment flows
  • ChannelManager for lifecycle and security operations
  • CryptoPaymentAmount for blockchain-native currencies
  • AI inference service sample with micropayment integration
  • Extended A2A roles: micropayment-provider, streaming-payment-consumer

This enables use cases like:

  • Pay-per-API-call for AI inference services
  • Streaming payments for real-time data feeds
  • Usage-based pricing for computational resources
  • Micro-subscriptions with automatic scaling
  • Cross-agent value transfer in multi-step workflows

Transforms AP2 from traditional e-commerce into a comprehensive framework for the agent economy, enabling ultra-high-frequency programmable payment flows while maintaining security and interoperability.

Description

Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

This enhancement extends AP2 with a comprehensive micropayment channel
framework that enables high-frequency, sub-cent transactions between
agents through state channels, supporting Kite's vision of pay-per-use
and streaming payment models.

Key Features:
- Payment channel infrastructure with state management
- Streaming payment primitives for real-time micropayments
- Multi-currency support including stablecoins (USDC, PYUSD)
- Channel security framework with dispute resolution
- Pay-per-token, pay-per-second, and pay-per-API-call models
- A2A extension integration for agent capability advertising

Components Added:
- PaymentChannel with participant management and policies
- StreamingPaymentSession for continuous payment flows
- ChannelManager for lifecycle and security operations
- CryptoPaymentAmount for blockchain-native currencies
- AI inference service sample with micropayment integration
- Extended A2A roles: micropayment-provider, streaming-payment-consumer

This enables use cases like:
- Pay-per-API-call for AI inference services
- Streaming payments for real-time data feeds
- Usage-based pricing for computational resources
- Micro-subscriptions with automatic scaling
- Cross-agent value transfer in multi-step workflows

Transforms AP2 from traditional e-commerce into a comprehensive
framework for the agent economy, enabling ultra-high-frequency
programmable payment flows while maintaining security and
interoperability.
@jaytoday jaytoday requested a review from a team as a code owner September 30, 2025 01:11
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jaytoday, 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 enhances AP2 by integrating a robust micropayment channel extension. This new capability facilitates ultra-high-frequency, low-value transactions, transforming AP2 into a comprehensive platform for the agent economy. It enables flexible payment models like streaming and pay-per-use, and includes a sample AI inference service to demonstrate its practical application, alongside necessary updates to documentation and core payment types.

Highlights

  • Micropayment Channel Framework: Introduces a comprehensive framework for micropayment channels within AP2, enabling high-frequency, sub-cent transactions between agents. This includes infrastructure for channel management, state handling, and security.
  • Streaming Payment Primitives: Adds core primitives for streaming payment models, supporting real-time micropayments for services like pay-per-token, pay-per-second, and pay-per-API-call, crucial for AI inference and data feeds.
  • Multi-Currency Support: The framework now supports multiple currencies, including stablecoins like USDC and PYUSD, and integrates with various blockchain networks such as Ethereum and Polygon.
  • A2A Extension Integration: Extends the Agent-to-Agent (A2A) protocol with new roles: micropayment-provider and streaming-payment-consumer, allowing agents to advertise their capabilities for micropayment services.
  • AI Inference Service Sample: A new sample AI inference service demonstrates the practical application of micropayment channels, showcasing how AI services can implement pay-per-token models using the new framework.
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 comprehensive micropayment channel framework, a significant enhancement for AP2. The new modules for channel management and streaming payments are well-structured and the sample AI inference service is a great addition for demonstrating the new capabilities. The code quality is high, and the widespread adoption of modern Python styling and type hints across the codebase is a welcome improvement for maintainability. I have a few minor suggestions to enhance code clarity and robustness.

Comment on lines +389 to +393
state_data = f'{channel_id}'
for participant in participants:
state_data += f'{participant.participant_id}:{participant.current_balance.value}'

return hashlib.sha256(state_data.encode()).hexdigest()
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 current state hash calculation is dependent on the order of participants in the list. This could lead to different hashes for the same state if the participant order changes for any reason. To make this more robust, I recommend sorting the participants by a unique and consistent key (e.g., participant_id) before generating the hash string.

Suggested change
state_data = f'{channel_id}'
for participant in participants:
state_data += f'{participant.participant_id}:{participant.current_balance.value}'
return hashlib.sha256(state_data.encode()).hexdigest()
state_data = f'{channel_id}'
sorted_participants = sorted(participants, key=lambda p: p.participant_id)
for participant in sorted_participants:
state_data += f'{participant.participant_id}:{participant.current_balance.value}'
return hashlib.sha256(state_data.encode()).hexdigest()

'I appreciate your question. Let me break this down into manageable components for you.',
]

import random
Copy link
Contributor

Choose a reason for hiding this comment

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

low

To adhere to PEP 8 guidelines and improve code readability, please move this import statement to the top of the file with the other imports.

Comment on lines +437 to +443
inactive_clients = []
for client_did, channel_id in self.active_clients.items():
if channel_id not in self.channel_manager.active_channels:
inactive_clients.append(client_did)

for client_did in inactive_clients:
del self.active_clients[client_did]
Copy link
Contributor

Choose a reason for hiding this comment

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

low

This logic for removing inactive clients can be made more concise and Pythonic by using a dictionary comprehension. This improves readability by expressing the intent in a single statement.

Suggested change
inactive_clients = []
for client_did, channel_id in self.active_clients.items():
if channel_id not in self.channel_manager.active_channels:
inactive_clients.append(client_did)
for client_did in inactive_clients:
del self.active_clients[client_did]
self.active_clients = {
client_did: channel_id
for client_did, channel_id in self.active_clients.items()
if channel_id in self.channel_manager.active_channels
}

Comment on lines +220 to +228
def is_expired(self, current_time: datetime | None = None) -> bool:
"""Check if the channel has expired."""
if current_time is None:
current_time = datetime.now(UTC)

expires_at = datetime.fromisoformat(
self.expires_at.replace('Z', '+00:00')
)
return current_time > expires_at
Copy link
Contributor

Choose a reason for hiding this comment

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

low

This is a minor point for future maintainability. The use of .replace('Z', '+00:00') is necessary for Python versions before 3.11. However, datetime.fromisoformat in Python 3.11+ can handle the 'Z' (Zulu time) suffix directly. Since the codebase is adopting other modern Python features, you might consider removing this replace call if you are targeting Python 3.11 or newer.

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