Build an AI Shopping Agent with Full Identity Infrastructure

A step-by-step tutorial for building an AI shopping agent that can handle payments, 2FA, and secure credential storage.

Anima Team2 min read
#tutorial#shopping-agent#getting-started

Building a Shopping Agent from Scratch#

An AI shopping agent needs to do more than just find a product. It needs to navigate a checkout flow, handle 2FA via SMS, store its merchant credentials, and receive an order confirmation email. In this tutorial, we'll build one using the Anima SDK.

Step 1: Initialize the Agent Identity#

First, we'll create a new agent identity with the necessary capabilities.

import { Anima } from '@anima/sdk';
 
const am = new Anima(process.env.AM_API_KEY);
 
const agent = await am.identities.create({
  name: "Shopping-Assistant-Alpha",
  capabilities: ['cards', 'email', 'phone', 'vault']
});
 
console.log(`Agent created with ID: ${agent.id}`);

Step 2: Configure Email and Phone#

The agent needs an email address for receipt parsing and a phone number for 2FA.

const email = await agent.email.provision({
  domain: "my-agents.com",
  prefix: "shopping-01"
});
 
const phone = await agent.phone.provision({
  country: "US",
  type: "mobile"
});
 
console.log(`Email: ${email.address}, Phone: ${phone.number}`);

Step 3: Issue a Virtual Card with Visa TAP#

We'll issue a virtual card specifically for this agent. We'll use the Visa TAP protocol to set a strict spending limit and merchant whitelist.

const card = await agent.cards.issue({
  limitCents: 20000, // $200.00 limit
  protocol: 'VISA_TAP',
  policy: {
    allowedMerchants: ['amazon.com', 'bestbuy.com'],
    maxTransactions: 5
  }
});

Step 4: Store Credentials in the Vault#

Instead of hardcoding merchant logins, we'll store them in the agent's secure identity vault.

await agent.vault.set('amazon_creds', {
  username: "agent-user@my-agents.com",
  password: "secure-generated-password-123"
});

Step 5: Handling the Checkout Flow#

When the agent reaches a checkout page that requires a 2FA code, it can listen for incoming SMS messages.

agent.on('sms:received', async (message) => {
  if (message.body.includes('verification code')) {
    const code = message.body.match(/\d{6}/)?.[0];
    console.log(`Received 2FA code: ${code}`);
    // Use the code in your agent's browser automation loop
  }
});

Step 6: Parsing the Receipt#

Once the purchase is complete, Amazon will send a confirmation email. Anima automatically parses the MIME content and provides a clean JSON representation.

agent.on('email:received', async (mail) => {
  if (mail.from.includes('amazon.com')) {
    const orderNumber = mail.data.metadata.order_number;
    console.log(`Order ${orderNumber} confirmed!`);
    await agent.cards.update(card.id, { active: false }); // Disable card after purchase
  }
});

Conclusion#

By using Anima, we've given our shopping agent a complete, verifiable identity. It can now act as a first-class citizen on the web, handling payments and security challenges just like a human user would. This approach is more robust than a DIY stack and more flexible than proprietary intent engines.

For more advanced configurations, check out our full documentation on the Anima SDK. Happy building!

Stay Updated

Get the latest on AI agent identity, delivered weekly.