ap2

The AP2 (Agent Payments Protocol) extension declares payment roles for agents, enabling payment-aware agent discovery.

Installation

bun add @regent/ap2

Basic Usage

import { createAgent } from '@regent/core';
import { http } from '@regent/http';
import { payments } from '@regent/x402';
import { ap2 } from '@regent/ap2';

const agent = await createAgent({
  name: 'my-agent',
  version: '1.0.0',
})
  .use(http())
  .use(payments({ config: paymentsConfig }))
  .use(ap2({ roles: ['merchant'] }))
  .build();

API Reference

ap2(options?)

Creates the AP2 extension.

AP2Config

AP2Runtime

When the extension is used, agent.ap2 provides:

AP2 Roles

Agents can declare one or more payment roles:

Role
Purpose
Use Case

merchant

Accepts payments

Service provider, vendor

shopper

Makes payments

Buyer, consumer

credentials-provider

Provides credentials

KYC/AML provider

payment-processor

Processes payments

Payment gateway

Single Role

Multiple Roles

Manifest Integration

AP2 adds an extension descriptor to the Agent Card:

Default required Behavior

  • required: true when 'merchant' role is included

  • required: false otherwise

  • Can be explicitly overridden

Manual Card Enhancement

Detecting AP2 Support

Check if another agent supports AP2:

Integration Examples

Payment Receiver (Merchant)

Payment Sender (Shopper)

Bidirectional Trading Agent

AP2 and A2A Relationship

Aspect
A2A
AP2

Purpose

Agent discovery & communication

Payment capability declaration

Scope

Protocol-agnostic interface

Payment-specific roles

Required

Always present with a2a()

Optional, explicit config

Agent Card

Base structure

Extension metadata

AP2 extends A2A by adding payment information to Agent Cards.

Exports

Last updated