AgentSea

Guide

ACP

Give an agent commerce tools that call an ACP-compliant backend through ACPClient.

01Setup

ACPClient takes a config with baseUrl, and optionally apiKey, merchantId, timeout (in milliseconds) and headers. createACPTools(client) returns tools that an agent can call.

TS
import { ACPClient, Agent, AnthropicProvider, ToolRegistry, createACPTools } from '@lov3kaizen/agentsea-core';

const acpClient = new ACPClient({
  baseUrl: 'https://api.yourcommerce.com/v1',
  apiKey: process.env.ACP_API_KEY,
  merchantId: process.env.ACP_MERCHANT_ID,
  timeout: 30000,
});

const acpTools = createACPTools(acpClient);
const toolRegistry = new ToolRegistry();
toolRegistry.registerMany(acpTools);

const agent = new Agent(
  { name: 'shopping-assistant', description: 'Shopping assistant', model: 'claude-sonnet-4-6', provider: 'anthropic', tools: acpTools },
  new AnthropicProvider(),
  toolRegistry,
);

Note

The example registers the ACP tools with toolRegistry.registerMany(acpTools).

02Tools

createACPTools returns 14 tools. Their names are:

  • acp_search_products, acp_get_product
  • acp_create_cart, acp_get_cart, acp_add_to_cart, acp_update_cart_item, acp_remove_from_cart
  • acp_create_checkout, acp_update_shipping_address, acp_update_payment_method, acp_complete_checkout
  • acp_get_order, acp_cancel_order, acp_get_order_tracking

03Client methods

The tools call these ACPClient methods. Each returns an ACPResponse.

  • Products: searchProducts, getProduct, getProducts
  • Carts: createCart, getCart, addToCart, updateCartItem, removeFromCart, clearCart
  • Checkout: createCheckoutSession, getCheckoutSession, updateShippingAddress, updateBillingAddress, updatePaymentMethod, completeCheckout
  • Payments: createDelegatedPayment, getPaymentIntent, confirmPayment
  • Orders: getOrder, getCustomerOrders, cancelOrder, getOrderTracking

04Checkout and payments

A checkout runs in this order: create a cart, add items, create a checkout session, set the shipping address and payment method, then call completeCheckout. Payment uses a delegated payment token. The agent should never ask for raw card numbers.

TS
const systemPrompt = `You are a shopping assistant.
Confirm prices and totals before adding items to a cart.
Ask the user to confirm before completing a purchase.
Never ask for raw credit card numbers.`;

Warning

acp_complete_checkout finalizes a purchase. The prompt above asks the agent to confirm first. Nothing in the code enforces that step, so add your own confirmation before the tool runs.

05Configuration

  • baseUrl: required.
  • apiKey and merchantId: optional. Pass them from environment variables.
  • timeout: request timeout in milliseconds. The example uses 30000.
  • headers: extra request headers, as a string map.

06Troubleshooting

  • Tool not found: register the ACP tools with the ToolRegistry the agent was constructed with. The agent config alone is not enough.
  • Timeouts: raise timeout on ACPClient.
  • Failed payments: check the payment token and the merchant account. Error codes are not listed here.