Skip to main content
Some steps happen outside the chat. The shopper saves a card from the Vault link, signs in to DoorDash from the sign-in link, or declines the approval. Agentcard tells your server the moment each one ends. If your server posts Agentcard’s message as it is, the shopper reads “Your Visa ending 4832 is saved, so you’re ready to check out.” and then has to say “ok” before anything moves. Take the next step for them instead, and the shopper reads one message that does the next thing: the approval link, the add-card link, or the total and the ask for their yes.

Open a turn for the message

A message whose advances is true ends a step the shopper took outside the chat. NEXT_STEP_KINDS lists the kinds that advance: card_added, store_connected, and approval_declined. Call buy.nextStep(message) in your onMessage. It returns a turn to run your model on, or null when there is no step to take.
server.ts
anthropic, histories, postToChat, and textOf stand for your own code. The turn is a buy.turn in every way but one: no shopper wrote anything, so turn.messages(history) ends with the event, marked as written by the system, and the instruction to take the next step now in one short message. The model never asks “you’re all set, what’s next?”. Post the model’s answer in place of message.text. The shopper never reads message.text, and the client never hands that text to a later turn as words the shopper read. Wait for each post. A post of the model’s answer that fails sends the turn to the fallback, and a fallback post that fails records nothing as delivered, so Agentcard’s redelivery of the event opens the turn again.

Skip the second yes after a pick

A shopper who picked something does not say yes again after the card or the sign-in. When the shopper picked what is in the cart, such as a product, a tap on its card, or a request to buy it, and answered only the checkout’s questions since, finishing the step is their go-ahead. The turn confirms the same cart by its hash, and the shopper reads the approval link at once. The approval link is the shopper’s consent to the payment: it names the most they can be charged, and Agentcard places the order only once they approve it there. The model reads yes_carried on the answer, with picked: true, and never asks for the yes. A total that moved because the store priced its fees and tax in changes the line only: it opens with the new total, such as it's $17.89 with fees and tax now. approve the payment to place your order (up to $19.02). With direct: true and replyAsWritten: true, the turn’s call goes straight to Agentcard and turn.replyAsWritten is a fixed short line from stepAsWritten, so the turn needs no model call. The step lines are add your card to place the order, sign in to Mendocino Farms to place your order, and approve the payment to place your order (up to $19.02). Read the step lines says when each applies.

Know what the shopper reads next

Keep the shopper’s decision theirs

The turn moves the purchase only up to the shopper’s own decision, and the tool holds it there whatever the model calls.
  • No call of the turn sends an ask to Agentcard, because Agentcard could read the model’s words as the shopper’s go-ahead. Each call reads where the purchase stands and answers with the next step: the card link the sign-in held back, or the cart and the ask for the shopper’s yes.
  • A confirm goes in only for the go-ahead the shopper already gave in the chat: a yes such as “lets place it”, when that confirm stopped for the card or the sign-in they finished, or the pick of what is in the cart. It goes in once, for that cart’s hash, so Agentcard refuses it if the cart changed. A shopper message after the go-ahead that is not a plain go-ahead, such as “wait, make it two”, takes it back.
  • Any other confirm the model sends is refused by the tool, and nothing reaches Agentcard.
  • The approval in the Vault is still the shopper’s. The confirm sends the approval link, and Agentcard places the order only once the shopper approves it.
  • A shopper who was not connected yet when they asked gets their own first ask run, in their words, once their card is saved.

Handle the cases with no step

buy.nextStep returns null in four cases, and your code posts message.text then:
  • The message’s advances is false, such as order_placed, whose text is already the whole message.
  • The message is for another shopper, or its link closed.
  • The tool already took a turn for the message.
  • The message arrives while a call for the shopper’s own message is still running. That call’s answer tells the model where the purchase stands.
When your agent cannot finish the turn, call step.release() before you post message.text. The text then reaches later turns once agentcard.delivered records it, and a redelivery of the event opens a turn again.

Run the listener and the model in one process

The client keeps each message in memory, at most 20 for each shopper, so listen or the webhook handler and the turn run in one process on one client. When your model runs elsewhere, such as a serverless chat route, keep each message where your chat history lives, as an assistant message, and the model reads it from the history. The Quickstart covers the webhook handler for serverless hosts.

Check it in the sandbox

  1. Send “two packs of AA batteries from Amazon” as a test shopper nobody connected, and open the Vault link.
  2. Save a card with the code 111111. Do not type anything in the chat.
  3. Check that the chat posts one message that does the next thing, such as the ask for your yes or the approval link, with nothing typed after the card saved.
  4. Check that the agent ran your first ask, “two packs of AA batteries from Amazon”, in your words once your card was saved, without you asking again.
  5. Ask for a sandwich, pick one, answer the address, and save a card from the Vault link. Check that the next message is the approval link with no second ask for your yes.
  6. Make your model throw during runModel. Check that the shopper still reads message.text.