15%

5.2 Escalation and Ambiguity Resolution

Escalation คืออะไร

Escalation คือกลไกที่ agent ใช้เมื่อพบสถานการณ์ที่ตัดสินเองไม่ได้ — แทนที่จะเดาหรือทำผิด agent “ยกระดับ” ปัญหาขึ้นไปหา human หรือ agent ที่มี authority สูงกว่า เป็น safety mechanism สำคัญที่ป้องกัน agent จากการทำสิ่งที่ irreversible โดยไม่มั่นใจ

เมื่อไหร่ควร Escalate

ต้อง Escalate (Non-negotiable)

  • Irreversible actions — ลบ data, deploy to production, ส่ง email ให้ลูกค้า
  • Ambiguous requirements — ไม่ชัดว่า user ต้องการอะไร
  • Conflicting instructions — system prompt ขัดกับ user request
  • Out of scope — task ที่ไม่อยู่ใน agent’s capabilities
  • Safety concerns — พบ potential security issues, harmful content

ไม่ต้อง Escalate

  • Routine operations ที่ทำประจำ
  • Decisions within clearly defined parameters
  • Error recovery ที่มี established playbook

Escalation Patterns

Pattern 1: Clarification Request

def handle_ambiguous_request(user_input, context):
    # Detect ambiguity
    interpretation = client.messages.create(
        system="""You are an ambiguity detector. 
        If the request has multiple valid interpretations, list them.
        If clear, respond with "CLEAR".""",
        messages=[{"role": "user", "content": user_input}]
    )
    
    if "CLEAR" not in interpretation.content[0].text:
        # Escalate — ask user to clarify
        return {
            "action": "clarify",
            "message": f"I found multiple interpretations:\n{interpretation.content[0].text}\nWhich did you mean?",
            "options": extract_options(interpretation)
        }
    
    return {"action": "proceed"}

Pattern 2: Confidence-Based Escalation

def should_escalate(confidence, action_type):
    thresholds = {
        "read_only": 0.3,      # Low bar — safe to try
        "reversible_write": 0.6,  # Medium bar
        "irreversible": 0.9,    # High bar — almost certain before acting
        "destructive": 0.99,    # Nearly certain
    }
    
    threshold = thresholds.get(action_type, 0.8)
    
    if confidence < threshold:
        return True, f"Confidence {confidence:.0%} below threshold {threshold:.0%} for {action_type}"
    return False, None

Pattern 3: Tiered Escalation

class EscalationTier:
    SELF_RESOLVE = 1      # Try harder, use more tools
    PEER_AGENT = 2        # Ask another agent for opinion  
    SUPERVISOR_AGENT = 3  # Escalate to orchestrator
    HUMAN = 4             # Ask the human

def escalate(issue, current_tier=1):
    if current_tier == EscalationTier.SELF_RESOLVE:
        result = try_alternative_approach(issue)
        if result.success:
            return result
        return escalate(issue, EscalationTier.PEER_AGENT)
    
    elif current_tier == EscalationTier.PEER_AGENT:
        opinion = ask_peer_agent(issue)
        if opinion.confidence > 0.8:
            return execute_with_opinion(opinion)
        return escalate(issue, EscalationTier.SUPERVISOR_AGENT)
    
    elif current_tier == EscalationTier.SUPERVISOR_AGENT:
        decision = ask_supervisor(issue)
        if decision.resolved:
            return execute_decision(decision)
        return escalate(issue, EscalationTier.HUMAN)
    
    elif current_tier == EscalationTier.HUMAN:
        return pause_and_ask_human(issue)

Ambiguity Resolution

Structured Clarification

แทนที่จะถามคำถาม open-ended ให้เลือกแบบ multiple choice:

def ask_clarification(ambiguity):
    return {
        "question": ambiguity.description,
        "options": [
            {"label": "A", "description": ambiguity.interpretation_1},
            {"label": "B", "description": ambiguity.interpretation_2},
            {"label": "C", "description": "Something else (please specify)"}
        ],
        "context": ambiguity.why_it_matters
    }

Default with Disclosure

เมื่อต้องเลือกแต่ไม่แน่ใจ — เลือก safe default แล้วบอก user:

def act_with_default(ambiguous_param, safe_default, reason):
    result = execute_with(safe_default)
    return {
        "result": result,
        "note": f"I assumed '{safe_default}' for '{ambiguous_param}' because {reason}. Let me know if you'd prefer something different."
    }

Key Concepts

  • Fail-safe > Fail-fast — เมื่อไม่แน่ใจ หยุดดีกว่าทำผิด (โดยเฉพาะ irreversible actions)
  • Structured choices > Open questions — ให้ options ดีกว่าถาม “อะไรก็ได้”
  • Escalation cost — ทุก escalation มี latency cost (human ช้ากว่า agent) ต้อง balance
  • Over-escalation — ถาม user ทุกอย่าง = useless agent; ต้องมี judgment

Exam Tips

  • Irreversible actions ต้อง escalate เสมอ — ข้อสอบจะถามว่า scenario ไหนต้อง escalate
  • Confidence threshold ต่าง action type: destructive > irreversible > reversible > read-only
  • ข้อสอบจะถาม: agent ไม่แน่ใจ ทำอย่างไร — ตอบ: escalate to human, ไม่ใช่เดา
  • Structured clarification (options) ดีกว่า open-ended question — ลด back-and-forth
  • Over-escalation เป็นปัญหาเท่ากับ under-escalation — agent ที่ถามทุกอย่าง = ไม่ helpful