Why AI Customer Service Forgets in Long Conversations? Four Context Engineering Practices
Every AI customer service deployment has a signature moment of failure: at turn 25 the user says "remember the order number I just gave you," and the bot answers off-topic — or worse, resurrects the old order number the user corrected back at turn 3. To the user, the bot "has amnesia." Inside the system, the real cause is usually one of two things: too much context stuffed in, diluting the key facts — or compression applied too aggressively, deleting them outright.
This post is part of the "AI Customer Service Product and Engineering Practices" experience-sharing series for product managers and developers. The material comes from a front-line team's retrospective, and the core question is single: in long conversations, how should context be organized so the model remembers and the cost stays down? The answer condenses into four practices: fix the order, compress history, use the cache, and pin the state.
Practice 1: Fix the order first — stable content up front, volatile content at the end
Every call to the LLM is really the assembly of one context: system prompt, tool definitions, customer profile, retrieval results, conversation history, current question. These components change at completely different frequencies, and their order should follow stability:
System prompt → Tool definitions → Customer profile → Retrieved docs → History → Current question
(most stable ·················································→ changes every turn)
Ordering is not a detail — it drives two things at once:
- Quality: with stable components up front, the model's attention is not scattered by constantly changing content, and instruction-following stays solid.
- Cost: a stable prefix at the front is the prerequisite for hitting provider prompt caching; once the order drifts, the cache value drops to zero (Practice 3 expands on this).
The worst pattern is "assemble as you think of it": retrieval results prepended this turn, user profile wedged into the middle next turn — model behavior wobbles, and the bill climbs along with it.
Practice 2: Don't stuff everything in — summary plus the last 5 turns
The most common long-conversation mistake is feeding the model the entire raw history. One team's retrospective found they had been stuffing in 15 to 100 turns of history — paying every single turn for stale dialogue that had long lost its value, while the context the model actually needed was quite limited.
A saner structure has two layers:
- History layer: early dialogue compressed into a summary that keeps only facts and conclusions (who the user is, what was done, how it ended).
- Recent layer: roughly the last 5 turns kept verbatim — language continuity and references ("do it like we just discussed") live here.
Why 5 turns and not 50? Because the vast majority of coreference and tone continuity happens within the last few turns; as long as earlier information is present in summary form, the model won't "forget." The number isn't sacred — tune it against your own traffic — but full-history stuffing is almost always wrong: it hurts accuracy (noise dilutes key facts) and cost (tokens balloon linearly) at the same time.
Practice 3: Save money with caching — a stable prefix is an asset; don't dirty it casually
Major LLM providers offer prompt caching: parts of the request prefix that match a previous request can be billed at cache rates, with substantial discounts. Three rules make the cache actually hit:
- ✓ Keep the stable opening fixed at the very front: near-constant content like system prompts and tool definitions must stay byte-for-byte stable in both text and assembly order.
- ✓ Never put changing content in the opening: current time, live inventory, this turn's retrieval results — all of it goes after the prefix.
- ✗ Be careful with timestamps: inserting "current time: hh:mm:ss" into the system prompt looks thoughtful, but it punctures the cache every minute, and cache hit rates fall off a cliff.
One misconception deserves a separate warning: cache optimization and knowledge base maintenance are two different things. Knowledge governance answers "is the retrieved content correct"; cache optimization answers "can repeated prefixes be reused cheaply." The former tunes the retrieval pipeline; the latter tunes assembly order and stability discipline. Don't manage both with one plan.
Practice 4: Pin the key facts — session state stored separately, injected every turn
The first three practices are about saving and stabilizing; this one is about not forgetting. Key business facts such as order numbers, membership IDs, and confirmed delivery addresses must not live only in conversation history — the moment history is compressed or summarized, they are the first things to be dropped.
The right approach is to store them separately as structured session state:
{
"orderId": "SO-2026-1120-8867",
"issue": "refund only",
"confirmedAt": "2026-11-08T15:42:00+08:00"
}
Then inject it verbatim into every turn's context assembly, with one iron rule: compression never deletes state. The effect is direct: the user gives an order number once at turn 2, and at turn 22 asks "how is it going?" — the model still gets it right.
This echoes an architectural principle this series keeps returning to — decouple raw dialogue text from structured state: the raw text lets the model understand tone and context, and can be compressed or summarized; the state carries business facts and must stay exact and present every turn. A system that keeps order numbers only inside chat logs gets more dangerous the longer the conversation runs.
The four practices together
| Practice | Problem it solves | Key action |
|---|---|---|
| Fix the order | Unstable instructions, cache misses | Stable up front, volatile at the end |
| Compress history | Token cost inflation, diluted key facts | Summary + last 5 turns verbatim |
| Use the cache | Paying repeatedly for the same prefix | Byte-stable prefix, no variables inside |
| Pin the state | Key facts lost to compression | Independent session state, injected every turn |
These aren't isolated tricks but one interlocking context engineering system: ordering determines whether the cache hits, compression shapes the cost curve, and state injection sets the floor for long-conversation quality. Each practice pays off alone; together, long conversations finally become both accurate and affordable.
How This Maps to Bytedesk
The Bytedesk open-source customer service system (GitHub, website) fits this playbook naturally: conversations and messages are fully persisted, supporting the "summary + last N turns" layered assembly; visitor profiles and thread records form the customer profile and long-term memory; in the AI Agent's multi-turn dialogue and tool-calling pipeline, the assembly order of system prompt, tool definitions, retrieval results, and history is controllable and tunable, making it easy to keep a stable prefix and hit prompt caching; key slots like order numbers can live in independent session state management, kept verbatim when history is compressed. The Spring AI-based access layer also lets caching strategies switch across model providers as needed.
Summary
- Order: system prompt → tool definitions → customer profile → retrieval results → history → current question; stable content first.
- Compression: history becomes a summary, last 5 turns stay verbatim; stuffing 15 to 100 turns is the most common waste.
- Cache: keep the stable opening byte-identical and put variables after it; a single timestamp can puncture the entire cache.
- State: key facts like order numbers stored independently, injected every turn, never deleted by compression.
- One sentence: long-conversation capability is designed, not piled up with tokens.
