File size: 1,355 Bytes
80dbe44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Graph State với conversation cache support - LangGraph compatible
"""
from typing import Optional, Dict, Any, List
from typing_extensions import TypedDict

class TransportationState(TypedDict):
    # Input/Output
    user_message: str
    ai_response: str
    
    # Conversation cache  
    conversation_cache: List[Dict[str, Any]]
    
    # Function tracking
    function_calls_made: List[Dict[str, Any]]
    
    # Error handling
    error_message: Optional[str]
    
    # Status
    current_step: str

def create_initial_state(user_message: str = "") -> TransportationState:
    """Create initial state with defaults"""
    return TransportationState(
        user_message=user_message,
        ai_response="",
        conversation_cache=[],
        function_calls_made=[],
        error_message=None,
        current_step="input"
    )

def add_function_call(state: TransportationState, function_name: str, arguments: Dict[str, Any], result: Dict[str, Any]) -> TransportationState:
    """Add function call to state"""
    state["function_calls_made"].append({
        "function_name": function_name,
        "arguments": arguments,
        "result": result
    })
    return state

def set_error(state: TransportationState, error: str) -> TransportationState:
    """Set error in state"""
    state["error_message"] = error
    return state