Your customers can give your AI agent a new address and then find the old one in a later reply. That can happen when your code saves the new address next to the old one and sends both to the model. In this article, I will show you how you can check your agent for that, and how you can brief your coding agent to generate code that marks the old address as replaced.
Audio and video play straight from the show's own hosting. PodSubs stores and serves no media.
Chapters
Opening
Check whether your agent provides the old value after the customer changes it
Your code can send both addresses to the model in every later chat
Is overwriting the old row enough?
How your code can mark the old row as replaced
From a short description to the change in your project
Repeating the check after your change
Other facts that customers change
When the new value is wrong
Transcript
From the show. Tap a time to play from there.
Why your courier can deliver to a customer's old address. This is the second of seven in Can You Trust Your Agent's Memory in Production? Written by Delali, and read by Metatron, his AI voice. Your customers can give your AI agent a new delivery address and then find the old one in a later reply. Suppose that a customer gives your agent an address in Glasgow in October. In November, the customer moves to Brighton and gives your agent the new address. When the customer asks in December where their armchair is going, the model behind
your agent can generate a reply with the Glasgow address. If your agent has a tool that books deliveries, the model can also pass the Glasgow address to that tool. In Do Returning Customers Have to Repeat Themselves to Your AI Agent?, the code gives the model a remember tool that stores each fact as a row in the customer's file, which is a separate database file for each customer. Each row has a subject, such as 'delivery address', and a value, such as the Glasgow address. When the customer gives the Brighton address, the code adds a second row with
the same subject, after which it loads both rows into every request. Because the code marks neither row as the current one, the model can generate a reply with either address. The LangChain team warns about the same failure in its guide to memory. For an agent that saves each memory as a separate item, the team writes that 'The model must now delete or update existing items in the list, which can be tricky', and that 'some models may default to over-inserting'.
Check whether your agent provides the old value after the customer changes it. Carry out this check on your agent as it is today. Use a test customer for whom your code stores nothing so that every value in a later reply comes from an earlier chat. Picture the check as four steps. As the test customer, give the agent a delivery address in one chat, such as 41 Kelvin Road in Glasgow, and a new address in a second chat, such as 9 Marine Parade in Brighton.
In a third chat, ask which delivery address the agent has for you. If the reply contains the old address, or both addresses, your code puts the old address into the request. Finally, look at the rows that your database stores for that fact, because a reply with only the new address can come from a request that contains both. Your code can send both addresses to the model in every later chat. On Sirannon 0.4.2, which is my database, the code with that remember tool puts
two lines at the end of the instructions for the third chat of the check. Each line starts with the subject delivery address. The first line gives 41 Kelvin Road in Glasgow, while the second gives 9 Marine Parade in Brighton. Both lines have the same subject and no date. The order of the lines is the only clue to which address is current, which means that the model can generate a reply with the Glasgow address in one chat and with the Brighton address in the next. Chat products with memory can provide wrong answers about a changed fact as well.
In August 2024, the authors of LongMemEval tested ChatGPT and Coze, two chat products that saved facts about their users at that time. With GPT-4o as the model in both, the testers marked 83.3% of ChatGPT's answers as right on the questions about a detail that changed in an earlier chat, against 20.8% of Coze's answers. Since both products used the same model, the difference came from the memory of each product.
The illustration that comes next lets you choose what your code does when a customer gives a new address, and its slider changes how many times the customer moves. Picture the customer's file beside the request for the armchair question. When your code adds a row for each new address, both the file and the request gain a row with every move, and the reply gives the Glasgow address. When your code overwrites the row, the file and the request contain only the newest address. A third choice marks each old row as replaced, so that the file contains
every address while the request contains only the newest. Is overwriting the old row enough? When your code overwrites the row, the model generates a reply with the right address, because the file contains only one address. However, the remember tool stores whatever value the model passes to it. Since the model generates that value from the customer's words, it can generate a wrong one.
Suppose that the customer writes 'Please send this one gift to my sister at 27 Elm Grove, Cardiff CF24 3RB.' The model can pass the sister's address to the tool as the new delivery address, at which point your code replaces the Brighton address with the Cardiff one. Your code will then load the Cardiff address into every later request, until the customer notices the mistake and gives the Brighton address again. In the same guide, the LangChain team writes that other models 'may default to
over-updating'. The LongMemEval authors also report that ChatGPT 'tended to overwrite crucial information as the chat continues'. To guard against this, have your code mark the old row as replaced in place of overwriting it. After a wrong save, your code can then make the Brighton row the current one again. You will also need the old rows when a customer complains, as in 'I gave you my new address on 20 November. Why is my armchair going to Glasgow?' Each row that this code saves contains the time of the save and the
ID of the chat in which the customer gave the fact. While the replaced rows remain in the file, you can find which address your code loaded on any past date, and in which chat the customer changed it. After an overwrite, however, your code stores only today's address. How your code can mark the old row as replaced. Add a superseded by column to the table of facts, under the same name as in Sirannon's guide to memory and forgetting.
In each old row, that column will contain the ID of the row that replaces it. To save a new value, have your code add the new row first, then write the new row's ID into the superseded by column of every other current row with the same subject. When your code loads facts, have it load only the rows whose superseded by column is empty. The customer's file will then contain the replaced rows as well, while the request will contain only the current one. In the illustration, the option called marks the old row as replaced shows each
replaced row with the ID of the row that replaces it. Make both writes in one transaction so that a failure between them leaves the old address as the current one. Your code finds the old row by its subject, which comes from the model's tool call. Suppose that the model generates 'home address' as the subject of the Brighton address. The Glasgow row under 'delivery address' will then remain a current row as well. To prevent that, give the tool a fixed list of subjects, in which 'delivery
address' is the only subject for an address. From a short description to the change in your project. Paste the brief that comes next into your coding agent as it is. From it, your coding agent can generate code with the same design for every kind of fact that your AI agent saves, in whichever database your AI agent uses. The brief asks your coding agent to put only the new value of a saved fact into later requests, and to record the earlier values as replaced.
Under the brief, every fact takes a subject from a fixed list, each save marks the current value as replaced in the same transaction, and the code loads only current values. Finally, the brief asks your coding agent to show you that the next request contains only the new value, while the store contains the old one, marked as replaced. The code that follows is one correct result of the brief on Sirannon 0.4, for a project whose saved facts already use the subjects in the list.
A new migration adds the superseded by column and marks the older rows of each subject as replaced. The remember function makes both writes, while recall current takes the place of recall all. In the mock model file, the support model function returns the scripted replies from the first fix in place of a real model so that you see the same replies every time that you start the support file. The code for the brief comes in four files, which you can copy from the written version. When the main file runs, the customer gives the Glasgow address in one chat,
the Brighton address in the next, and then asks where the armchair is going. In the output, the instructions for the armchair chat contain only the Brighton address, while the stored rows include the Glasgow row as well, marked as replaced by row 2. Repeating the check after your change. Repeat the check from the start with a new test customer. This time, the reply in the third chat will contain the new value, while
your database contains the old value as well, marked as replaced. The rows that your code saves before the change can contain two values of one fact for the same customer as well. To test that case, give a second test customer an old value and a new value before you put the change live. After the change, repeat the third step as that customer. The reply will contain the newer value, because the new migration marks every value of a subject except the newest as replaced.
Other facts that customers change. The written version ends with a short quiz, in which you can try the same design on the facts that other businesses save about their customers. The quiz takes five made-up businesses: a florist in Auckland, a bakery in Accra, a bank in Kuala Lumpur, a gym in Vienna, and a pharmacy in Montreal. Each one asks what the business's code saves, loads, or can restore after a customer changes a fact.
When the new value is wrong. Your code marks the old row as replaced even when the new value is wrong. Suppose that the model sends the Brighton address to a postcode lookup tool that returns the wrong street. If the model then passes that street to remember, your code will save it as the newest delivery address and mark the Brighton row as replaced. From that save onwards, it will load the wrong street into every chat. Your code can make the Brighton row current again to repair that one fact.
Before anyone notices the wrong street, however, the model can include it in replies and in more tool calls, which are wrong whether or not you repair the fact. In One Wrong Tool Result Is Enough to Corrupt Later Replies, I will show you how you can undo a wrong value along with everything that the model generates from it.
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...
Every fact that your AI agent saves about a customer can go out of date, appear in another customer's chat, or remain in a backup after you delete the customer's data. In this study, I will show you how you can check...