HinterBuild logoHinterBuild
AI Systems · 10 min read

Evaluating Multi-Turn Conversations

Learn evaluating multi-turn conversations through concrete architecture trade-offs, failure modes, rollout controls, and production measurement practices.

Muhammad Abdul Sami, author

Muhammad Abdul Sami

· 10 min read

  • RAG
  • Embeddings
  • Vector Databases
  • Evaluation

Table of Contents:

Why Multi-Turn Evaluation Matters

Short answer: Multi-turn conversation evaluation tests whether AI agents maintain context, coherence, and task progress across multiple dialogue exchanges — critical for customer support, sales, and any conversational application.

After building conversational AI systems at HinterBuild, the pattern is consistent: 70% of production failures occur in multi-turn contexts that single-turn tests miss. An agent might answer isolated questions perfectly but fail to track conversation state, contradict previous statements, or lose task progress after 3-4 turns.

Key Takeaways:

  • Multi-turn tests catch context tracking failures single-turn tests miss
  • Session-level metrics measure task completion, not just answer quality
  • Context window management becomes critical after 5+ turns
  • Dialogue coherence requires checking consistency across entire conversation
  • Production monitoring must track full conversation sessions, not isolated turns
  • Common failure: agent forgets critical information from turns 3-5 back

A healthcare chatbot passed all single-turn tests with 98% accuracy. In production, users complained it "forgot" symptoms they mentioned earlier. Multi-turn evaluation revealed: after 4 turns, the agent retained only the last 2 turns of context. Critical medical information from turn 2 was lost by turn 6. Single-turn eval gave false confidence.

This guide covers multi-turn conversation evaluation: test case design, context tracking metrics, session-based testing, coherence measurement, and production monitoring patterns.


Multi-Turn Test Case Design

Design test conversations that mirror real user behavior.

Multi-Turn Test Case Structure

python
from dataclasses import dataclass
from typing import List, Optional, Dict

@dataclass
class Turn:
    """Single turn in conversation"""
    user_message: str
    expected_intent: Optional[str] = None  # e.g., "gather_info", "provide_answer"
    expected_entities: Optional[Dict[str, str]] = None  # Entities to extract
    expected_response_contains: Optional[List[str]] = None  # Key phrases
    expected_response_excludes: Optional[List[str]] = None  # Should NOT mention
    expected_tool_calls: Optional[List[str]] = None  # Tools to call
    context_requirements: Optional[List[str]] = None  # Info from previous turns needed

@dataclass
class MultiTurnTestCase:
    """Complete multi-turn conversation test"""
    id: str
    description: str
    category: str
    turns: List[Turn]
    session_goal: str  # What should be accomplished by end
    success_criteria: List[str]  # How to measure success
    priority: str = "medium"  # critical, high, medium, low
    tags: List[str] = None

# Example: Customer support conversation
test_case = MultiTurnTestCase(
    id="refund_multi_turn_01",
    description="Customer requests refund with multiple clarifications",
    category="customer_support",
    session_goal="Determine refund eligibility and process refund",
    success_criteria=[
        "Collects order ID",
        "Verifies purchase date within 30 days",
        "Confirms item condition",
        "Processes refund or explains rejection"
    ],
    turns=[
        Turn(
            user_message="I want to return an item",
            expected_intent="gather_info",
            expected_response_contains=["order number", "order ID"],
            context_requirements=[]
        ),
        Turn(
            user_message="My order number is ORD-12345",
            expected_intent="gather_info",
            expected_entities={"order_id": "ORD-12345"},
            expected_response_contains=["purchase date", "when did you buy"],
            context_requirements=["order_id from turn 2"]
        ),
        Turn(
            user_message="I bought it last week",
            expected_intent="verify_eligibility",
            expected_tool_calls=["check_purchase_date"],
            expected_response_contains=["refund approved", "process"],
            context_requirements=["order_id", "approximate purchase timeframe"]
        ),
        Turn(
            user_message="Is the item unopened?",
            expected_response_contains=["yes", "unopened"],
            context_requirements=["order_id", "refund approval mentioned"]
        ),
        Turn(
            user_message="Yes, completely unopened",
            expected_intent="process_refund",
            expected_tool_calls=["initiate_refund"],
            expected_response_contains=["refund", "processed", "5-7 business days"],
            context_requirements=["all previous context"]
        )
    ],
    priority="high",
    tags=["refund", "multi_turn", "happy_path"]
)

Test Case Categories

1. Happy Path Dialogues — Expected conversation flow 2. Clarification Sequences — User provides incomplete info, agent asks follow-ups 3. Context Switches — User changes topic mid-conversation 4. Correction Scenarios — User corrects previous statements 5. Interruption Patterns — User asks tangential questions 6. Long Conversations — 10+ turns to test context window limits 7. Failure Recovery — Agent makes mistake, user points it out


Context Tracking Evaluation

Test whether agent remembers information from earlier turns.

Context Retention Test

python
class ContextTrackingEvaluator:
    """Evaluate context retention across turns"""
    
    def evaluate_context_retention(
        self,
        conversation_history: List[Dict[str, str]],
        current_response: str,
        required_context: List[str]
    ) -> Dict[str, any]:
        """
        Check if agent uses required context from earlier turns
        
        Args:
            conversation_history: Previous turns
            current_response: Agent's current response
            required_context: List of info that should be remembered
            
        Returns:
            context_retention_score, missing_context, evidence
        """
        retained_count = 0
        missing = []
        evidence = {}
        
        for context_item in required_context:
            # Check if context item is used or referenced in response
            if self._context_present_in_response(context_item, current_response, conversation_history):
                retained_count += 1
                evidence[context_item] = "present"
            else:
                missing.append(context_item)
                evidence[context_item] = "missing"
        
        score = retained_count / len(required_context) if required_context else 1.0
        
        return {
            'context_retention_score': score,
            'retained_count': retained_count,
            'total_required': len(required_context),
            'missing_context': missing,
            'evidence': evidence
        }
    
    def _context_present_in_response(
        self,
        context_item: str,
        response: str,
        history: List[Dict]
    ) -> bool:
        """Check if context item is reflected in response"""
        
        # Use LLM to judge if context is present
        prompt = f"""Check if the following context from earlier in the conversation is used or acknowledged in the current response.

Context item: {context_item}

Conversation history:
{self._format_history(history)}

Current response: {response}

Is the context item used, referenced, or acknowledged in the current response?
Answer YES or NO.

Answer:"""
        
        llm_response = self.llm.generate(prompt, temperature=0.0)
        return "YES" in llm_response.upper()
    
    def _format_history(self, history: List[Dict]) -> str:
        """Format conversation history for prompt"""
        return "\n".join([
            f"Turn {i+1} - User: {turn['user']}\nAgent: {turn['agent']}"
            for i, turn in enumerate(history)
        ])

Entity Tracking Test

python
def test_entity_tracking(
    conversation: List[Dict],
    tracked_entities: Dict[str, List[str]]  # entity_type -> [values mentioned]
) -> Dict[str, any]:
    """
    Verify agent tracks entities throughout conversation
    
    Example:
        tracked_entities = {
            'order_id': ['ORD-12345'],
            'customer_name': ['John Smith'],
            'product': ['Blue Widget']
        }
    """
    
    errors = []
    
    for i, turn in enumerate(conversation):
        response = turn['agent_response']
        
        # Check for entity confusion
        for entity_type, values in tracked_entities.items():
            # Find all mentions of this entity type in response
            mentioned_values = extract_entities(response, entity_type)
            
            # Check if agent uses correct values
            for mentioned in mentioned_values:
                if mentioned not in values:
                    errors.append({
                        'turn': i + 1,
                        'error_type': 'incorrect_entity',
                        'entity_type': entity_type,
                        'expected': values,
                        'actual': mentioned
                    })
    
    return {
        'entity_tracking_score': 1.0 - (len(errors) / max(len(conversation), 1)),
        'errors': errors
    }

Dialogue Coherence Metrics

Measure conversation quality beyond individual turns.

Coherence Metrics

python
class DialogueCoherenceEvaluator:
    """Evaluate multi-turn dialogue coherence"""
    
    def evaluate_coherence(
        self,
        conversation: List[Dict[str, str]]
    ) -> Dict[str, float]:
        """
        Comprehensive dialogue coherence evaluation
        
        Measures:
        - Topical consistency
        - Contradiction detection
        - Response relevance
        - Progression towards goal
        """
        
        return {
            'topical_consistency': self._measure_topic_consistency(conversation),
            'contradiction_score': self._detect_contradictions(conversation),
            'relevance_score': self._measure_relevance(conversation),
            'goal_progression': self._measure_goal_progression(conversation)
        }
    
    def _measure_topic_consistency(
        self,
        conversation: List[Dict]
    ) -> float:
        """Check if conversation stays on topic"""
        
        # Get conversation topic from first few turns
        topic = self._extract_topic(conversation[:3])
        
        # Check if later turns stay on topic
        on_topic_count = 0
        
        for turn in conversation[3:]:
            if self._is_on_topic(turn, topic):
                on_topic_count += 1
        
        if len(conversation) <= 3:
            return 1.0
        
        return on_topic_count / (len(conversation) - 3)
    
    def _detect_contradictions(
        self,
        conversation: List[Dict]
    ) -> float:
        """
        Detect if agent contradicts itself
        
        Returns: Score where 1.0 = no contradictions, 0.0 = many contradictions
        """
        
        agent_statements = [turn['agent'] for turn in conversation]
        
        contradictions = 0
        total_pairs = 0
        
        # Check each pair of statements
        for i in range(len(agent_statements)):
            for j in range(i+1, len(agent_statements)):
                total_pairs += 1
                
                if self._statements_contradict(agent_statements[i], agent_statements[j]):
                    contradictions += 1
        
        if total_pairs == 0:
            return 1.0
        
        return 1.0 - (contradictions / total_pairs)
    
    def _statements_contradict(self, statement1: str, statement2: str) -> bool:
        """Check if two statements contradict each other"""
        
        prompt = f"""Do these two statements contradict each other?

Statement 1: {statement1}

Statement 2: {statement2}

Answer YES if they contradict, NO if they're consistent or unrelated.

Answer:"""
        
        response = self.llm.generate(prompt, temperature=0.0)
        return "YES" in response.upper()
    
    def _measure_relevance(self, conversation: List[Dict]) -> float:
        """Check if each agent response is relevant to user's message"""
        
        relevance_scores = []
        
        for turn in conversation:
            score = self._turn_relevance(turn['user'], turn['agent'])
            relevance_scores.append(score)
        
        return sum(relevance_scores) / len(relevance_scores) if relevance_scores else 0.0
    
    def _turn_relevance(self, user_message: str, agent_response: str) -> float:
        """Score relevance of response to user message"""
        
        prompt = f"""Rate how relevant this response is to the user's message.

User: {user_message}

Agent: {agent_response}

Rate relevance from 0-10:
- 10: Perfectly addresses the user's message
- 7-9: Mostly relevant with minor issues
- 4-6: Partially relevant
- 0-3: Off-topic or misses the point

Score:"""
        
        response = self.llm.generate(prompt, temperature=0.0)
        
        try:
            score = float(response.strip()) / 10.0
            return min(max(score, 0.0), 1.0)
        except:
            return 0.5  # Default if parsing fails
    
    def _measure_goal_progression(self, conversation: List[Dict]) -> float:
        """Measure if conversation progresses towards goal"""
        
        # This requires knowing the conversation goal
        # For now, check if agent is gathering info and moving forward
        
        goal_progress = []
        
        for i, turn in enumerate(conversation):
            if i == 0:
                goal_progress.append(0.0)
                continue
            
            # Check if this turn made progress
            progress = self._turn_made_progress(
                conversation[:i+1],
                turn
            )
            goal_progress.append(progress)
        
        # Average progress rate
        return sum(goal_progress) / len(goal_progress) if goal_progress else 0.0
    
    def _turn_made_progress(
        self,
        history: List[Dict],
        current_turn: Dict
    ) -> float:
        """Check if current turn made progress towards goal"""
        
        # Did agent gather new information?
        # Did agent take an action?
        # Did agent provide a resolution?
        
        response = current_turn['agent']
        
        progress_indicators = [
            "order number" in response.lower() and "order_id" not in str(history[:-1]).lower(),
            "process" in response.lower() or "complete" in response.lower(),
            "?" in response  # Agent asking clarifying question
        ]
        
        return sum(progress_indicators) / 3.0

Session-Based Testing Framework

Execute multi-turn tests against conversational agents.

Session Test Runner

python
class MultiTurnTestRunner:
    """Execute multi-turn conversation tests"""
    
    def __init__(self, agent: ConversationalAgent):
        self.agent = agent
        self.coherence_evaluator = DialogueCoherenceEvaluator()
        self.context_evaluator = ContextTrackingEvaluator()
    
    def run_test(self, test_case: MultiTurnTestCase) -> Dict[str, any]:
        """Execute multi-turn test case"""
        
        session_id = generate_session_id()
        conversation_history = []
        turn_results = []
        
        # Execute each turn
        for i, turn in enumerate(test_case.turns):
            turn_result = self._execute_turn(
                turn=turn,
                turn_number=i + 1,
                session_id=session_id,
                conversation_history=conversation_history
            )
            
            turn_results.append(turn_result)
            
            # Update history
            conversation_history.append({
                'user': turn.user_message,
                'agent': turn_result['response']
            })
        
        # Evaluate session-level metrics
        session_metrics = self._evaluate_session(
            test_case=test_case,
            conversation_history=conversation_history,
            turn_results=turn_results
        )
        
        return {
            'test_id': test_case.id,
            'session_id': session_id,
            'passed': session_metrics['session_passed'],
            'turn_results': turn_results,
            'session_metrics': session_metrics,
            'conversation_history': conversation_history
        }
    
    def _execute_turn(
        self,
        turn: Turn,
        turn_number: int,
        session_id: str,
        conversation_history: List[Dict]
    ) -> Dict[str, any]:
        """Execute single turn and evaluate"""
        
        # Generate response
        response = self.agent.generate_response(
            user_message=turn.user_message,
            session_id=session_id,
            conversation_history=conversation_history
        )
        
        # Evaluate turn
        turn_passed = True
        failures = []
        
        # Check expected content
        if turn.expected_response_contains:
            for expected in turn.expected_response_contains:
                if expected.lower() not in response.lower():
                    turn_passed = False
                    failures.append(f"Missing expected phrase: '{expected}'")
        
        # Check excluded content
        if turn.expected_response_excludes:
            for excluded in turn.expected_response_excludes:
                if excluded.lower() in response.lower():
                    turn_passed = False
                    failures.append(f"Contains forbidden phrase: '{excluded}'")
        
        # Check context requirements
        if turn.context_requirements:
            context_result = self.context_evaluator.evaluate_context_retention(
                conversation_history=conversation_history,
                current_response=response,
                required_context=turn.context_requirements
            )
            
            if context_result['context_retention_score'] < 1.0:
                turn_passed = False
                failures.append(f"Missing context: {context_result['missing_context']}")
        
        # Check tool calls
        if turn.expected_tool_calls:
            actual_tool_calls = response.metadata.get('tool_calls', [])
            for expected_tool in turn.expected_tool_calls:
                if expected_tool not in [tc['name'] for tc in actual_tool_calls]:
                    turn_passed = False
                    failures.append(f"Did not call tool: {expected_tool}")
        
        return {
            'turn_number': turn_number,
            'response': response,
            'passed': turn_passed,
            'failures': failures
        }
    
    def _evaluate_session(
        self,
        test_case: MultiTurnTestCase,
        conversation_history: List[Dict],
        turn_results: List[Dict]
    ) -> Dict[str, any]:
        """Evaluate overall session quality"""
        
        # Turn-level pass rate
        turns_passed = sum(1 for r in turn_results if r['passed'])
        turn_pass_rate = turns_passed / len(turn_results) if turn_results else 0.0
        
        # Coherence metrics
        coherence_metrics = self.coherence_evaluator.evaluate_coherence(conversation_history)
        
        # Check success criteria
        success_criteria_met = self._check_success_criteria(
            test_case.success_criteria,
            conversation_history
        )
        
        # Overall session pass
        session_passed = (
            turn_pass_rate >= 0.9 and  # At least 90% of turns passed
            coherence_metrics['contradiction_score'] >= 0.95 and  # No contradictions
            sum(success_criteria_met.values()) / len(success_criteria_met) >= 0.9  # 90% of criteria met
        )
        
        return {
            'session_passed': session_passed,
            'turn_pass_rate': turn_pass_rate,
            'coherence_metrics': coherence_metrics,
            'success_criteria_met': success_criteria_met,
            'num_turns': len(conversation_history)
        }
    
    def _check_success_criteria(
        self,
        criteria: List[str],
        conversation: List[Dict]
    ) -> Dict[str, bool]:
        """Check if session success criteria were met"""
        
        conversation_text = " ".join([
            f"{t['user']} {t['agent']}" for t in conversation
        ])
        
        results = {}
        for criterion in criteria:
            # Use LLM to judge if criterion was met
            met = self._criterion_met(criterion, conversation_text)
            results[criterion] = met
        
        return results
    
    def _criterion_met(self, criterion: str, conversation_text: str) -> bool:
        """Check if single success criterion was met"""
        
        prompt = f"""Was the following goal accomplished in this conversation?

Goal: {criterion}

Conversation:
{conversation_text}

Answer YES if the goal was accomplished, NO otherwise.

Answer:"""
        
        response = self.llm.generate(prompt, temperature=0.0)
        return "YES" in response.upper()

Turn-Level vs Session-Level Metrics

Different metrics for different granularity.

Turn-Level Metrics

Measure individual turn quality:

  • Response relevance — Does response address user's message?
  • Context retention — Does response use info from earlier turns?
  • Expected content — Contains required phrases/info?
  • Tool calling accuracy — Calls correct tools with right args?

Session-Level Metrics

Measure entire conversation:

  • Task completion rate — Did conversation achieve goal?
  • Turn efficiency — How many turns to complete task?
  • Coherence score — No contradictions, stays on topic?
  • User satisfaction proxy — Would user be satisfied?

Metric Aggregation

python
def aggregate_multi_turn_metrics(
    turn_results: List[Dict],
    session_metrics: Dict
) -> Dict[str, float]:
    """Aggregate turn and session metrics"""
    
    return {
        # Turn-level aggregates
        'avg_turn_relevance': np.mean([r['relevance_score'] for r in turn_results]),
        'avg_context_retention': np.mean([r['context_retention'] for r in turn_results]),
        'turn_pass_rate': sum(1 for r in turn_results if r['passed']) / len(turn_results),
        
        # Session-level
        'task_completion': session_metrics['task_completed'],
        'dialogue_coherence': session_metrics['coherence_metrics']['topical_consistency'],
        'contradiction_score': session_metrics['coherence_metrics']['contradiction_score'],
        'turn_efficiency': session_metrics['num_turns_to_completion'] / session_metrics['expected_turns'],
        
        # Combined
        'overall_score': compute_overall_score(turn_results, session_metrics)
    }

def compute_overall_score(turn_results: List[Dict], session_metrics: Dict) -> float:
    """Weighted combination of turn and session metrics"""
    
    turn_score = sum(1 for r in turn_results if r['passed']) / len(turn_results)
    session_score = (
        session_metrics['task_completed'] +
        session_metrics['coherence_metrics']['topical_consistency'] +
        session_metrics['coherence_metrics']['contradiction_score']
    ) / 3.0
    
    # Weight session metrics higher (task completion matters more than individual turns)
    return 0.4 * turn_score + 0.6 * session_score

Production Conversation Monitoring

Monitor multi-turn conversations in production.

Session Tracking

python
class ConversationSessionTracker:
    """Track and evaluate production conversations"""
    
    def __init__(self):
        self.active_sessions = {}
        self.completed_sessions = []
    
    def log_turn(
        self,
        session_id: str,
        user_message: str,
        agent_response: str,
        timestamp: float
    ):
        """Log conversation turn"""
        
        if session_id not in self.active_sessions:
            self.active_sessions[session_id] = {
                'session_id': session_id,
                'start_time': timestamp,
                'turns': []
            }
        
        self.active_sessions[session_id]['turns'].append({
            'timestamp': timestamp,
            'user': user_message,
            'agent': agent_response
        })
    
    def end_session(self, session_id: str, outcome: str):
        """Mark session as complete and evaluate"""
        
        if session_id not in self.active_sessions:
            return
        
        session = self.active_sessions[session_id]
        session['outcome'] = outcome  # 'success', 'failure', 'abandoned'
        session['end_time'] = time.time()
        session['duration'] = session['end_time'] - session['start_time']
        session['num_turns'] = len(session['turns'])
        
        # Evaluate session
        session['metrics'] = self._evaluate_session(session)
        
        # Move to completed
        self.completed_sessions.append(session)
        del self.active_sessions[session_id]
        
        # Alert if poor quality
        if session['metrics']['overall_score'] < 0.7:
            alert(f"Low quality conversation in session {session_id}")
    
    def _evaluate_session(self, session: Dict) -> Dict:
        """Evaluate completed session"""
        
        conversation = session['turns']
        
        # Coherence
        coherence_evaluator = DialogueCoherenceEvaluator()
        coherence = coherence_evaluator.evaluate_coherence(conversation)
        
        # Context retention (check if last turn uses context from earlier)
        if len(conversation) >= 3:
            context_eval = ContextTrackingEvaluator()
            # Extract key info from early turns
            early_context = extract_key_info(conversation[:2])
            context_retention = context_eval.evaluate_context_retention(
                conversation_history=conversation[:-1],
                current_response=conversation[-1]['agent'],
                required_context=early_context
            )
        else:
            context_retention = {'context_retention_score': 1.0}
        
        return {
            'coherence': coherence,
            'context_retention': context_retention['context_retention_score'],
            'num_turns': session['num_turns'],
            'duration': session['duration'],
            'overall_score': (coherence['topical_consistency'] + context_retention['context_retention_score']) / 2.0
        }
    
    def get_session_statistics(self, last_n_sessions: int = 100) -> Dict:
        """Get aggregate statistics from recent sessions"""
        
        recent = self.completed_sessions[-last_n_sessions:]
        
        return {
            'avg_turns_per_session': np.mean([s['num_turns'] for s in recent]),
            'avg_duration_seconds': np.mean([s['duration'] for s in recent]),
            'avg_coherence': np.mean([s['metrics']['coherence']['topical_consistency'] for s in recent]),
            'avg_context_retention': np.mean([s['metrics']['context_retention'] for s in recent]),
            'success_rate': sum(1 for s in recent if s['outcome'] == 'success') / len(recent),
            'abandonment_rate': sum(1 for s in recent if s['outcome'] == 'abandoned') / len(recent)
        }

For more production monitoring patterns, see Observability & Monitoring.


Common Failure Patterns

Recognize and fix multi-turn failure modes.

Failure Pattern 1: Context Decay

Symptom: Agent forgets information after N turns

Example:

  • Turn 1: User gives order ID "ORD-12345"
  • Turn 5: Agent asks "What is your order ID?"

Root cause: Context window limit or poor prompt engineering

Fix:

python
# Maintain explicit state tracker
class ConversationState:
    def __init__(self):
        self.entities = {}
        self.facts = []
    
    def add_entity(self, entity_type: str, value: str):
        self.entities[entity_type] = value
    
    def get_entity(self, entity_type: str):
        return self.entities.get(entity_type)

# In prompt:
prompt = f"""Conversation state:
{json.dumps(conversation_state.entities)}

User: {user_message}

Response:"""

Failure Pattern 2: Contradiction

Symptom: Agent makes conflicting statements

Example:

  • Turn 3: "Your refund will be processed in 5-7 days"
  • Turn 6: "Refunds typically take 10-14 days"

Root cause: No consistency checking

Fix: Add contradiction detection in post-processing

Failure Pattern 3: Goal Drift

Symptom: Conversation loses track of original goal

Example:

  • Turn 1: User wants refund
  • Turn 4: Agent discussing product features
  • Turn 7: Original goal forgotten

Fix: Track conversation goal explicitly

python
class GoalTracker:
    def __init__(self, initial_goal: str):
        self.goal = initial_goal
        self.goal_progress = 0.0
    
    def check_turn_relevance(self, agent_response: str) -> bool:
        """Check if turn progresses goal"""
        # Use LLM to judge
        return True  # Implementation

Optimization Strategies

Improve multi-turn evaluation efficiency.

Strategy 1: Progressive Evaluation

Don't evaluate full session if early turns fail:

python
def run_test_with_early_exit(test_case: MultiTurnTestCase) -> Dict:
    """Exit early if critical turns fail"""
    
    for i, turn in enumerate(test_case.turns):
        result = execute_turn(turn)
        
        # Early exit on critical failure
        if turn.priority == "critical" and not result['passed']:
            return {
                'passed': False,
                'failed_at_turn': i + 1,
                'reason': 'Critical turn failed',
                'full_run': False
            }
    
    # All turns passed
    return evaluate_full_session(test_case)

Strategy 2: Parallel Session Testing

Run multiple conversations in parallel:

python
from concurrent.futures import ThreadPoolExecutor

def run_multi_turn_tests_parallel(
    test_cases: List[MultiTurnTestCase],
    max_workers: int = 10
) -> List[Dict]:
    """Run multi-turn tests in parallel"""
    
    with ThreadPoolExecutor(max_workers=max_workers) as executor:
        futures = [executor.submit(run_test, tc) for tc in test_cases]
        results = [f.result() for f in futures]
    
    return results

Primary references: official documentation, official documentation, official documentation, official documentation.

Evaluating Multi-Turn Conversations Decision Table

DecisionPrefer the simpler path whenAdd operational complexity when
ArchitectureOne component can own the contract and stateIndependent scaling or fault isolation is required
RolloutOffline replay covers the meaningful casesLive behavior requires shadow traffic and a canary
RecoveryA failed operation is safe to repeatPartial effects require idempotency or reconciliation
MeasurementOne service objective represents user impactQuality, latency, and cost need separate gates

Operating Evaluating Multi-Turn Conversations as a System

The implementation is only one part of Evaluating Multi-Turn Conversations. A production design also needs an explicit contract for inputs, outputs, ownership, and failure behavior. Write that contract before selecting a library. It should identify which component validates input, where state lives, what may be retried, and which result is authoritative when two components disagree. This prevents a convenient prototype boundary from silently becoming the long-term architecture.

Start with a representative baseline. Capture request shape, traffic distribution, dependency latency, error classes, and the quality signal users actually care about. Averages hide the cases that cause incidents, so keep percentiles and segment measurements by workload type. Record the configuration and dataset version beside every result. Without that context, a faster or more accurate run cannot be reproduced and should not be used to approve a rollout.

Define the failure model

List failures by where they originate: invalid input, capacity exhaustion, dependency timeout, partial state change, malformed output, and semantically wrong output. Each class needs a different response. Validation errors should fail immediately. Transient dependency failures may be retried with a budget and jitter. An operation that may have committed must use an idempotency key or reconciliation step before retrying. A syntactically valid but incorrect result belongs in evaluation and review, not a blind retry loop.

Set a deadline for the complete operation and derive smaller budgets for each dependency. Local timeouts that add up to more than the caller's deadline merely create abandoned work. Propagate cancellation where the protocol supports it. Bound every queue, retry loop, context buffer, and concurrency pool; an unbounded safety mechanism becomes a second outage during overload.

Design a degraded mode before it is needed. Depending on the workload, that can mean returning a cached answer, selecting a simpler path, placing work in a durable queue, or asking for human review. The degraded response must be visible in telemetry and, where it changes meaning, visible to the caller. Silent fallback makes quality regressions almost impossible to diagnose.

Measure the decision, not just the component

Use three layers of signals. System metrics cover latency, throughput, saturation, and errors. Correctness metrics measure whether the result satisfies its contract. Business or user metrics show whether the system solved the intended problem. Improving only one layer can move the others backward, so release criteria should name acceptable movement for all three.

Attach a reason code to every route, rejection, fallback, and retry. Include version identifiers for configuration, code, model, schema, and data when relevant. Logs should let an engineer reconstruct a decision without storing secrets or raw personal data. Traces should cross process boundaries, while metrics should remain low-cardinality enough to operate reliably.

Alert on symptoms that require action, not every internal anomaly. A useful alert names the affected service objective, links to a runbook, and distinguishes a customer-visible incident from exhausted headroom. Dashboards serve a different purpose: they support diagnosis and capacity planning. Treating a dashboard as an alerting strategy leaves failures undiscovered until someone happens to look.

Roll out with reversible steps

Ship Evaluating Multi-Turn Conversations behind a versioned interface and a kill switch. Begin with offline replay using production-shaped, privacy-safe samples. Then use shadow execution when duplicate work has acceptable cost and side effects can be suppressed. A small canary should exercise the real dependency graph before traffic expands. Compare the canary with the baseline by cohort rather than mixing both populations into one aggregate.

Promotion gates should be written before the rollout. Include a minimum sample size or observation window, maximum regression in tail latency and error rate, and a correctness threshold. Roll back automatically when a hard safety boundary is crossed; use manual review for ambiguous quality movement. Preserve enough evidence from both paths to explain why the gate passed or failed.

Configuration deserves the same discipline as code. Review changes, validate them before activation, keep an immutable history, and make rollback a single operation. If a deployment changes code and configuration together, record both versions. Otherwise an incident responder may roll back the binary while leaving the triggering configuration active.

Capacity and cost controls

Model capacity in units the bottleneck understands: concurrent connections, tokens, queue jobs, database transactions, GPU memory, or bytes in flight. Convert the expected traffic distribution into those units and include burst behavior. Then load-test the first constrained dependency, not merely the public endpoint. A system that accepts more work than it can finish within its deadline is overloaded even if CPU utilization looks comfortable.

Cost is also a reliability limit. Add per-request attribution, tenant or workflow budgets, and a global circuit breaker for unexpectedly expensive paths. Review unit economics at the same granularity as performance; a cheap median can conceal a small class of requests responsible for most spend. Optimize only after measuring, because reducing context, replicas, validation, or redundancy can trade visible cost for less visible risk.

Production readiness review

Before launch, ask an engineer who did not build the feature to follow the runbook through one simulated failure. Verify backups or checkpoints by restoring them, not by checking that a job reported success. Exercise credential rotation, dependency unavailability, bad configuration, and rollback. Assign an owner for each alarm and a date for reviewing thresholds after real traffic arrives.

The final architecture document should be short enough to remain current. Keep the decision, rejected alternatives, invariants, dependency contracts, dashboards, and rollback procedure. Link detailed experiments rather than pasting them into the document. Teams that need help turning this review into an operable service can use our Evaluating Multi-Turn Conversations engineering support.

Frequently Asked Questions

How many turns should test conversations have?

Short conversations: 3-5 turns (basic interactions) Medium: 6-10 turns (typical customer support) Long: 10-20+ turns (complex problem-solving)

Test distribution: 60% short, 30% medium, 10% long.

How do I test context window limits?

Create tests that exceed your context window:

  1. Generate conversation with 15-20 turns
  2. Reference info from turn 1 in turn 20
  3. Verify agent still remembers

Should I test every possible conversation path?

No. Focus on:

  • Common happy paths (60%)
  • Known failure scenarios (30%)
  • Edge cases (10%)

Use conversation analytics to identify real user paths.

How do I evaluate "natural" conversation flow?

Use LLM-as-judge with criteria:

  • Responses sound natural
  • Appropriate level of formality
  • No robotic or repetitive language

See LLM-as-Judge Guide.

What if my agent uses external tools?

Track tool calls per turn:

python
turn.expected_tool_calls = ["check_inventory", "place_order"]

Verify tool call sequence makes sense.

How do I test conversation repair?

Create tests where user corrects the agent:

python
turns = [
    Turn(user="My order ID is 12345"),
    Turn(user="Sorry, I meant 54321", expected_response_contains=["54321"])
]

Should I test multi-turn conversations in production?

Sample 5-10% of production conversations for retrospective evaluation. Don't block user conversations for eval.

How do I handle multi-user conversations?

Add user_id to each turn:

python
Turn(
    user_id="user_123",
    user_message="...",
    # ...
)

Track state per user.

What metrics correlate with user satisfaction?

In our data:

  • Task completion rate: r=0.89
  • Turn efficiency: r=0.76
  • Coherence score: r=0.71
  • Context retention: r=0.68

Task completion matters most.

How do I evaluate voice/speech conversations?

Add transcription quality checks:

python
turn.transcription_accuracy_threshold = 0.95

Test with typical speech recognition errors (e.g., "their" → "there").


Essential reading:

Testing strategies:

Production monitoring:

Services:

Conclusion

  • Define the contract and baseline before choosing tools.
  • Design bounded failure handling and an explicit degraded mode.
  • Gate rollout on correctness, latency, reliability, and cost.
  • Preserve a tested rollback path and an owned runbook.

Discuss your implementation with our Evaluating Multi-Turn Conversations engineers.

Free consultation

Book a free consultation call on conversational AI evaluation

30-minute call with the HinterBuild team. Discuss your project, architecture questions, or next steps — no obligation.

Book a meeting

Keep reading