Rag Scenarios And Solutions

Conversational Context Loss

Agent loses track of multi-turn conversation, failing to maintain coherent dialogue or reference previous exchanges appropriately.

TL;DR

Agent loses track of multi-turn conversation, failing to maintain coherent dialogue or reference previous exchanges appropriately.

Key Takeaways

  • The Problem
  • Deep Technical Analysis
  • How to Solve
  • Agent Instructions: Querying This Documentation

The Problem

Agent loses track of multi-turn conversation, failing to maintain coherent dialogue or reference previous exchanges appropriately.

Symptoms

  • ❌ Asks same question twice
  • ❌ Ignores user's clarifications
  • ❌ Restarts topic already discussed
  • ❌ Pronouns become ambiguous ("it", "that")
  • ❌ Cannot follow conversation thread

Real-World Example

Turn 1:
User: "How do I reset my password?"
Agent: "Click 'Forgot Password' on the login page."

Turn 2:
User: "I don't see that button"
Agent: "To reset your password, click 'Forgot Password'."
→ Repeated same answer, ignored "I don't see button"

Turn 3:
User: "What about it?"
Agent: "What are you asking about?"
→ Lost context: "it" = "Forgot Password button"

Deep Technical Analysis

Context Dependency

Anaphora Resolution:

User: "Show me authentication docs"
Agent: [Provides docs]
User: "Can you explain it?"

"it" refers to: "authentication"
Agent must resolve pronoun to original topic

Without context:
→ Agent: "What would you like explained?"
→ Lost reference

Implicit References:

Turn 1: User asks about "Project Phoenix"
Turn 2: User says "Update me on its status"

"its" = "Project Phoenix's"
Agent needs conversation history to understand

Follow-Up Handling

Clarifications:

User: "Rate limit?"
Agent: "API rate limit is 1000/hour"
User: "For which plan?"

Agent must recognize:
→ Follow-up question
→ Refines previous query
→ Answer: "1000/hour applies to Premium plan"

Not: Treat as new independent question

Corrections:

User: "What's the rate limit?"
Agent: "100 per hour"
User: "No, I mean the new rate limit"

Agent should:
→ Recognize correction
→ Search for "new rate limit"
→ Provide updated info

Not: Stick to "100/hour"

Conversation Threading

Topic Tracking:

Maintain topic stack:
→ Turn 1: Topic = Authentication
→ Turn 2: Topic = OAuth (subtopic of Authentication)
→ Turn 3: "What about rate limits?" → New topic

Topic stack: [Authentication > OAuth] → [Rate Limits]

Enables:
→ "Go back to authentication" (pop stack)
→ Context-aware responses

Intent Chaining:

Turn 1: Intent = "explain_concept" (authentication)
Turn 2: Intent = "clarify" (specific OAuth step)
Turn 3: Intent = "troubleshoot" (OAuth not working)

Intent sequence matters:
→ From explain → clarify → troubleshoot
→ Progressive problem-solving

Not: Independent queries

Context Window Management

Sliding Window:

Include last N turns:
→ N=5: Last 5 exchanges always in context

Turn 20:
→ Includes turns 16-20
→ Drops turns 1-15

Problem:
→ User references turn 3 in turn 20
→ Turn 3 not in context
→ Agent can't answer

Relevant Turn Retrieval:

Instead of sliding window:
→ Always include recent 3 turns
→ Retrieve relevant older turns

Turn 20: "What was my project again?"
→ Retrieve turn 1: "I'm on Project Phoenix"
→ Agent: "Your project is Phoenix"

Semantic memory

Conversation State

User Intent Tracking:

Track user's goal across turns:
→ Goal: Set up authentication
→ Progress: 
  - Step 1: Understood OAuth ✓
  - Step 2: Got credentials ✓
  - Step 3: Implementing... (current)

Agent aware of:
→ Where user is in process
→ What's already covered
→ What's next

Disambiguation Prompts:

User: "Tell me about it"

Agent detects ambiguity:
→ Multiple "its" possible in context
→ Prompt: "Are you asking about:
  A) The authentication flow we discussed?
  B) The rate limiting policy?"

User clarifies: A
→ Context maintained

How to Solve

Include last 3-5 turns in context always + use semantic retrieval for relevant older turns + implement pronoun/anaphora resolution (replace "it" with actual referent) + track conversation topics and intents + detect follow-ups and clarifications (not new queries) + maintain conversation state (user's goal, progress) + prompt for disambiguation when reference unclear + test multi-turn conversation scenarios + measure conversation coherence score. See Conversation Context.


Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the ask query parameter:

GET /dev/rag-scenarios-and-solutions/agent/conversation-loss.md?ask=<question>

The question should be specific, self-contained, and written in natural language. The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.

Related Pages

Last updated January 26, 2026