Spaces:
Runtime error
Runtime error
feat: synchronize text-to-sql-bot codebase with Hugging Face Space repository, including Docker build configurations
6086e71 | """ | |
| Agent State β Shared TypedDict for the LangGraph multi-agent pipeline. | |
| Every agent reads from and writes to this state object. | |
| """ | |
| from typing import TypedDict, Optional, Literal | |
| class AgentState(TypedDict, total=False): | |
| """ | |
| Shared state flowing through the LangGraph agent pipeline. | |
| Each agent enriches specific fields and passes state forward. | |
| """ | |
| # ββ Input ββββββββββββββββββββββββββββββββββββββββββββ | |
| user_query: str | |
| conversation_history: list[dict] | |
| tenant_id: str | |
| user_role: str | |
| trace_id: str | |
| # ββ Query Understanding Agent Output βββββββββββββββββ | |
| intent: Literal[ | |
| "chat", # Natural conversation | |
| "sql", # Database query that should continue to SQL generation | |
| ] | |
| route_intent: Literal[ | |
| "chat", # Hi, hello, thanks, capabilities, etc. | |
| "data_query", # SELECT with filters | |
| "aggregation", # COUNT, SUM, AVG, GROUP BY | |
| "comparison", # Compare datasets | |
| "explanation", # Explain a concept or previous query | |
| "meta_query", # Questions about the schema itself | |
| ] | |
| entities: list[str] # Extracted table/column names | |
| complexity: Literal["simple", "moderate", "complex"] | |
| retrieval_top_k: int # How many schema docs to fetch (3=simple, 5=default, 8=complex) | |
| # ββ Schema Retrieval Agent Output ββββββββββββββββββββ | |
| relevant_schema: str # Formatted schema context for LLM | |
| relevant_tables: list[str] # Table names retrieved | |
| retrieval_source: str # "rag_top_k:{n}" | "full_schema_fallback" | "meta_query" β for tracing | |
| # ββ SQL Generation Agent Output ββββββββββββββββββββββ | |
| generated_sql: str # The SQL query | |
| sql_explanation: str # Technical explanation | |
| friendly_message: str # User-friendly message | |
| # ββ SQL Validation Agent Output ββββββββββββββββββββββ | |
| is_valid: bool # Safety check passed | |
| validation_errors: list[str] # List of issues found | |
| sanitized_sql: str # SQL after safety modifications (LIMIT injection, etc.) | |
| retry_count: int # Number of regeneration attempts | |
| # ββ Output Guardrail Results βββββββββββββββββββββββββ | |
| guardrail_warnings: list[str] # Hallucinated reference warnings | |
| guardrail_confidence: float # LLM output confidence score (0.0-1.0) | |
| # ββ Execution Agent Output βββββββββββββββββββββββββββ | |
| query_results: list[dict] # Raw query results | |
| execution_time_ms: float # Query execution duration | |
| row_count: int # Number of rows returned | |
| column_names: list[str] # Column names in result set | |
| # ββ Visualization Agent Output βββββββββββββββββββββββ | |
| chart_config: Optional[dict] # Chart.js configuration | |
| chart_type: Optional[str] # bar, line, pie, doughnut, scatter | |
| insights: list[str] # Auto-generated insights | |
| follow_up_questions: list[str] # Suggested follow-up queries | |
| # ββ Error Handling βββββββββββββββββββββββββββββββββββ | |
| error: Optional[str] # Error message if any step failed | |
| error_agent: Optional[str] # Which agent produced the error | |