| """ | |
| agent/state.py | |
| LangGraph agent state β single TypedDict shared across all nodes. | |
| """ | |
| from typing import Any, Dict, List, Optional, TypedDict | |
| class AgentState(TypedDict): | |
| # ββ Input ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| session_id: str | |
| user_id: str | |
| user_query: str | |
| connector_id: str # neon:<schema> | sqlite:<supabase_url> | csv:<supabase_url> | |
| # ββ Routing ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| intent: str # sql | pandas | insight | unsupported | |
| query_plan: Dict[str, Any] # tables, approach, complexity | |
| # ββ Schema context βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| relevant_tables: List[Dict[str, Any]] # [{table, columns, sample_rows}] | |
| schema_context: str # compressed text for prompts | |
| # ββ Memory context βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| memory_context: str # retrieved similar past queries/insights | |
| # ββ Multi-turn conversation context ββββββββββββββββββββββββββββββββββββββββ | |
| conversation_history: List[Dict[str, Any]] # [{query, code, result_preview, insight}] | |
| # ββ Code generation ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| generated_code: str | |
| code_type: str # sql | pandas | |
| sql_dialect: str # postgres | sqlite | |
| # ββ Execution βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| execution_result: Optional[List[Dict[str, Any]]] | |
| execution_error: Optional[str] | |
| from_cache: bool | |
| # ββ Error handling βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| error_class: Optional[str] # nonexistent_column | syntax | logic | permission | unknown | |
| correction_attempts: int | |
| max_corrections: int # default 3 | |
| # ββ Output βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| insight_text: str | |
| chart_spec: Optional[Dict[str, Any]] # Plotly JSON | |
| anomalies: List[str] # Proactive anomaly callouts | |
| # ββ History / persistence ββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| history_id: Optional[str] | |
| latency_ms: Optional[int] | |
| stream_tokens: List[str] # SSE partial tokens | |