Agent Payments Protocol (AP2)

repository·main·Indexed 25 days ago

https://github.com/google-agentic-commerce/ap2

A framework and set of samples for implementing agentic commerce and payments. AP2 includes a Python SDK (version 0.1) for managing carts, mandates, and payment requests, alongside reference implementations in Python, Go, and Android. It demonstrates agent-to-agent (A2A) and human-in-the-loop payment flows, featuring components such as Merchant Agents, Credentials Providers, Shopping Agents, and Payment Processors.

Tokens
41.9K
Snippets
61
Records
201
Agent score
84%

What's inside AP2

  1. Overview of AP2 Repository Structure

    main

    The Agent Payments Protocol (AP2) repository is organized into three main components:

    • sdk/: The core AP2 SDK. The current primary implementation is in Python, installed via import ap2.
    • samples/: Reference implementations of end-to-end scenarios (Merchant, Credentials Provider, Shopping Agent, Payment Processor) across Python, Go, and Android.
    • web-client/: A demo UI built with Vite, React, and TypeScript used to exercise the A2A protocol against sample agents.
  2. Overview of the Agent Payments Protocol (AP2)

    main
    The Agent Payments Protocol (AP2) is an open, interoperable protocol designed as an extension for emerging agent-to-agent (A2A), model-context protocols (MCP), and Universal Commerce Protocol (UCP). It provides a secure framework for AI-driven commerce, addressing the lack of mechanisms in existing payment infrastructures to validate an agent's authenticity and authority to transact. AP2 aims to solve issues around transaction liability, authorization, and accountability in autonomous, non-human agent transactions.
  3. Overview of Agent Payments Protocol (AP2)

    main

    Agent Payments Protocol (AP2) is an open protocol designed for the Agent Economy to enable secure, reliable, and interoperable agent commerce. It serves as an extension for the Agent2Agent (A2A) protocol and the Universal Commerce Protocol (UCP).

    AP2 addresses critical challenges in autonomous agent commerce, including:

    • Authorization: Verifying user authority for specific purchases.
    • Authenticity: Ensuring agent requests accurately reflect user intent.
    • Accountability: Providing a cryptographic audit trail for dispute resolution.

    Developers can build agents using any framework (e.g., ADK), equip them with tools (e.g., MCP), and use AP2 to secure payments.

  4. Python AP2 Samples Layout

    main

    The Python sample repository is organized as follows:

    • scenarios/: Runnable end-to-end flows. Each contains a run.sh or run_*.sh script to start all required agents/servers.
    • src/roles/: Individual implementations of AP2 roles (e.g., merchant, credentials provider).
    • src/common/: Shared utilities including A2A clients, message builders, and server bootstrapping.
  5. Explore Go samples for the Agent Payments Protocol (AP2)

    main

    The code/samples/go/ directory provides Go-based implementations of AP2 agents. These samples demonstrate how to leverage Go's type safety, performance, and concurrency for building backend agents.

    Currently, the available scenario is:

    • Human-Present Card Payment (A2A): A complete card payment flow involving Go agents and a Python Shopping Agent. Detailed instructions for this specific scenario can be found in its dedicated README.
  6. Guiding Principles of AP2

    main

    The AP2 protocol is built on four core principles to ensure a secure and equitable agent economy:

    • Openness and Interoperability: A non-proprietary extension for A2A, MCP, and UCP to foster a competitive environment.
    • User Control and Privacy by Design: Ensures granular user control and protects sensitive data (like conversational prompts and PCI data) through Selective Disclosure.
    • Verifiable Intent, Not Inferred Action: Transactions are anchored to deterministic, non-repudiable proof of intent rather than probabilistic LLM outputs to prevent errors from agent 'hallucinations'.
    • Clear Transaction Accountability: Provides supporting evidence to help payment networks establish clear liability principles.
  7. Understand the Agentic Authorization model

    main

    The Agentic Authorization model in AP2 is designed to constrain the non-deterministic behavior of Agents by providing clear proof of user intent to Verifiers. The process consists of two distinct phases:

    1. Mandate Delegation: The User approves specific Mandate Content on a Trusted Surface and delegates the resulting Mandate to the Agent.
    2. Action Authorization: When an Agent attempts an action, a Verifier challenges the Agent for proof of authorization. The Agent presents a relevant Mandate, and upon successful verification, the Verifier issues a Receipt to the Agent.
  8. Explore the AP2 repository structure

    main

    The repository is organized as follows:

    • docs/: Specification, flows, FAQ, and MkDocs sources.
    • code/sdk/: The AP2 SDK (Python SDK is located at code/sdk/python/ap2/).
    • code/samples/: Reference implementations and scenarios.
      • code/samples/python/scenarios/: Python scenarios.
      • code/samples/go/scenarios/: Go scenarios.
      • code/samples/android/scenarios/: Android scenarios.
    • code/web-client/: The demo web client (Vite + React).
  9. Understand Mandate States: Open vs Closed

    main

    In the AP2 protocol, Mandates exist in two distinct states to facilitate both human-present and autonomous agent actions:

    • Open Mandate: A mandate that has not yet been bound to a specific transaction. It contains constraints on what the closed mandate can contain and is bound to a specific Agent. Open mandates MUST support cryptographic Key Binding (using the cnf claim) to allow agents to perform autonomous actions.
    • Closed Mandate: A mandate bound to a specific transaction with a Verifier. This is achieved by the Agent generating a Key Binding JWT (Proof-of-Possession) using the key endorsed in the open Mandate's cnf claim.

    Mandates form a cryptographically verifiable chain from the user-approved Open Mandate to the transaction-specific Closed Mandate.

  10. Understand Payment Mandate types and usage

    main

    A Payment Mandate is used to authorize payment for a specific checkout. The lifecycle involves the Shopping Agent creating the content, the Trusted Surface rendering it to the User, and the Credential Provider, Network, and Merchant Payment Processor verifying it.

    There are two types of Payment Mandates defined by the vct claim:

    • Closed Payment Mandate: Use mandate.payment.1.
    • Open Payment Mandate: Use mandate.payment.open.1. Open mandates may optionally include any property found in a closed mandate.
  11. Identify AP2 Roles and Responsibilities

    main

    The Agentic Payment Protocol (AP2) defines five distinct roles. While an entity can play multiple roles, each role carries specific verification and processing responsibilities:

    • Shopping Agent (SA): Performs product discovery, builds the checkout, and executes the purchase. Expected to be agentic.
    • Credential Provider (CP): Source of Payment Credentials. Verifies Agent authorization and scopes credentials. Can be agentic or non-agentic.
    • Merchant (M): Provides and completes the Checkout. Verifies items and ensures inventory/pricing integrity. Can be agentic or non-agentic.
    • Merchant Payment Processor (MPP): Processes payments. Verifies that the Payment Credential is authorized for the specific Checkout instance. Can be agentic or non-agentic.
    • Trusted Surface (TS): A UI surface used to obtain informed user consent for an Intent and create user-signed Mandates. MUST be non-agentic.

    Note: Validation and processing for any role MUST occur in deterministic code, even if the role itself is agentic.

  12. Understand Mandate Delegation models

    main

    Mandate Delegation allows an Agent to obtain authorization from a User to perform specific actions (like payments). AP2 defines two primary models for this:

    1. User Credential Model: A three-party model involving a User Credential Issuer, a Trusted Surface (acting as the Holder of the User Credential), and the Agent. The Verifier trusts the Issuer to ensure the Trusted Surface only constructs Mandates after obtaining explicit user consent. This allows a single User Credential to delegate mandates to many different Agents without the Verifier needing a direct trust relationship with every Agent.

    2. Trusted Agent Provider Model: The Agent Provider is the party trusted by the Verifier. The Agent passes Mandate Content to a Trusted Surface controlled by the Provider. The Provider obtains user consent and uses a secure signing key to create the Mandate. This is simpler but requires Verifiers to establish trust with every Agent Provider.