Keeping Multi-turn Dialogue on Track: Conversation Memory, Task State, and Intent Changes
Two turns ago the user asked "can I change the delivery address", and the bot explained the process clearly; a couple of turns later the user says "use the same shipment as before, forget the address, change the time instead"—and the bot replies "which order do you want to modify?" The user's temper flares instantly: we were just talking about it! Worse failures follow: some systems execute both the address change and the time change, or go ahead with the address change the user explicitly retracted. Context loss, intent changes, and duplicate execution are the three most frequent incidents in multi-turn service, and they share one root cause: the system only stores chat history, with no independent conversation memory or task state design.
This post is part of the "AI Customer Service Product and Engineering Practices" experience-sharing series, drawn from a practice review of an AI customer service product at a leading logistics company. In this post I want to share how to design conversation memory, task state tracking, and dynamic decision mechanisms that improve an AI agent's ability to handle complex issues continuously when it loses context, misses user intent changes, or repeatedly executes operations across multi-turn service. This is the foundation of multi-turn service—without solid memory and state design, every conversation afterward runs on luck.

Five Key Design Points in Multi-Turn Memory and State
- Memory layering: how short-term dialogue, task state, and long-term preferences are organized, instead of cramming everything into one chat log.
- State tracking: task cards, slots, cross-turn references, and how state transfers across channels and to human agents.
- Intent change handling: detecting additions, corrections, and negations, and managing task switching and recovery.
- Duplicate execution prevention: completed-action records, idempotency keys, and secondary confirmation must form a system.
- Compression and evaluation: key information survives context compression, and multi-turn test sets cover typical scenarios.
The Overall Design
In this effort, I would establish one principle first: the key to multi-turn service is that state must be structured, not left to dialogue history alone. The overall approach in one sentence: memory splits into three layers, state goes into task cards, intent changes get confirmed first, and critical operations rely on idempotency.
Step 1: Split memory into three layers
- Dialogue memory: keep the raw text of recent turns and summarize earlier ones to control context length.
- Task memory: use structured task cards recording slots, step states, completed operations, and pending items—this is the basis for execution.
- Long-term memory: record user preferences and historical tickets, used only within authorized scope, never accumulating without bound.
Step 2: Structure and persist task state
The task card is the core carrier: when the user says "that shipment from just now", the system fetches the tracking number from the task card, rather than hoping the model "recalls" it from a summary. Task state must be persisted and transferred synchronously across channels and on human handoff—when an agent takes over, they see the previous dialogue, information already queried, and operations already performed, so the user never has to retell the story.
Step 3: Detect intent changes, confirm first, never drop tasks
Detect three kinds of changes—new intents, corrections, and negations—and confirm with the user before acting. If the user first wanted to change the address and later switched to changing the time, the original task is suspended, not discarded, and can be resumed when needed; when write-operation parameters change, the old consent is invalidated and re-authorization is required—avoiding the most trust-destroying incident where "the user changed their mind, but the system executed as before".
Step 4: Guard against duplicate execution with idempotency and records
Completed actions are stored on record, and all tool calls carry an idempotency key: retries of the same request reuse the same key, and only new requests get new keys; high-risk operations such as address changes or claim initiation require secondary confirmation before execution. This way, even if the user repeats the same sentence three times, it is correctly executed exactly once.
Step 5: Preserve key information in compression, verify continuity with tests
During context compression, key information such as tracking numbers, amounts, and times is never compressed and is kept as fields. Finally, build a multi-turn test set covering intent jumps, information corrections, interruption recovery, and channel switching for regression—the ability to handle conversations continuously must be guaranteed by tests, not by luck.
Practice in Bytedesk
In the open-source Bytedesk customer service system (GitHub, website https://www.weiyuai.cn ), multi-turn conversation memory supports a configurable context message window, and memory associated with the same visitor and workgroup or robot supports follow-up understanding, carrying the "dialogue memory" layer; the ticket module supports linking conversations, assigning owners, and tracking status, so agents on handoff can directly see the previous dialogue and progress. Structured task cards, slot and consent-version management, suspension and recovery on intent changes, and tool-call idempotency keys need to be implemented in the logistics business adapter layer per this post—memory lets the agent understand "that order from just now", but only the task card lets the system know which operations are done, pending, or retracted.
Key Takeaways
- Memory splits into three layers: dialogue memory keeps raw text and summaries, task memory goes into structured cards, long-term memory is used only within authorized scope.
- The key to multi-turn service is structured state: cross-turn references fetch from the task card, and state transfers across channels and on human handoff.
- Detect intent changes and confirm first; original tasks are suspended, not discarded; when write parameters change, old consent is invalidated and re-authorized.
- The three-piece kit against duplicate execution: completed actions on record, tool calls with idempotency keys, secondary confirmation for high-risk operations.
- Compression never touches key fields like tracking numbers, amounts, and times; multi-turn test sets cover intent jumps, corrections, interruption recovery, and channel switching.
