posted an update —

Sahayak Multi-Turn Conversation Mode

Overview

Sahayak now supports multi-turn conversations. Instead of treating every query as an isolated question, the system detects follow-ups, expands ambiguous references using conversation context, and generates responses that build naturally on previous exchanges.

Before (Single-Shot)

User: "Can police search my phone without a warrant?"
→ Full response about phone search laws

User: "What if they say it's urgent?"
→ Confused response — doesn't know what "they" or "it" refers to

After (Multi-Turn)

User: "Can police search my phone without a warrant?"
→ Full response about phone search laws

User: "What if they say it's urgent?"
→ FOLLOW-UP detected
→ Rewritten: "Can police search a phone without a warrant in urgent situations?"
→ Context-aware response building on the previous answer

Architecture

Pipeline Flow

User Query
  ↓
Step 0: Query Intent Gate (LLM classification)
  ├─ "greeting" → friendly intro response
  ├─ "off-topic" → polite redirect
  └─ "legal" → continue pipeline
  ↓
Step 1: Normalize query text
  ↓
Step 2: Conversation Context
  ├─ Sanitize history (max 8 turns, 3000 chars/turn)
  ├─ Classify intent (follow-up vs new-topic vs clarification)
  └─ Rewrite query if follow-up (LLM-powered expansion)
  ↓
Step 3: Extract entities (from rewritten query)
  ↓
Step 4: Resolve jurisdiction
  ↓
Step 5: Retrieve sources (using rewritten query for better results)
  ↓
Step 6: Generate response
  ├─ Single-shot: llm.generate() (no history)
  └─ Multi-turn: llm.generateWithMessages() (with history)
  ↓
Step 7: Verify citations + guardrails (independent per response)
  ↓
Response (with isFollowUp flag + rewrittenQuery if applicable)

Log in or sign up for Devpost to join the conversation.