AP2 Merchant Agent Implementation
Before writing code
Fetch live docs:
- Fetch
https://ap2-protocol.org/specification/ for Merchant Endpoint responsibilities
- Web-search
site:github.com google-agentic-commerce AP2 samples roles merchant_agent for reference implementation
- Web-search
site:github.com google-agentic-commerce AP2 merchant cart mandate for Cart Mandate creation
- Fetch SDK docs for merchant-side agent patterns
Conceptual Architecture
What the Merchant Agent Does
The Merchant Agent (ME) represents the seller in AP2 transactions:
- Receives Intent Mandates from Shopping Agents
- Searches product catalog for matching items
- Creates Cart Mandates with specific product offers, prices, and totals
- Signs Cart Mandates with the merchant entity's signature
- Handles clarification requests when intent is ambiguous
- Supports the payment flow by forwarding to Payment Processor
Agent Card
The Merchant Agent's Agent Card advertises:
- AP2 extension support with supported payment methods
- Skills related to product search, cart creation, order management
- Product categories and capabilities
- Authentication requirements for Shopping Agents
Key Responsibilities
Intent Processing
- Parse incoming Intent Mandates from Shopping Agents
- Match intent against product catalog
- Determine if the intent can be fulfilled within constraints
- Decide whether to proceed, request clarification, or reject
Cart Mandate Creation
- Select matching products from catalog
- Calculate prices, taxes, shipping, and totals
- Build the Cart Mandate with W3C Payment Request API structure
- Include all line items with individual pricing
- Sign the Cart Mandate with the merchant entity's key
Merchant Signature
The merchant signature is critical:
- It's an entity-level signature (the merchant organization, not the AI agent)
- It guarantees product availability at the stated prices
- It commits the merchant to fulfillment
- Key management must be handled at the organization level
Escalation Decisions
When facing ambiguous intent, the merchant can:
- Offer choices — Present multiple matching products for user selection
- Ask clarifications — Request more specific requirements
- Force human-present — Require the user to confirm directly
- Reject — Decline the intent if it can't be fulfilled
Catalog Integration
The Merchant Agent needs access to:
- Product catalog — Names, descriptions, SKUs, images
- Inventory — Real-time stock availability
- Pricing — Current prices, discounts, taxes
- Shipping — Available shipping methods, costs, timeframes
- Policies — Return policy, refund period, terms
Payment Method Advertisement
Cart Mandates include supported payment methods:
"method_data": [
{
"supportedMethods": "https://processor.example.com/pay",
"data": { "merchant_id": "..." }
}
]
Multi-Merchant Scenarios
A Shopping Agent may contact multiple merchants:
- Each merchant independently evaluates the Intent Mandate
- Each returns their own Cart Mandate
- The Shopping Agent compares offers on behalf of the user
- The merchant should respond quickly to be competitive
Best Practices
- Sign Cart Mandates at the entity level, not the agent level
- Include all items with clear descriptions and prices
- Respond to Intent Mandates promptly — the Shopping Agent may be comparing merchants
- Handle out-of-stock gracefully with alternatives or clear messaging
- Implement proper key management for merchant signing keys
- Validate incoming Intent Mandates for authenticity
- Keep catalog data fresh — stale prices cause disputes
- Log all Cart Mandate creation for audit trail
Fetch the specification for exact Merchant Agent requirements, Cart Mandate creation process, and signing formats before implementing.
1---2name: ap2-merchant-agent3description: Build an AP2 Merchant Agent — the seller-side agent that receives intent mandates, searches product catalogs, creates signed cart mandates, and represents the merchant in agentic transactions. Use when implementing the Merchant Endpoint role.4---56# AP2 Merchant Agent Implementation78## Before writing code910**Fetch live docs**:111. Fetch `https://ap2-protocol.org/specification/` for Merchant Endpoint responsibilities122. Web-search `site:github.com google-agentic-commerce AP2 samples roles merchant_agent` for reference implementation133. Web-search `site:github.com google-agentic-commerce AP2 merchant cart mandate` for Cart Mandate creation144. Fetch SDK docs for merchant-side agent patterns1516## Conceptual Architecture1718### What the Merchant Agent Does1920The Merchant Agent (ME) **represents the seller** in AP2 transactions:21221. **Receives Intent Mandates** from Shopping Agents232. **Searches product catalog** for matching items243. **Creates Cart Mandates** with specific product offers, prices, and totals254. **Signs Cart Mandates** with the merchant entity's signature265. **Handles clarification requests** when intent is ambiguous276. **Supports the payment flow** by forwarding to Payment Processor2829### Agent Card3031The Merchant Agent's Agent Card advertises:32- AP2 extension support with supported payment methods33- Skills related to product search, cart creation, order management34- Product categories and capabilities35- Authentication requirements for Shopping Agents3637### Key Responsibilities3839#### Intent Processing40- Parse incoming Intent Mandates from Shopping Agents41- Match intent against product catalog42- Determine if the intent can be fulfilled within constraints43- Decide whether to proceed, request clarification, or reject4445#### Cart Mandate Creation46- Select matching products from catalog47- Calculate prices, taxes, shipping, and totals48- Build the Cart Mandate with W3C Payment Request API structure49- Include all line items with individual pricing50- Sign the Cart Mandate with the merchant entity's key5152#### Merchant Signature53The merchant signature is critical:54- It's an **entity-level** signature (the merchant organization, not the AI agent)55- It guarantees product availability at the stated prices56- It commits the merchant to fulfillment57- Key management must be handled at the organization level5859#### Escalation Decisions60When facing ambiguous intent, the merchant can:61- **Offer choices** — Present multiple matching products for user selection62- **Ask clarifications** — Request more specific requirements63- **Force human-present** — Require the user to confirm directly64- **Reject** — Decline the intent if it can't be fulfilled6566### Catalog Integration6768The Merchant Agent needs access to:69- **Product catalog** — Names, descriptions, SKUs, images70- **Inventory** — Real-time stock availability71- **Pricing** — Current prices, discounts, taxes72- **Shipping** — Available shipping methods, costs, timeframes73- **Policies** — Return policy, refund period, terms7475### Payment Method Advertisement7677Cart Mandates include supported payment methods:78```json79"method_data": [80 {81 "supportedMethods": "https://processor.example.com/pay",82 "data": { "merchant_id": "..." }83 }84]85```8687### Multi-Merchant Scenarios8889A Shopping Agent may contact multiple merchants:90- Each merchant independently evaluates the Intent Mandate91- Each returns their own Cart Mandate92- The Shopping Agent compares offers on behalf of the user93- The merchant should respond quickly to be competitive9495### Best Practices9697- Sign Cart Mandates at the entity level, not the agent level98- Include all items with clear descriptions and prices99- Respond to Intent Mandates promptly — the Shopping Agent may be comparing merchants100- Handle out-of-stock gracefully with alternatives or clear messaging101- Implement proper key management for merchant signing keys102- Validate incoming Intent Mandates for authenticity103- Keep catalog data fresh — stale prices cause disputes104- Log all Cart Mandate creation for audit trail105106Fetch the specification for exact Merchant Agent requirements, Cart Mandate creation process, and signing formats before implementing.