Multi-Turn Followup Capabilities
This document outlines the system's capabilities for handling multi-turn conversations, ensuring context is preserved, switched, or recovered intelligently across user interactions.
Overview
The system supports 8 core scenarios designed to handle natural conversation flows, from simple "show more" requests to complex context switching and reference resolution.
Visualizing the Flow
Context Preservation & Refinement
This flowchart illustrates how the system maintains context when a user asks for more results or refines their search (e.g., adding a budget).
Context Switching (Anti-Poisoning)
The system detects when a user wants to change topics completely, preventing old context (like "books") from polluting a new search (like "toys").
Core Capabilities
1. Context Preservation ("Show More")
Goal: Keep the current search active while fetching more results or applying minor filters.
| Capability | Example | Behavior |
|---|---|---|
| Preserve Type | "Show more" | Keeps showing the same product type (e.g., grills). |
| Preserve Category | "More please" | Maintains the current category context. |
| Add Budget | "Under 30 euros" | Applies budget limit to the existing search. |
2. Progressive Context Building
Goal: Allow users to build a complex query step-by-step.
Example Flow:
- "Gift ideas" (Generic)
- "For mom" (+Recipient)
- "She likes gardening" (+Hobby)
- "Under 50 euros" (+Budget)
Result: A search for "Gardening gifts for mom under 50€".
3. Anti-Poisoning (Clean Pivots)
Goal: Detect when the user changes their mind and wants to start over.
- Triggers: "Instead...", "Actually...", "I want X instead".
- Action: The system clears
product_type,category, and other specific constraints to avoid "leaking" old context into the new search.
4. Agile Context Switching
Goal: Support rapid switching between topics and returning to previous ones.
- Switch: "Actually, show me books." (Switches to Books)
- Switch Back: "Back to the games." (Restores Games context)
5. Reference Resolution
Goal: Understand pronouns and references to authors or products.
Supported Patterns:
- Pronouns: "his works", "from this author", "it", "that one".
- Ordinals: "the first one", "the second product".
- Implicit: "How much is it?" (Refers to the last shown product).
- Mixed Intent: "Is this suitable for an 8-year-old?" (Pronoun + age context).
Ordinal and pronoun detection uses regex-based patterns for Estonian language, running at PRIORITY -2 (earliest) in the routing pipeline. This ensures ~2ms detection instead of LLM latency. See Product Inquiry Detection for implementation details.
6. Budget Management
Goal: Flexibly handle budget constraints.
- Add: "Under 20 euros"
- Modify: "Actually up to 50"
- Remove: "Price doesn't matter"
7. Constraint Overrides
Goal: Handle negative constraints (exclusions).
- Exclude: "Not books"
- Re-include: "Actually books are okay"
8. Mixed Intent Recovery
Goal: Handle questions in the middle of a search flow without losing the search context.
- Search: "Show me games."
- Question: "Is this one suitable for 5 year olds?" (Context preserved)
- Resume: "Show more." (Resumes game search)
Technical Implementation
The context is managed via lastSearchParams, which persists critical fields across turns:
queryForSearch: The base query.product_type/csv_category: Core classification.budget:{ min, max }.recipient/ageGroup: Gift context.isContextSwitch: Flag to indicate a hard reset.
Related Files
- Test Suite:
qa-surface/test-multi-turn-followups.ts - Types:
app/api/chat/types/index.ts(ChatRequest.lastSearchParams) - Show More Utils:
app/api/chat/utils/show-more.ts(LastSearchParams) - Parallel Orchestrator:
app/api/chat/orchestrators/parallel-orchestrator.ts(metadata construction) - Context Types:
app/api/chat/context/types.ts(GiftContext) - Product Inquiry Detection:
app/api/chat/orchestrators/context-orchestrator/llm-query-router.ts
Related Documentation
- Product Inquiry Detection - Ordinal/pronoun detection implementation
- Intent Classification - Dual-path intent detection
- Followup Router Prompt - Semantic reasoning prompt for followup classification