WEBVTT

00:00:08.030 --> 00:00:11.985
Do returning customers have to repeat themselves to your AI agent?

00:00:12.300 --> 00:00:16.425
This is the first of seven in Can You Trust Your Agent's Memory in

00:00:16.570 --> 00:00:17.465
Production?

00:00:17.550 --> 00:00:21.532
Written by Delali, and read by Metatron, his AI voice.

00:00:22.130 --> 00:00:27.050
Your returning customers can find themselves giving your AI agent the same details in

00:00:27.130 --> 00:00:28.650
every new chat.

00:00:28.770 --> 00:00:32.890
Twilio found this problem in a survey of consumers and businesses that it carried

00:00:32.970 --> 00:00:35.970
out in April and May 2026.

00:00:36.010 --> 00:00:41.610
As TechNode reports, 70% of the consumers in Asia-Pacific said that they 'often have

00:00:41.690 --> 00:00:45.930
to start new AI customer-service conversations from scratch'.

00:00:46.000 --> 00:00:50.330
The same share said that they had abandoned an AI customer-service chat because it

00:00:50.370 --> 00:00:54.410
'lacked basic information about them or previous interactions'.

00:00:54.490 --> 00:01:00.010
Yet 84% of the businesses in that region believed that their AI agents 'recognize

00:01:00.230 --> 00:01:02.157
returning customers and their history'.

00:01:02.920 --> 00:01:07.042
Suppose that a customer gives your agent a delivery address on Monday.

00:01:07.068 --> 00:01:10.535
When the customer opens a new chat on Thursday to ask where their armchair

00:01:10.615 --> 00:01:15.495
is going, the model behind your agent can generate the reply 'Which address should

00:01:15.535 --> 00:01:17.002
we deliver your armchair to?'

00:01:17.750 --> 00:01:21.950
Your database can store every chat that a customer has with your agent.

00:01:22.310 --> 00:01:26.670
However, the model behind your agent receives only what your code puts into each

00:01:26.750 --> 00:01:27.750
request.

00:01:27.790 --> 00:01:31.070
A request is the text that your code sends to the model for each

00:01:31.630 --> 00:01:32.070
reply.

00:01:32.110 --> 00:01:37.070
As a result, whichever model you choose receives Monday's address only if your code

00:01:37.150 --> 00:01:39.517
loads that address into Thursday's request.

00:01:40.580 --> 00:01:44.420
In other words, your agent has storage but no memory.

00:01:44.500 --> 00:01:48.420
Its storage is the database where your code saves every chat.

00:01:48.500 --> 00:01:52.500
Its memory is what your code loads from that database into the request for

00:01:52.580 --> 00:01:53.580
each new chat.

00:01:58.960 --> 00:02:02.291
Check whether a returning customer has to repeat themselves.

00:02:02.810 --> 00:02:05.770
Carry out this check on your agent as it is today.

00:02:05.960 --> 00:02:09.930
Use a test customer with no orders and no saved address.

00:02:10.140 --> 00:02:13.850
That way, any address in a later reply can only be one that the

00:02:13.940 --> 00:02:16.010
customer gives in an earlier chat.

00:02:16.730 --> 00:02:18.710
Picture the check as three steps.

00:02:19.070 --> 00:02:24.150
First, open a chat as the test customer, give the agent a delivery address,

00:02:24.270 --> 00:02:28.390
such as 41 Kelvin Road in Glasgow, and close the chat.

00:02:28.550 --> 00:02:33.350
Then open a new chat as the same customer and ask which delivery address

00:02:33.460 --> 00:02:34.750
the agent has for you.

00:02:34.960 --> 00:02:39.710
If the reply contains the address, the model receives the earlier detail, while a

00:02:39.750 --> 00:02:44.230
question about the address means that the model receives only the new chat and

00:02:44.270 --> 00:02:47.449
the fixed text that your code adds to every request.

00:02:52.780 --> 00:02:55.565
What does the model receive when a customer returns?

00:02:56.220 --> 00:03:00.580
Your agent's model generates each reply from the request that your code sends to

00:03:00.660 --> 00:03:00.900
it.

00:03:01.350 --> 00:03:05.100
Every request that your code sends starts with your instructions.

00:03:05.310 --> 00:03:10.260
Instructions are text such as 'You are the support agent of a furniture shop.'

00:03:10.600 --> 00:03:14.700
After the instructions, your code adds the messages in the current chat.

00:03:15.400 --> 00:03:19.050
Your code can also add a description of each tool to the request.

00:03:19.380 --> 00:03:22.890
A tool is a function in your code, such as a function that looks

00:03:22.970 --> 00:03:23.730
up an order.

00:03:23.970 --> 00:03:28.090
In place of a reply, the model can then generate a tool call.

00:03:28.140 --> 00:03:31.770
A tool call is a short text that contains the name of a tool

00:03:31.810 --> 00:03:34.010
and the values to pass to that tool.

00:03:34.090 --> 00:03:38.250
From that text, your code calls the tool with those values and adds the

00:03:38.330 --> 00:03:39.980
tool's result to the request.

00:03:40.630 --> 00:03:47.600
In its guide to conversation state, OpenAI describes each request as 'independent and stateless'.

00:03:47.600 --> 00:03:52.560
Stateless means that the model processes each request with only the text inside that

00:03:52.750 --> 00:03:53.440
request.

00:03:53.480 --> 00:03:57.600
The messages from earlier chats are therefore in a new request only when your

00:03:57.680 --> 00:03:58.750
code adds them.

00:03:59.460 --> 00:04:03.020
If you build your agent with an agent framework, look at what the sample

00:04:03.100 --> 00:04:05.900
code in its guide does when a chat starts.

00:04:05.980 --> 00:04:10.060
An agent framework is a library of code for building AI agents.

00:04:10.140 --> 00:04:15.340
The AI SDK from Vercel and LangGraph from the company LangChain are examples.

00:04:15.700 --> 00:04:19.820
In the guides to both frameworks, the sample code saves the messages of each

00:04:19.960 --> 00:04:21.820
chat under that chat's ID.

00:04:22.140 --> 00:04:25.740
A new chat has a new ID, which means that code built from those

00:04:25.820 --> 00:04:29.820
samples starts every new chat with an empty list of messages.

00:04:30.030 --> 00:04:34.380
The list is empty even when your database stores every earlier chat.

00:04:34.420 --> 00:04:39.260
In the AI SDK's guide to saving chat messages, for example, the sample code

00:04:39.340 --> 00:04:43.020
creates 'an empty chat file' for each new chat.

00:04:43.860 --> 00:04:48.970
In its guide to memory, LangChain calls the message history of the current conversation

00:04:48.970 --> 00:04:52.250
'short-term memory, or thread-scoped memory'.

00:04:52.250 --> 00:04:57.290
In that guide, a thread is a single conversation, which means that this history

00:04:57.320 --> 00:04:59.450
covers one chat only.

00:04:59.520 --> 00:05:04.170
For details that your code loads into every chat with a customer, LangChain offers

00:05:04.230 --> 00:05:05.770
a separate store.

00:05:05.830 --> 00:05:13.450
LangChain recommends the store for 'long-term, cross-thread memory, including user preferences, facts, and shared

00:05:13.510 --> 00:05:14.160
knowledge'.

00:05:14.890 --> 00:05:19.910
Whichever framework you use, your code has to put Monday's address into Thursday's request

00:05:20.080 --> 00:05:21.110
itself.

00:05:21.190 --> 00:05:25.110
Your code can load Monday's whole chat into the request again, which I will

00:05:25.190 --> 00:05:26.710
call replay.

00:05:27.070 --> 00:05:31.190
Alternatively, it can save the address as a fact about the customer and load

00:05:31.250 --> 00:05:32.890
only that fact.

00:05:33.670 --> 00:05:38.143
Replay and a saved fact also differ in what you pay your provider.

00:05:38.197 --> 00:05:42.570
Your provider is the company whose model you call, such as OpenAI.

00:05:42.650 --> 00:05:46.490
That company charges you for every token in each request.

00:05:46.630 --> 00:05:50.810
A token is the unit in which a model processes all text, such as

00:05:50.870 --> 00:05:52.900
a word or a part of a word.

00:05:54.310 --> 00:05:58.290
The illustration that comes next shows the request that the model receives when a

00:05:58.490 --> 00:06:03.010
returning customer asks where their armchair is going, along with the number of tokens

00:06:03.090 --> 00:06:04.490
in that request.

00:06:04.530 --> 00:06:08.370
It lets you choose what your code loads into the request, and it adds

00:06:08.450 --> 00:06:10.445
earlier chats as you move its slider.

00:06:11.710 --> 00:06:15.610
Picture that request as a short list of its parts, beside a meter that

00:06:15.730 --> 00:06:17.263
counts its tokens.

00:06:17.317 --> 00:06:23.370
When your code loads every earlier chat, each chat adds about 2,300 tokens, so

00:06:23.450 --> 00:06:26.050
the meter climbs with every chat.

00:06:26.090 --> 00:06:30.410
When your code loads saved facts, the request grows by one short line for

00:06:30.450 --> 00:06:33.357
each fact, however many chats the customer has.

00:06:38.710 --> 00:06:43.530
Why you pay more for worse replies when your code sends every earlier chat.

00:06:44.060 --> 00:06:49.050
With replay, your code loads every earlier chat into the request again.

00:06:49.170 --> 00:06:53.930
The request for the armchair question then contains the address, along with everything else

00:06:54.010 --> 00:06:56.170
from the customer's earlier chats.

00:06:56.250 --> 00:07:01.690
In the illustration, under the option called every earlier chat, each earlier chat is

00:07:01.890 --> 00:07:07.290
about 2,300 tokens long, whereas the address is a single line.

00:07:07.350 --> 00:07:11.770
That figure is my estimate from the size of the chats in LongMemEval, a

00:07:11.970 --> 00:07:13.650
test that I will describe next.

00:07:14.390 --> 00:07:18.750
A model's replies can also be less accurate when a request is long, for

00:07:19.030 --> 00:07:21.870
example when it contains many old chats.

00:07:21.960 --> 00:07:29.710
In October 2024, Di Wu and colleagues published LongMemEval, a test of 500 questions.

00:07:29.750 --> 00:07:33.763
The answer to each question is somewhere in a long chat history.

00:07:33.817 --> 00:07:37.110
The authors tested four long-context models on it.

00:07:37.150 --> 00:07:41.550
A long-context model can receive a long text, such as a whole chat history,

00:07:41.630 --> 00:07:43.110
in one request.

00:07:43.150 --> 00:07:48.910
In one setting, each model received a history of about 115,000 tokens, which is

00:07:48.990 --> 00:07:50.617
about 50 chats.

00:07:50.643 --> 00:07:55.203
In another, each model received only the chats that contained the answer.

00:07:55.257 --> 00:08:00.483
With the long history, the models scored between 30% and 60% lower.

00:08:00.537 --> 00:08:05.950
The authors add that performance is 'likely to further degrade as the interaction history

00:08:06.030 --> 00:08:06.960
expands'.

00:08:07.720 --> 00:08:11.850
With replay, your code adds a whole chat to the request each time that

00:08:11.930 --> 00:08:14.130
the customer chats with your agent.

00:08:14.170 --> 00:08:18.250
After about 50 chats, the request will be as long as the long history

00:08:18.320 --> 00:08:22.730
in that test, which means that your agent's replies can become less accurate in

00:08:22.810 --> 00:08:23.674
the same way.

00:08:24.450 --> 00:08:29.010
You also pay for the whole history on every request, even when your provider

00:08:29.090 --> 00:08:30.810
stores that history for you.

00:08:31.110 --> 00:08:35.890
With OpenAI, for example, your code can link each request to the one before

00:08:35.970 --> 00:08:36.410
it.

00:08:36.700 --> 00:08:40.930
To do so, your code sets the previous response ID, which is a value

00:08:40.970 --> 00:08:44.210
in the request, to the ID of the previous reply.

00:08:44.780 --> 00:08:48.770
OpenAI then sends the earlier messages to the model for you.

00:08:48.870 --> 00:08:54.610
In its guide, however, OpenAI states that 'all previous input tokens for responses in

00:08:54.690 --> 00:08:57.880
the chain are billed as input tokens in the API'.

00:08:58.630 --> 00:09:02.750
For the reply about the armchair, the model has to receive only one line

00:09:02.790 --> 00:09:05.630
of that history, which is the delivery address.

00:09:05.730 --> 00:09:09.390
Your code can save that line as a fact about the customer.

00:09:09.480 --> 00:09:13.790
At the start of every chat, your code then loads the customer's facts into

00:09:13.830 --> 00:09:15.150
the instructions.

00:09:15.270 --> 00:09:19.630
The request grows by one line for each new fact, however many chats the

00:09:19.830 --> 00:09:20.990
customer has.

00:09:21.060 --> 00:09:26.350
In the illustration, the option called saved facts shows how much smaller that request

00:09:26.430 --> 00:09:28.575
stays than the request with replay.

00:09:33.930 --> 00:09:37.600
Code that loads each customer's details into a new chat.

00:09:38.110 --> 00:09:42.830
A coding agent is an AI tool, such as Claude Code or Codex, that

00:09:42.910 --> 00:09:45.070
generates code in your project.

00:09:45.160 --> 00:09:49.230
A brief is a short description that you can paste into a coding agent

00:09:49.310 --> 00:09:51.870
so that it generates the code that you want.

00:09:51.960 --> 00:09:55.870
Copy the brief that comes next into your coding agent as it is.

00:09:55.940 --> 00:10:00.270
From the brief, your coding agent will generate the code that saves each customer's

00:10:00.350 --> 00:10:02.270
facts in your project's database.

00:10:03.010 --> 00:10:07.585
If your project has no database, your coding agent will install Sirannon, which is

00:10:07.665 --> 00:10:08.865
my database.

00:10:08.950 --> 00:10:14.385
Sirannon uses SQLite, a database engine that stores a whole database in a single

00:10:14.825 --> 00:10:15.318
file.

00:10:15.372 --> 00:10:20.105
To set up Sirannon, your coding agent will first install the Sirannon skill.

00:10:20.145 --> 00:10:24.465
A skill is a package of written steps and examples for one task, such

00:10:24.585 --> 00:10:26.185
as setting up Sirannon.

00:10:26.225 --> 00:10:29.825
Your coding agent will load the skill before it generates the code for that

00:10:30.345 --> 00:10:30.435
task.

00:10:31.200 --> 00:10:34.700
In the brief, you ask your coding agent to put the facts that each

00:10:34.780 --> 00:10:39.180
user gives in earlier chats into the model's instructions at the start of every

00:10:39.260 --> 00:10:40.420
new chat.

00:10:40.460 --> 00:10:45.447
Your code will save each fact in the project's database under the user's identifier,

00:10:45.473 --> 00:10:49.233
and it will take that identifier from the signed-in session alone.

00:10:49.287 --> 00:10:52.460
The model will also get a tool that saves a fact.

00:10:52.860 --> 00:10:56.540
Finally, you ask your coding agent to show you that the model receives a

00:10:56.620 --> 00:11:00.700
fact from one chat in the same user's next chat, and only in that

00:11:00.780 --> 00:11:01.840
user's requests.

00:11:02.620 --> 00:11:07.787
The code that follows is one correct result of this brief on Sirannon 0.4,

00:11:07.813 --> 00:11:10.520
for a project that has no database yet.

00:11:10.560 --> 00:11:14.760
This code stores each fact as a row in a table of the database.

00:11:14.800 --> 00:11:18.880
A row is one entry in that table, while a column is one part

00:11:18.960 --> 00:11:22.080
of every row, such as the value of the fact.

00:11:22.130 --> 00:11:24.609
The subject column is the key from the brief.

00:11:25.370 --> 00:11:29.990
Each customer has a separate database file in a folder of customer files.

00:11:30.320 --> 00:11:35.030
To find that file, Sirannon calls a resolver, which is a function that returns

00:11:35.110 --> 00:11:37.910
the path of the file for a customer's ID.

00:11:37.950 --> 00:11:43.350
The create tenant resolver function builds that resolver from the folder of customer files.

00:11:43.440 --> 00:11:47.990
In the support file, the converse function passes the same ID to the memory

00:11:48.070 --> 00:11:50.390
tools when it creates the tools.

00:11:50.470 --> 00:11:54.720
That is why the model's tool call contains only the subject and the value.

00:11:55.460 --> 00:11:59.700
In the mock model file, the support model function returns a test model from

00:11:59.780 --> 00:12:02.900
the AI SDK in place of a real model.

00:12:03.020 --> 00:12:07.460
That test model returns scripted replies so that you see the same replies every

00:12:07.510 --> 00:12:09.700
time that you start the support file.

00:12:09.790 --> 00:12:13.460
To use a real model, replace the support model with a model from your

00:12:13.660 --> 00:12:19.200
provider's package for the AI SDK, such as GPT-5 from the OpenAI package.

00:12:19.930 --> 00:12:23.355
The code for the brief comes in four files, which you can copy from

00:12:23.395 --> 00:12:24.515
the written version.

00:12:24.820 --> 00:12:29.995
When the main file runs, the customer's Monday address appears in the Thursday reply,

00:12:30.070 --> 00:12:33.575
while a second customer's reply asks which address to deliver to.

00:12:38.920 --> 00:12:42.110
The address from the earlier chat appears in the new reply.

00:12:42.610 --> 00:12:45.570
Repeat the check from the start with the same test customer.

00:12:46.060 --> 00:12:49.410
This time, you will see the address in the reply in the new chat.

00:12:50.200 --> 00:12:54.520
Then open a chat as a second test customer and ask the same question.

00:12:55.080 --> 00:12:59.240
The reply will contain a question about the address, because your code stores no

00:12:59.440 --> 00:13:01.080
address for the second customer yet.

00:13:01.590 --> 00:13:06.040
If you see the first customer's address in the second customer's reply, your code

00:13:06.120 --> 00:13:10.280
loads facts from a store that contains the facts of both customers.

00:13:10.360 --> 00:13:15.080
In Another Customer's Data Can Appear in Your Agent's Replies, I will show you

00:13:15.160 --> 00:13:17.378
that failure and how you can prevent it.

00:13:22.740 --> 00:13:26.012
How other businesses can handle their returning customers.

00:13:26.640 --> 00:13:30.310
The written version ends with a short quiz, in which you can test what

00:13:30.390 --> 00:13:33.565
you learn here on made-up cases from other businesses.

00:13:34.850 --> 00:13:40.090
The quiz takes five made-up businesses: a shoe shop in Melbourne, an online bookshop

00:13:40.130 --> 00:13:45.530
in Nairobi, a hotel in Lisbon, a gym in Manchester, and a pharmacy in

00:13:45.610 --> 00:13:46.250
Cape Town.

00:13:46.810 --> 00:13:51.210
Each one asks what happens to a returning customer, or where the agent should

00:13:51.290 --> 00:13:52.240
save a fact.

00:13:57.570 --> 00:13:59.890
When a customer gives a new address.

00:14:00.430 --> 00:14:05.300
With saved facts, your code puts a returning customer's address into the request in

00:14:05.380 --> 00:14:06.900
every new chat.

00:14:06.970 --> 00:14:11.540
Suppose, however, that the customer moves house in November and gives the agent the

00:14:11.700 --> 00:14:12.820
new address.

00:14:12.900 --> 00:14:16.740
Your code then saves the new delivery address next to the old one in

00:14:16.860 --> 00:14:18.420
that customer's file.

00:14:18.500 --> 00:14:22.500
The two rows have the same subject, while the table has no column that

00:14:22.580 --> 00:14:24.580
marks a row as replaced.

00:14:24.670 --> 00:14:28.660
The function that loads the customer's facts is called recall all.

00:14:28.920 --> 00:14:32.180
For the next request, it returns both addresses.

00:14:32.270 --> 00:14:36.580
In Why Your Courier Can Deliver to a Customer's Old Address, I will show

00:14:36.660 --> 00:14:39.493
you how you can mark the old address as replaced.
