How alisadeghiaghili/local-sql-agent works
Local SQL Agent turns Persian or English questions into guarded warehouse queries, returning rows and optional exports; conversational turns can refine prior SQL. The graph emphasizes the documented query path, session handling, authentication, schema/knowledge inputs, and runtime safeguards. README descriptions support the principal pipeline; source-index references support several internal calls. Some API execution and persistence wiring is unsampled, so uncertain links are omitted.
Main entry points: engine.py Turn engine · context_retriever.py Context retrieval · sql_guard.py SQL guard · v2_routes.py HTTP API
Components 23
User interfaces
- HTTP API
api/v2_routes.py - Command-line app
app.py - Rows and exports
exporters/excel_exporter.py
Query orchestration
- Turn engine
session/engine.py
Context and prompts
- Context retrieval
retrieval/context_retriever.py - Prompt building
prompt_engine/builder.py - Static prompt prefix
prompt_engine/static_prefix.py - Domain knowledge
knowledge/config_loader.py - Schema registry
schema_data/registry.py
SQL and data access
- Source selection
llm/source_routing.py - LLM routing
llm/router.py - SQL generation
llm/sql_agent.py - SQL guard
security/sql_guard.py - Warehouse sources
database/datasources.py - Query source routing
database/routing.py - Query execution
database/executor.py - Evaluation harness
eval/pipeline.py
Identity and state
- Column policy
security/column_policy.py - Session store
session/store.py - Application database
appdb/engine.py - API authentication
api/auth.py - Audit logging
observability/audit.py
Other components
- Analyst
Connections 24
- Analyst → HTTP API: asks over HTTP
- Analyst → Command-line app: asks interactively
- HTTP API → API authentication: authenticates requests
api/v2_routes.py - HTTP API → Turn engine: handles session turns
api/v2_routes.py - Command-line app → Query execution: executes queries
app.py - Turn engine → Context retrieval: retrieves context
session/engine.py - Context retrieval → Prompt building: supplies context
retrieval/context_retriever.py - Prompt building → LLM routing: builds model prompt
llm/router.py - LLM routing → SQL generation: routes generation
llm/router.py - SQL generation → SQL guard: validates SQL
- SQL guard → Column policy: checks column access
security/sql_guard.py - SQL guard → Query source routing: selects source
security/sql_guard.py - Query source routing → Warehouse sources: resolves source
database/routing.py - SQL guard → Query execution: passes guarded SQL
- Query execution → Rows and exports: returns rows
- Rows and exports → Analyst: presents answer
- Turn engine → Session store: uses session state
session/engine.py - Session store → Application database: persists conversations
- Static prompt prefix → Domain knowledge: includes domain material
prompt_engine/static_prefix.py - Static prompt prefix → Schema registry: includes schema
prompt_engine/static_prefix.py - Context retrieval → Domain knowledge: retrieves rules and examples
retrieval/context_retriever.py - Context retrieval → Schema registry: selects schema context
retrieval/context_retriever.py - Turn engine → Audit logging: records activity
session/engine.py - Evaluation harness → SQL generation: evaluates generation
eval/pipeline.py