# Every reply on the right thread

New sender, new subject, days later — it still lands on the conversation it answers. Your agent reads the whole thread in one call.

[Get started](/signup)
[Documentation](https://docs.aiinbx.com/guides/threads)

Four mails that look unrelated: the RFQ you sent, Dana's out-of-office auto-reply, a reply from Marco (a new sender with a new subject), and Dana's confirmation four days later. They fold into one conversation, thread thr\_8f2c, in order, with the last two smart-matched.

In the console

## Everything that came back, on one page

The console's thread page shows all four messages of the thread in order, each labelled with its category (out of office, human). Under each smart-matched message it says why it landed on this thread and quotes the words it relied on, such as Marco’s “Covering for Dana this week” and Dana’s “$4.80 a sheet at 240 works”.

In your code

## One id in, the whole conversation out

Step 1, email.received: what we post to your webhook.

```
{
  "type": "email.received",
  "data": {
    "thread_id": "thr_8f2c",
    "from": "marco.lind@lindmetall.de"
  }
}
```

Step 2, GET /v1/threads/thr\_8f2c: what one call gives you back.

```
{
  "id": "thr_8f2c",
  "subject": "RFQ 4471 — 3mm brushed sheets",
  "messages": [
    { "direction": "outbound", "from": { "address": "nora@northwind.io" } },
    { "direction": "inbound",  "from": { "address": "dana@lindmetall.de" } },
    { "direction": "inbound",  "from": { "address": "marco.lind@lindmetall.de" } },
    { "direction": "inbound",  "from": { "address": "dana@lindmetall.de" } }
  ]
}
```

Step 3, your handler: in-reply-to, references and subject: ours.

```
const { thread_id } = event.data

const thread = await aiinbx.threads.retrieve(thread_id)
const answer = await agent.run(thread.messages)

await aiinbx.threads.reply(thread_id, { text: answer })
```

## Give your product an inbox. The hard parts are already handled.

[Get started](/signup)
