File size: 2,041 Bytes
cff1a2a
 
 
 
 
 
 
72bff80
cff1a2a
 
 
 
 
72bff80
 
 
 
cff1a2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72bff80
cff1a2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from typing import TypedDict, Annotated, List, Dict, Any, Optional
import operator


class UserProfile(TypedDict, total=False):
    """User profile for recommendation intent."""
    age: Optional[int]
    gender: Optional[str]  # "male", "female"
    income: Optional[str]
    smoker: Optional[bool]
    dependents: Optional[int]
    goal: Optional[str]  # "protection", "savings", "retirement", "wealth"
    cover_amount: Optional[str]  # e.g., "1 Cr", "50 Lakh"
    premium_amount: Optional[str]  # e.g., "1 Lakh", "50000"
    policy_term: Optional[str] # PT
    payment_term: Optional[str] # PPT
    payment_mode: Optional[str] # Mode (Monthly, Annual, etc.)


class ExtractedEntities(TypedDict, total=False):
    """Entities extracted from user query."""
    provider: Optional[List[str]]  # ["TATA AIA", "Edelweiss Life"]
    insurance_type: Optional[List[str]]  # ["Term Insurance", "ULIP"]
    plan_names: Optional[List[str]]  # Specific plan names mentioned
    user_profile: Optional[UserProfile]


class AgentState(TypedDict):
    """
    Enhanced state for the LangGraph RAG workflow.
    Supports deterministic, compliance-focused retrieval.
    """
    # Input
    input: str
    chat_history: List[str]
    
    # Query Classification
    intent: str  # 'list_plans', 'plan_details', 'compare_plans', 'recommendation', 'general_query'
    query_complexity: str # 'low' | 'high'
    
    # Entity Extraction
    extracted_entities: ExtractedEntities
    
    # Retrieval Configuration
    metadata_filters: Dict[str, Any]  # Filters for vector store
    retrieval_strategy: str  # 'metadata_only', 'plan_level', 'section_specific', 'cross_plan'
    
    # Retrieved Content
    context: List[str]  # accumulated context strings
    retrieved_chunks: Dict[str, List[Dict]]  # Grouped by plan_id: {plan_id: [chunks]}
    
    # Reasoning & Output
    reasoning_output: str  # Structured comparison/recommendation data
    answer: str  # Final answer to user
    
    # Internal Routing
    next_step: str  # For conditional edges