Skip to main content

Multi-Intent Dialogue State Management: Task Stack, Context Isolation, and Idempotent Orchestration

· 5 min read
Jack Ning
Maintainer of Bytedesk

In one IM session a user says three things: "change my address to my office," "where is my order," and "I want a refund on that previous order." Many customer service systems fall apart right here: querying order A's status but applying it to order B, submitting the refund twice, or completely forgetting the address change when the user circles back.

This is the fifth article in an experience-sharing series on "AI customer service product and engineering practice," drawn from hands-on practice as an AI Product Manager focused on IM intelligent customer service at a local-life services platform. In this post I want to share how to design multi-turn dialogue state management, task switching, and tool orchestration when a user raises multiple requests in IM—order modification, delivery progress query, refund application—and the Agent must call different business systems, avoiding context confusion, duplicate execution, and task interruption.

This is where task-oriented Agents most often fail—single-task demos flow smoothly; concurrent tasks reveal the truth.

Illustration: Task stacks and context switching under concurrent intents

Three Key Points in Multi-Intent State Design​

  1. Dialogue state machine design under concurrent tasks—splitting "one blob of conversation" into "multiple task instances."
  2. A task stack, context isolation, and recovery mechanism so tasks are never lost and parameters never cross-contaminate.
  3. Idempotency and consistency in tool orchestration—the engineering bottom line against duplicate execution and financial loss.

Overall Approach​

The core design is a trio: "task stack + context isolation + idempotent orchestration."

Step 1: Session State Design — the Task Stack​

Maintain a "task stack" per session: each independent request is a task instance containing the task type, confirmed slots, execution progress, and associated order. The active task sits on top of the stack; others are suspended but their state is preserved.

When a user raises three requests, the system does not mash everything into one context—it creates three independent task instances, each bound to its own order and slots.

Step 2: Task Recognition and Switching​

Classify intent on every turn to determine ownership:

  • Belongs to the current task (slot filling) → continue;
  • Belongs to a new task → push onto the stack and switch, explicitly telling the user: "I've noted your refund request; let me check the delivery progress first."

When the old task finishes, proactively prompt to resume: "The refund has been submitted—shall we continue with the address change?" Avoiding forgotten tasks is the most overlooked part of the experience. Users should never have to remember "something is still unfinished" themselves.

Step 3: Context Isolation​

Each task instance holds independent slots and its own order ID; global context (user identity, default address) is separated from task context.

This is the key to avoiding "context confusion": it prevents task A's parameters from contaminating task B. Without isolation, the office address confirmed during the address-change task could easily be misused by the refund task as the delivery address for validation.

Step 4: Tool Orchestration — Explicit Workflows with Idempotency Keys​

For multi-tool calls within one task, use an explicit workflow (DAG) rather than free-form decisions: dependent steps run serially, independent ones in parallel.

Every tool call carries an idempotency key, so retries produce no duplicate side effects. When resuming an interrupted task, query the tool side's actual execution state before continuing—check whether the refund was really submitted, then decide to retry or proceed, avoiding double submission.

What to Watch After Launch​

Track three categories of bad cases:

  • Parameter cross-wiring: order A's parameters applied to order B—isolation failed;
  • Duplicate execution: the same operation ran twice—idempotency failed;
  • Lost tasks: the user asks "what about that thing I mentioned?" and the system has no memory—task stack design failed.

These three directly reflect state-management quality and localize problems better than aggregate completion rates.

Practice in Weiyu​

Weiyu, the open-source AI customer service system (GitHub, website), provides the state foundation at the session level: the thread and message models naturally isolate context across topics; the AI Agent supports multi-turn dialogue with context memory, and full conversation context transfers at human handoff; the ticket module provides independent ticket instances with their own workflow states—the concrete form of "task instances." For complex concurrency scenarios, task-stack semantics can be extended on top of tickets and the task state machine, while idempotency keys should be implemented at the business tool integration layer.

Takeaways​

  • The fundamental abstraction for concurrent requests is the task stack: one request, one task instance—active on top, suspended below.
  • Task switching must be explicitly communicated to the user, with proactive reminders to resume—no "forgotten requests."
  • Context isolation prevents cross-wiring: global context separate from task context, each task holding its own slots.
  • Orchestration uses explicit DAGs + idempotency keys; on recovery, check business-side actual state before resuming.
  • Parameter cross-wiring, duplicate execution, and lost tasks are the three direct signals of state-management quality.