> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentcard.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Acknowledging the shopper: a reaction or a short text

> Tell the shopper you are on it while Agentcard works, with a 👀 on their message or a short text.

A first search can take Agentcard most of a minute. While it works, the shopper sees a 👀 on their own message, the way a friend reacts to a text before answering it. In a chat that shows no reactions, the shopper reads a short text instead, such as `one sec, checking target for la croix`.

## React with a 👀

Pass `onReaction` to `buy.turn`. Show the emoji as a tapback on the shopper's bubble.

```ts chat.ts theme={null}
const turn = buy.turn(message, {
  onReaction: (emoji) => reactToShopperMessage(shopper.id, emoji), // your code; emoji is always '👀'
});
```

A reaction is the default acknowledgement. It names nothing the shopper said, so it never reads a request back wrong, and the chat holds only real answers. Each message gets at most one 👀, and it goes out in these cases:

* A message that starts a search gets it the moment `buy.turn` opens, before your model runs.
* A call that Agentcard has not answered within 1 second puts the 👀 on a message that has none yet: a slow `yes`, a pick, or a confirm that is still placing the order. The tool sends no text with the 👀.

These messages get none when the turn opens, because Agentcard answers them fast: a pick of a product or a store the shopper saw, an address or other details, an answer to a question such as `yes`, `2`, or a code, a step toward checkout such as `ok lets checkout`, and an acknowledgement such as `its ok`.

When the 👀 went out, the model reads `shopper_already_told_looking: true` in that turn's answers, and its description tells it not to acknowledge the request again. The reply opens with the answer or the question, not `on it`. The field reads false on a turn that reacted with nothing, and when `onReaction` threw. An `onReaction` that throws costs only the reaction.

With `onItem` on the turn, the 👀 still goes to `onReaction` and never joins the turn's items, because it sits on the shopper's bubble and not in the agent's sequence.

## Send a short text instead

For SMS, or any chat that shows no reactions, pass `onWorking` and no `onReaction`, or set `ack: 'text'`:

```ts chat.ts theme={null}
const buy = buyTool({
  agentcard,
  externalUserId: shopper.id,
  ack: 'text',
  onWorking: (text) => textShopper(shopper.id, text), // your code
});
```

`ack` takes `'reaction'`, `'text'`, or `'none'`. Left out, the tool reacts when the tool or the turn has an `onReaction`, and sends text through `onWorking` otherwise. With both callbacks, the shopper gets the 👀 and never the text too. `'none'`, or `false`, sends nothing.

With `ack: 'reaction'`, or an `onReaction` on the turn, Agentcard's line never reaches the shopper as text, not even through `onText`. The shopper reads the 👀 alone.

A streamed search that `buy.turn` sends straight to Agentcard gets a line that Agentcard writes while it searches, from the shopper's message and the last turns of the conversation. After a search for office chairs, `can you show me yellow ones` reads `looking now for yellow ergonomic office chairs under $250`. The line goes to `onWorking`, or to `onText` when you pass no `onWorking`, before the cards.

The line goes out only while the shopper has read nothing else of the turn, because a line after a card or a message says nothing. When it goes out, the model reads `shopper_already_told_looking: true`.

When your app writes the model's words through the turn, a straight search has a fallback. If Agentcard's line has not come after twice `ackDelayMs`, 2 seconds by default, and the call has not answered, the tool sends `one moment` once through `onWorking`. A line of Agentcard's that comes after that is dropped, so the shopper reads one line. A call that answers or fails first cancels the fallback, so a failed search is never followed by `one moment`.

A pick, a confirm, or an answer such as `yes` or an address waits for the delay. When the turn has shown the shopper nothing for `ackDelayMs`, 1 second by default, it sends one line through `onWorking`. A turn sends one line at most, however many calls the model makes. The call waits for `onWorking`, so the shopper reads the line before any link and before the model answers. An `onWorking` that throws costs only the line.

| The shopper's message | The text |
| - | - |
| A streamed search sent straight | The line Agentcard writes, such as `one sec, checking target for la croix`. |
| The same search, when Agentcard's line has not come after twice `ackDelayMs` | `one moment`, and Agentcard's line is dropped if it comes later. |
| A search with `stream: false` | A template of the tool's, such as `on it, looking for usb-c cables under $20` or `give me a sec, checking for a table for 2 in north beach`. |
| A slow pick of a product, a store, or a place in a list such as `the first one` | `got it, one moment` |
| A slow confirm | `on it, one moment` |
| Any other slow answer, such as `yes` or an address | `one moment` |
| A code | No text. |

A fixed line names nothing the shopper said. A turn counts what the shopper read only when your app writes the model's words through the turn, with `onItem`, `onMessage`, `turn.messageStream()`, or `turn.say()`. In any other app, the tool sends the fixed line when a call has gone `ackDelayMs` without an answer.

### Read which searches get Agentcard's line

On a tool built with `direct: true`, `buy.turn` asks Agentcard for the line on a search it sends without your model. A pick, a confirm, an address, and an answer such as `yes` get no line from Agentcard.

A search sent with `stream: false` gets none either, because a caller that waits for the whole answer would read the line after the answer.

A turn that your model runs gets no line from Agentcard. The tool's description tells your model to write one short line itself before it calls the tool on a new request, and that line is the turn's acknowledgement. When your app writes the model's words through the turn and the model has written nothing, the tool sends a fixed line instead: `one moment` for a search, once the model calls the tool or twice `ackDelayMs` passes. When the shopper already read a line, the call asks Agentcard for none.

With `stream: false`, the tool writes the search's line itself. The words rotate through six templates, and one tool never sends the same template twice in a row. A short paraphrase of the request goes in when the tool can read one. It stops before any link, email address, phone number, street address, or long number, and a request that starts with one gets a reply that names nothing, such as `looking for that now`.

Pass `ack: (ask) => text` to write your own text from the shopper's words, where an empty answer sends none. Pass `ackDelayMs` to change the 1 second for either mode.

## Drop your model's opening line

When your model's first message of a turn is a line like `on it, looking for a dryer under $20`, written before it calls the tool, and the fixed line already reached the shopper, the shopper would read two. The turn keeps the model's line in the model's own history and never sends it. A line counts as an opening line when it is one line of at most 90 characters, says the turn is working, as `on it, looking for` does, asks nothing, and claims no result such as a price or a cart. A first message that asks a question, answers, or says what a search found goes out, and so does every message after it.

When the app failed to send the fixed line, the model's line goes out in its place, so the shopper reads one line either way.

## End the turn when your model fails

If your model's run fails before it writes or calls anything, the turn would still send `one moment` or a 👀 after your app showed its error. Call `turn.end()` in the `catch` or `finally` of the run:

```ts chat.ts theme={null}
const turn = buy.turn(message, { onItem: (item) => deliver(shopper.id, item) }); // your code
try {
  await runModel(shopper.id, turn); // your code
} catch (error) {
  turn.end(); // no `one moment` and no 👀 after your error message
  await showError(shopper.id, error); // your code
}
```

`turn.end()` cancels the wait line the turn holds and the acknowledgement of every call still running, a 👀 or a line for a slow pick, confirm, or answer. A call still running keeps answering: its text, its products and its links reach the shopper after your error message, and a search that streams sends Agentcard's line for it. A second call of `turn.end()` does nothing, so a `finally` is safe too.

## Acknowledge before the model runs

The model takes several seconds to call the tool after the shopper's message arrives. With `buy.turn`, the turn acknowledges the moment it opens. In reaction mode, it calls `instantReaction` for you and puts the 👀 on the message. In text mode, a streamed search waits for Agentcard's line, so the turn calls `instantAck` for you only with `stream: false` or an `ack` function.

Outside a turn, call `buy.instantReaction(message)` the moment the message arrives, before your model runs, and put the emoji it returns on the message. In text mode, call `buy.instantAck(message)` and send the text it returns.

```ts chat.ts theme={null}
const reaction = buy.instantReaction(message); // '👀' or null
if (reaction) await reactToShopperMessage(shopper.id, reaction);
// In text mode instead:
const ack = buy.instantAck(message);
if (ack) await textShopper(shopper.id, ack);
```

Both return null for a message that starts no search, such as a confirmation, a short answer, a step toward paying, a pick of something the shopper saw, a code, small talk like `hi`, a message that carries the shopper's own details, or a short reply right after a question the last answer asked. A reply that opens a new request, such as `find me black running shoes`, or that runs past four words is still a search. When either returns an acknowledgement, neither the tool nor Agentcard sends one for that turn.

The reply never reads the shopper's details back, and it names the request only when it reads as a short, whole phrase. Otherwise it says `on it, give me a moment` or another reply that names nothing. Pass `ack: 'none'` to the tool when you acknowledge yourself.

## Show a long wait

A turn that runs long, even past a minute, gets no second text line. A search often takes 10 to 40 seconds, so a second line at any wait short enough to help would land on most searches and bring back the chatter the reaction replaces.

To show a long wait, pass `onProgress` and show its stage as a status line or a typing indicator:

```ts chat.ts theme={null}
const turn = buy.turn(message, {
  onProgress: ({ stage }) => showStatus(shopper.id, stage), // 'searching', 'building_cart', 'checking_out' or 'working'
});
```

The tool then asks Agentcard to stream each call. Pass `stream: false` to wait for each whole answer instead.

## Check it in the sandbox

1. Send "two packs of AA batteries from Amazon" as a test shopper. Check that the 👀 appears on your message at once, before the model answers, and that the reply opens with the answer.
2. Send "yes" after a cart. Check that no 👀 appears at once, and that a slow answer gets one after about 1 second.
3. Send "the first one" after a product list. Check that no reaction or text appears when the turn opens.
4. Switch to `ack: 'text'` and send `la croix from target`. Check that a line like `one sec, checking target for la croix` reaches `onWorking` before the cards, and that the reply opens with the answer.
5. Send "the first one" after a product list, in text mode, with a store slow enough to pass 1 second. Check that `got it, one moment` arrives once and repeats none of your words.
6. Make `onReaction` throw. Check that the turn still answers and the model reads `shopper_already_told_looking: false`.
7. Make your model throw before it writes anything, and call `turn.end()` in the `catch`. Wait 3 seconds. Check that the shopper reads your error and no `one moment` after it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.