> Complete content index: https://sondelali.com/llms.txt

# Do Returning Customers Have to Repeat Themselves to Your AI Agent?

> Your returning customers can end up giving your AI agent the same details in every new chat. In one survey, however, most businesses in Asia-Pacific believed that their agent had each customer's history. In this article, I will show you how you can check whether your agent receives a returning customer's earlier details, and how you can brief your coding agent to generate the code that loads those details into every new chat.

URL: https://sondelali.com/blog/agent-memory-between-conversations
Published: 2026-11-23
Category: Technology

<Frame caption="The two halves of the bridge stop short of each other. Your database can store every earlier chat with a customer, while your code sends the model the new chat alone.">
  <img
    src="/images/blog/agent-memory-between-conversations/banner.jpg"
    alt="A flat stylised illustration shows a stone arch bridge across a deep blue gorge at night, with its middle span missing. Warm amber light falls on the left half of the bridge and on the cliff face at the right, while the right half of the bridge and the floor of the gorge are dark."
    loading="eager"
  />
</Frame>

Your returning customers can find themselves giving your AI agent the same details in every new chat. Twilio found this problem in a [survey](https://www.twilio.com/en-us/press/releases/the-ai-expectations-gap--twilio-s-report-finds-businesses-are-me) of consumers and businesses that it carried out in April and May 2026. As [TechNode reports](https://technode.global/2026/09/24/twilio-apac-ai-amnesia-consumer-trust/), 70% of the consumers in Asia-Pacific said that they 'often have to start new AI customer-service conversations from scratch'. The same share said that they had abandoned an AI customer-service chat because it 'lacked basic information about them or previous interactions'. Yet 84% of the businesses in that region believed that their AI agents 'recognize returning customers and their history'.

Suppose that a customer gives your agent a delivery address on Monday. When the customer opens a new chat on Thursday to ask where their armchair is going, the model behind your agent can generate the reply 'Which address should we deliver your armchair to?'

Your database can store every chat that a customer has with your agent. However, the model behind your agent receives only what your code puts into each **request**. A request is the text that your code sends to the model for each reply. As a result, whichever model you choose receives Monday's address only if your code loads that address into Thursday's request.

In other words, your agent has storage but no memory. Its **storage** is the database where your code saves every chat. Its **memory** is what your code loads from that database into the request for each new chat.

## Check whether a returning customer has to repeat themselves

Carry out this check on your agent as it is today. Use a test customer with no orders and no saved address. That way, any address in a later reply can only be one that the customer gives in an earlier chat.

<Steps>
  <Step title="Give the agent a detail in one chat">
    Open a chat as the test customer and give the agent a delivery address, as in 'My delivery address is 41 Kelvin
    Road, Glasgow G12 8QQ.' Then close the chat.
  </Step>
  <Step title="Ask about that detail in a new chat">
    Open a new chat as the same customer, then ask 'Which delivery address do you have for me?'
  </Step>
  <Step title="Look for the address in the reply">
    If you see the address in the reply, the model receives the earlier detail in the new chat. If you see a question
    about the address instead, the model receives only the new chat and the fixed text that your code adds to every
    request.
  </Step>
</Steps>

## What does the model receive when a customer returns?

Your agent's model generates each reply from the request that your code sends to it. Every request that your code sends starts with your **instructions**. Instructions are text such as 'You are the support agent of a furniture shop.' After the instructions, your code adds the messages in the current chat.

Your code can also add a description of each **tool** to the request. A tool is a function in your code, such as a function that looks up an order. In place of a reply, the model can then generate a **tool call**. A tool call is a short text that contains the name of a tool and the values to pass to that tool. From that text, your code calls the tool with those values and adds the tool's result to the request.

In its [guide to conversation state](https://developers.openai.com/api/docs/guides/conversation-state), OpenAI describes each request as 'independent and stateless'. **Stateless** means that the model processes each request with only the text inside that request. The messages from earlier chats are therefore in a new request only when your code adds them.

If you build your agent with an **agent framework**, look at what the sample code in its guide does when a chat starts. An agent framework is a library of code for building AI agents. The AI SDK from Vercel and LangGraph from the company LangChain are examples. In the guides to both frameworks, the sample code saves the messages of each chat under that chat's ID. A new chat has a new ID, which means that code built from those samples starts every new chat with an empty list of messages. The list is empty even when your database stores every earlier chat. In the AI SDK's [guide to saving chat messages](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence), for example, the sample code creates 'an empty chat file' for each new chat.

In its [guide to memory](https://docs.langchain.com/oss/python/concepts/memory), LangChain calls the message history of the current conversation 'short-term memory, or thread-scoped memory'. In that guide, a thread is a single conversation, which means that this history covers one chat only. For details that your code loads into every chat with a customer, LangChain offers a separate [store](https://docs.langchain.com/oss/python/langgraph/persistence). LangChain recommends the store for 'long-term, cross-thread memory, including user preferences, facts, and shared knowledge'.

Whichever framework you use, your code has to put Monday's address into Thursday's request itself. Your code can load Monday's whole chat into the request again, which I will call **replay** in this article. Alternatively, it can save the address as a fact about the customer and load only that fact.

Replay and a saved fact also differ in what you pay your **provider**. Your provider is the company whose model you call, such as OpenAI. That company charges you for every **token** in each request. A token is the unit in which a model processes all text, such as a word or a part of a word.

The illustration below contains the request that the model receives when a returning customer asks where their armchair is going, along with the number of tokens in that request. Choose what your code loads into the request, then move the slider to add earlier chats.

## Why you pay more for worse replies when your code sends every earlier chat

With replay, your code loads every earlier chat into the request again. The request for the armchair question then contains the address, along with everything else from the customer's earlier chats. In the illustration above, choose 'Every earlier chat'. In that option, each earlier chat is about 2,300 tokens long, whereas the address is a single line. That figure is my estimate from the size of the chats in LongMemEval, a test that I will describe below.

A model's replies can also be less accurate when a request is long, for example when it contains many old chats. In October 2024, Di Wu and colleagues published [LongMemEval](https://arxiv.org/abs/2410.10813), a test of 500 questions. The answer to each question is somewhere in a long chat history. The authors tested four **long-context models** on it. A long-context model can receive a long text, such as a whole chat history, in one request. In one setting, each model received a history of about 115,000 tokens, which is about 50 chats. In another, each model received only the chats that contained the answer. With the long history, the models scored between 30% and 60% lower. The authors add that performance is 'likely to further degrade as the interaction history expands'.

With replay, your code adds a whole chat to the request each time that the customer chats with your agent. After about 50 chats, the request will be as long as the long history in that test, which means that your agent's replies can become less accurate in the same way.

You also pay for the whole history on every request, even when your provider stores that history for you. With OpenAI, for example, your code can link each request to the one before it. To do so, your code sets the `previous_response_id` field of the request to the ID of the previous reply. OpenAI then sends the earlier messages to the model for you. In its guide, however, OpenAI states that 'all previous input tokens for responses in the chain are billed as input tokens in the API'.

For the reply about the armchair, the model has to receive only one line of that history, which is the delivery address. Your code can save that line as a fact about the customer. At the start of every chat, your code will then load the customer's facts into the instructions. The request will grow by one line for each new fact, however many chats the customer has. Choose 'Saved facts' and move the slider to compare the size of the request with replay.

## Code that loads each customer's details into a new chat

A **coding agent** is an AI tool, such as Claude Code or Codex, that generates code in your project. A **brief** is a short description that you can paste into a coding agent so that it generates the code that you want. Copy the brief below into your coding agent as it is. From the brief, your coding agent will generate the code that saves each customer's facts in your project's database.

If your project has no database, your coding agent will install Sirannon, which is my database. Sirannon uses [SQLite](https://www.sqlite.org/about.html), a database engine that stores a whole database in a single file. To set up Sirannon, your coding agent will first install the Sirannon **skill**. A skill is a package of written steps and examples for one task, such as setting up Sirannon. Your coding agent will load the skill before it generates the code for that task.

**Brief for your coding agent**

At the start of every new chat with the AI agent in this codebase, put the facts that the user gives in earlier chats into the model's instructions.

- Save each fact in the project's database under the user's identifier, with a key, a value, the ID of the chat, and the time at which the user gives it. If the project has no database, install the Sirannon skill with `npx skills add assetcorp/sirannon-db` and use Sirannon.
- Give the model a tool that saves a fact, and take the user's identifier from the signed-in session alone.
- Leave the earlier chats out of the request.

Show me that the model receives a fact from one chat in the same user's next chat, and only in that user's requests.

The code below is one correct result of this brief on Sirannon 0.4, for a project that has no database yet. This code stores each fact as a **row** in a table of the database. A row is one entry in that table, while a **column** is one part of every row, such as the value of the fact. The `subject` column is the key from the brief.

Each customer has a separate database file under `data/customers`. To find that file, Sirannon calls a **resolver**. A resolver is a function that returns the path of the file for a customer's ID. The `createTenantResolver` function builds that resolver from the folder `data/customers`. In `support.ts`, the `converse` function passes the same ID to `memoryTools` when it creates the tools. That is why the model's tool call contains only the subject and the value.

In `mock-model.ts`, `supportModel` returns a test model from the AI SDK in place of a real model. That test model returns scripted replies so that you can see the same replies every time that you start `support.ts`. To use a real model, replace `supportModel()` in `support.ts` with a model from your provider's package for the AI SDK, such as `openai('gpt-5')` from `@ai-sdk/openai`.

<Expandable title="the code for this brief">

Install the packages, then start `support.ts` with Node.js 24, which strips the types from a TypeScript file without a build step.

```bash pm
pnpm add -E @delali/sirannon-db better-sqlite3 ai zod
```

<CodeGroup defaultTab="support.ts">

```ts title="support.ts" package=sirannon
import { readdir } from 'node:fs/promises'
import { ToolLoopAgent } from 'ai'
import { CUSTOMER_ROOT, resetCustomerRoot, sirannon } from './memory-store.ts'
import { describeSavedFacts, memoryTools, recallAll } from './memory-tools.ts'
import { supportModel } from './mock-model.ts'

const INSTRUCTIONS = 'You help the customers of a furniture shop with their orders.'

resetCustomerRoot()

const converse = async (customerId: string, conversationId: string, message: string): Promise<string> => {
  const savedFacts = await recallAll(sirannon, customerId)
  const agent = new ToolLoopAgent({
    model: supportModel(),
    instructions: `${INSTRUCTIONS}\n\n${describeSavedFacts(savedFacts)}`,
    tools: memoryTools(sirannon, customerId, conversationId),
  })
  const reply = await agent.generate({ prompt: message })
  return reply.text
}

const mondayReply = await converse(
  'customer-1042',
  'conversation-3001',
  'Please deliver my sofa to 41 Kelvin Road, Glasgow G12 8QQ.'
)
const thursdayReply = await converse('customer-1042', 'conversation-3002', 'Where are you delivering my armchair?')
const anotherCustomersReply = await converse(
  'customer-2210',
  'conversation-3003',
  'Where are you delivering my armchair?'
)

console.log(
  JSON.stringify(
    {
      mondayReply,
      thursdayReply,
      anotherCustomersReply,
      customerFiles: (await readdir(CUSTOMER_ROOT)).filter((name) => name.endsWith('.db')).sort(),
    },
    null,
    2
  )
)

await sirannon.shutdown()
```

```json result open
{
  "mondayReply": "I have saved 41 Kelvin Road, Glasgow G12 8QQ as your delivery address.",
  "thursdayReply": "Your armchair goes to 41 Kelvin Road, Glasgow G12 8QQ, the address that you gave us.",
  "anotherCustomersReply": "I have no delivery address for you yet. Which address should we deliver to?",
  "customerFiles": [
    "customer-1042.db",
    "customer-2210.db"
  ]
}
```

```ts title="memory-store.ts"
import { mkdirSync, rmSync } from 'node:fs'
import { createTenantResolver, Sirannon } from '@delali/sirannon-db'
import { betterSqlite3 } from '@delali/sirannon-db/driver/better-sqlite3'

export const CUSTOMER_ROOT = './data/customers'

export const sirannon = new Sirannon({
  driver: betterSqlite3(),
  migrations: [
    {
      version: 1,
      name: 'fact',
      up: `CREATE TABLE fact (
        id INTEGER PRIMARY KEY,
        subject TEXT NOT NULL,
        value TEXT NOT NULL,
        source TEXT NOT NULL,
        learned_at INTEGER NOT NULL
      )`,
    },
  ],
  lifecycle: {
    autoOpen: { resolver: createTenantResolver({ basePath: CUSTOMER_ROOT }) },
  },
})

export const resetCustomerRoot = (): void => {
  rmSync(CUSTOMER_ROOT, { recursive: true, force: true })
  mkdirSync(CUSTOMER_ROOT, { recursive: true })
}
```

```ts title="memory-tools.ts"
import type { Database, Sirannon } from '@delali/sirannon-db'
import { tool } from 'ai'
import { z } from 'zod'

export interface SavedFact {
  subject: string
  value: string
}

const openCustomer = async (registry: Sirannon, customerId: string): Promise<Database> => {
  const db = await registry.resolve(customerId)
  if (!db) throw new Error(`The resolver returns no file for ${customerId}`)
  return db
}

export const remember = async (
  registry: Sirannon,
  customerId: string,
  conversationId: string,
  fact: SavedFact
): Promise<void> => {
  const db = await openCustomer(registry, customerId)
  await db.execute('INSERT INTO fact (subject, value, source, learned_at) VALUES (?, ?, ?, ?)', [
    fact.subject,
    fact.value,
    conversationId,
    Date.now(),
  ])
}

export const recallAll = async (registry: Sirannon, customerId: string): Promise<SavedFact[]> => {
  const db = await openCustomer(registry, customerId)
  return db.query<SavedFact>('SELECT subject, value FROM fact ORDER BY id')
}

export const describeSavedFacts = (facts: SavedFact[]): string => {
  if (facts.length === 0) return 'This customer has told you nothing in earlier conversations.'
  const lines = facts.map((fact) => `- ${fact.subject}: ${fact.value}`)
  return ['This customer has told you these facts in earlier conversations:', ...lines].join('\n')
}

export const memoryTools = (registry: Sirannon, customerId: string, conversationId: string) => ({
  remember: tool({
    description: 'Save a fact that the customer gives you, such as a delivery address, for later conversations.',
    inputSchema: z.object({ subject: z.string(), value: z.string() }),
    execute: async (fact: SavedFact): Promise<string> => {
      await remember(registry, customerId, conversationId, fact)
      return 'saved'
    },
  }),
})
```

```ts title="mock-model.ts"
import { MockLanguageModelV4 } from 'ai/test'

const NO_USAGE = {
  inputTokens: { total: 0, noCache: 0, cacheRead: undefined, cacheWrite: undefined },
  outputTokens: { total: 0, text: 0, reasoning: undefined },
}

const DELIVERY_REQUEST = /deliver my \w+ to (.+?)\.?$/i
const SAVED_ADDRESS = /^- delivery address: (.+)$/m

interface PromptPart {
  type?: string
  text?: string
}

interface PromptMessage {
  role: string
  content: string | PromptPart[]
}

const textOf = (message: PromptMessage | undefined): string => {
  if (message === undefined) return ''
  if (typeof message.content === 'string') return message.content
  return message.content.map((part) => part.text ?? '').join('')
}

const say = (text: string) => ({
  content: [{ type: 'text' as const, text }],
  finishReason: { unified: 'stop' as const, raw: undefined },
  usage: NO_USAGE,
  warnings: [],
})

const saveAddress = (address: string) => ({
  content: [
    {
      type: 'tool-call' as const,
      toolCallId: 'remember-1',
      toolName: 'remember',
      input: JSON.stringify({ subject: 'delivery address', value: address }),
    },
  ],
  finishReason: { unified: 'tool-calls' as const, raw: undefined },
  usage: NO_USAGE,
  warnings: [],
})

export const supportModel = () =>
  new MockLanguageModelV4({
    doGenerate: async ({ prompt }) => {
      const messages = prompt as PromptMessage[]
      const instructions = messages.filter((message) => message.role === 'system').map(textOf).join('\n')
      const question = textOf(messages.findLast((message) => message.role === 'user'))
      const hasSaved = messages.some((message) => message.role === 'tool')

      const request = question.match(DELIVERY_REQUEST)
      if (request) {
        return hasSaved ? say(`I have saved ${request[1]} as your delivery address.`) : saveAddress(request[1])
      }

      const saved = instructions.match(SAVED_ADDRESS)
      if (saved) return say(`Your armchair goes to ${saved[1]}, the address that you gave us.`)
      return say('I have no delivery address for you yet. Which address should we deliver to?')
    },
  })
```

</CodeGroup>

</Expandable>

## The address from the earlier chat appears in the new reply

Repeat the check from the start of this article with the same test customer. This time, you will see the address in the reply in the new chat.

Then open a chat as a second test customer and ask the same question. The reply will contain a question about the address, because your code stores no address for the second customer yet. If you see the first customer's address in the second customer's reply, your code loads facts from a store that contains the facts of both customers. In [Another Customer's Data Can Appear in Your Agent's Replies](/blog/agent-memory-other-customers-data), I will show you that failure and how you can prevent it.

## How other businesses can handle their returning customers

In the quiz below, you can test what you learn here on made-up cases from other businesses.

**Question 1.** What changes for returning customers?

At a shoe shop in Melbourne, returning customers give the AI agent their shoe size again in every chat. The team's only change is a move to a newer model with a context window twice as large. A context window is the most text that a model can receive in one request.

- A. The model receives the size from an earlier chat in a new chat
- B. Returning customers go on giving their shoe size in every chat
- C. The model receives the size for customers whose earlier chat is in the same week

**Answer:** B. Returning customers go on giving their shoe size in every chat

The newer model receives the same request as the old one, with the instructions and the current chat alone. The model will therefore generate the same reply as before, which is a question about the shoe size.

The other choices:

- A. The model receives the size from an earlier chat in a new chat: With a larger window, the model can receive more text in one request. However, the team's code puts only the current chat into that request, which means that the earlier size is missing from it.
- C. The model receives the size for customers whose earlier chat is in the same week: The model receives only what the team's code puts into each request, whatever the gap between two chats. Like a chat from last year, a chat from earlier in the same week is missing from the request.

**Question 2.** About how many tokens of earlier chats are in the first request of the next chat?

An online bookshop in Nairobi sends each customer's whole history with every request. One customer has 30 earlier chats of about 2,000 tokens each.

The answer lies between 0tokens and 150000tokens.

**Answer:** 60000tokens. An estimate within 2000tokens of the answer counts as correct.

The customer's 30 chats of about 2,000 tokens come to about 60,000 tokens, which the bookshop pays for on every request in the new chat. The bookshop's code then adds about 2,000 tokens to the history with each chat, whereas saved facts for the same customer will be only a few lines long.

**Question 3.** Where should the agent save that fact?

A guest tells a Lisbon hotel's AI agent that they can't eat gluten.

- A. In one notes table that the agent loads into every guest's chats
- B. In a store for that guest alone
- C. In the chat history, which the hotel's code sends with every later request

**Answer:** B. In a store for that guest alone

The hotel's code will load the fact only into the chats of that guest, including the first chat of their next stay.

The other choices:

- A. In one notes table that the agent loads into every guest's chats: The hotel's code will then load this guest's dietary need into the chats of every other guest as well.
- C. In the chat history, which the hotel's code sends with every later request: The model will then receive the fact as one line in a long history. That history will grow with every chat, which means that the hotel will pay for more of it on each request.

**Question 4.** What should provide the value of customerId?

A gym's AI agent in Manchester saves facts through a remember tool. In each tool call, the model generates values for customerId, subject, and value.

- A. The model, from what the member says in the chat
- B. The gym's code, from the signed-in session, with customerId removed from the values that the model generates
- C. The member, who types their membership number

**Answer:** B. The gym's code, from the signed-in session, with customerId removed from the values that the model generates

The gym's code can take the identifier from the session and pass it to the tool at the moment that the code creates the tool. The model will then provide only the subject and the value in its tool call.

The other choices:

- A. The model, from what the member says in the chat: A model can generate any identifier for customerId, including another member's identifier from a message in the chat.
- C. The member, who types their membership number: Anybody can type another member's number, whereas each signed-in session is for one member only.

**Question 5.** Put the steps of a returning customer's chat in order.

A pharmacy in Cape Town uses an AI agent for its prescription deliveries.

**Answer:** The steps happen in this order.

1. Take the customer's identifier from the signed-in session
2. Load that customer's saved facts
3. Add the facts to the model's instructions
4. Send the request with the customer's first message
5. Save each new fact from a call to the remember tool

The pharmacy's code can load the right customer's facts only after taking the identifier from the session. The code then adds those facts to the instructions before the first request so that the model receives them with the customer's first message. Later in the chat, whenever the customer gives a new fact, the model can generate a call to the remember tool, from which the pharmacy's code saves that fact.

## When a customer gives a new address

With saved facts, your code puts a returning customer's address into the request in every new chat. Suppose, however, that the customer moves house in November and gives the agent the new address. Your code will then save the new delivery address next to the old one in that customer's file. The two rows will have the same subject, while the table has no column that stores whether a row is replaced. The function that loads the customer's facts is `recallAll`. For the next request, it will return both addresses. In [Why Your Courier Can Deliver to a Customer's Old Address](/blog/agent-memory-changed-facts), I will show you how you can mark the old address as replaced.
