File size: 2,063 Bytes
b7f63db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc3dd51
b7f63db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156dd84
b7f63db
0f123dc
 
b7f63db
 
156dd84
b7f63db
 
 
 
 
 
 
171371a
 
 
c47ca30
 
 
b7f63db
 
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
59
60
61
"""
Centralized AgentState for the StateGraph pipeline.

Every node reads from and writes to this shared state dict.
"""

from __future__ import annotations

from typing import Any, Dict, List, Optional, TypedDict


class AgentState(TypedDict, total=False):
    # --- Input ---
    messages: List[Dict[str, Any]]          # Raw conversation messages from the gateway
    user_id: str
    conversation_id: str
    wallet_address: Optional[str]           # EVM wallet address (from HTTP request)

    # --- Windowed context ---
    windowed_messages: List[Dict[str, Any]] # After context windowing
    langchain_messages: List[Any]           # LangChain message objects

    # --- Routing ---
    last_user_message: str
    route_intent: Optional[str]             # IntentCategory value
    route_confidence: float
    route_agent: Optional[str]              # Target agent name
    needs_llm_confirmation: bool
    has_active_defi: bool                   # In-progress DeFi flow detected

    # --- Pre-processing ---
    pre_extracted_hint: Optional[str]       # Pre-extracted parameter hint
    preflight_errors: List[str]             # Validation errors (empty = valid)

    # --- DeFi state ---
    swap_state: Optional[Dict[str, Any]]
    lending_state: Optional[Dict[str, Any]]
    staking_state: Optional[Dict[str, Any]]
    liquidity_state: Optional[Dict[str, Any]]
    dca_state: Optional[Dict[str, Any]]
    strategy_state: Optional[Dict[str, Any]]
    strategy_preferences: Optional[Dict[str, Any]]
    awaiting_swap: bool
    awaiting_dca: bool
    awaiting_liquidity: bool

    # --- Output ---
    final_response: str
    response_agent: str
    response_metadata: Dict[str, Any]
    raw_agent_messages: List[Any]           # Raw messages from agent invocation

    # --- Dual-path control ---
    response_mode: str                      # "fast" | "reasoning"

    # --- File attachments ---
    file_attachments: Optional[List[Dict[str, Any]]]

    # --- Observability ---
    nodes_executed: List[str]               # Trace of executed node names