Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 5 min read

The order number was in the chat. The agent still forgot it.

The order number was in the chat. The agent still forgot it. Pine, the support agent at a made-up outdoor gear shop, handles a long chat about a damaged tent. Message 3: the customer verifies identity and gives order 7

The order number was in the chat. The agent still forgot it.

Pine, the support agent at a made-up outdoor gear shop, handles a long chat about a damaged tent. Message 3: the customer verifies identity and gives order 73921. Message 41: Pine asks for both again. The customer repeats them, then writes: "Forget it."

Message 52, another day: Pine offers a $700 refund limit from an earlier case in the same long thread. This case's limit is $500. Nothing was deleted. The facts were still in the history, just no longer in focus.

Nadia Okafor, head of support, counts 214 such chats a month. At a made-up $6 per repeat contact, rework alone costs about $1,284, before lost trust. The agent did not lose the order number, it stopped noticing it.

The middle of a long chat is where facts go to die

Claude sees only the messages you send in one request: its whole memory. As the chat grows, early facts compete with many later messages for attention, facts in the middle get the weakest attention, a pattern called lost in the middle, and at the limit old messages may be cut to make room, gone for real.

Think of a long meeting. You recall the first point and the last point well. Point 17 blurs. The model has the same shape of memory, except worse: a person can check their notes, and a person knows a number mattered. The model has no notes except what you send, and it does not know which old number you will need later. Repeating a fact once does not fix it.

"Fits the window, so it is remembered" is the trap. Presence is not focus. The order number was in the chat, and Pine still asked for it again.

The fix: a case file card pinned to the top of the desk

Your app keeps one short block per case, rewritten after each turn from tool results and confirmed decisions. Each new request sends the system prompt and tools, then the pinned case summary near the start in a fixed shape, then the recent messages, not the full transcript.

The picture is a case file card pinned to the top of a messy desk. The desk can fill up, the card stays in sight.

The summary is not a prose recap. Fixed fields keep the facts that matter present and easy to check, and tool results, not model guesses, fill money and identity fields. For Pine's tent case the block holds: customer ID, identity verified at message 3 by the customer lookup tool, order 73921, a 3-person tent paid $429, a pole snapped on first use, a replacement pole offered and a refund chosen, refund agreed $429, auto refund limit for this case $500, refund not yet issued, do-not-ask-again: identity, order number.

Pin what would hurt to lose

Pin everything and the summary becomes a second transcript. Pin too little and the bug returns. The rule of thumb: if losing the fact changes money, identity, safety or a promise, pin it. If it only changes tone, let it scroll.

Pin verified identity and customer ID: re-asking breaks trust and flow. Pin the order number, item and amounts paid: money decisions depend on exact numbers. Pin decisions made and promised actions, to stop repeat questions and contradictions. Pin the policy limit for this case, to stop limits leaking in from other cases. Let greetings, small talk, dead ends and old explanations scroll away.

Two rules keep the card honest. One summary per case, because threads hold many cases and mixing them leaks limits and amounts across cases. That is how Pine offered $700 on a $500 case. Never copy a limit or amount from another case, and never ask the model to recall a total. For money, read the pinned field or call the tool again. Recall is a guess.

As the chat grows past a set size, summarize and carry forward: fold older turns into the summary, keep recent turns raw, store the full transcript outside the prompt for audit, and load the summary first on resume.

The same 60 messages, costed two ways

The summary wins on focus first and cost second. The chapter's worked example runs one support case of 60 messages, with made-up prices of $3 per million input tokens and $15 per million output tokens.

Raw history at turn 60: the full transcript is 60 messages at about 300 tokens each, 18,000 tokens, plus system and tools at 1,500, so input per call is about 19,500 tokens. The order number sits at message 3, deep in the middle of what follows. Present, and weak.

Summary plus recent at turn 60: the case summary is about 250 tokens, the recent 8 messages 2,400, plus system and tools 1,500, so input per call is about 4,150 tokens. The saving per call is 15,350 tokens, about 79 percent less input. Cost per call falls from about $0.0585 to about $0.0125. Over 1,000 long chats a month, that gap is about $46 saved. The real win is not the $46, it is that identity, order and limit arrive pinned on every call.

Duplication is not a fix. Sending the whole transcript twice pays twice for the same clutter, and the middle facts are still in the middle. A short summary near the start is cheaper and puts the facts in focus.

What this looks like in real teams

Long-running support and coding tools commonly carry a compact state block forward instead of replaying everything. The pattern is the same everywhere: the app owns memory, the model owns the next reply.

If losing a fact would change money, identity or a promise, your app pins it in the summary and re-sends it every turn, in the same place and shape. Never leave it to model recall. The order number was in the chat, and the agent still forgot it. The fix is not a bigger window. It is a card that never leaves the top of the desk.

The full interactive chapter is free at https://deployedlab.dev/lessons/cca-22-conversation-context, with a hands-on lab where you write Pine's case summary block and test your pin choices. 79 chapters are free with no signup, and the full bundle is $5 a month or $39 a year at deployedlab.dev.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.