How gurdeepsingh-10/sql_agent works
This is an AI SQL Agent API: users authenticate, register a database connection, ask questions in natural language, and receive SQL results or a confirmation request. The query route selects a connection, assembles conversation memory, and hands work to the agent workflow; query history and dashboard telemetry support follow-up. The agent directory contains the distinct planning, schema, generation, validation, and execution stages. Several of those modules were not excerpted, so internal workflow links are marked unverified rather than asserted as observed calls.
Main entry points: nodes.py Workflow nodes · agent.py Query API · main.py FastAPI app · database.py Application database
Components 27
API and identity
- FastAPI app
app/main.py - Auth routes
app/api/routes/auth.py - JWT auth dependency
app/api/deps.py - Token security
app/core/security.py - Query API
app/api/routes/agent.py - Connection API
app/api/routes/connections.py
SQL agent
- Agent workflow
app/core/agent/graph.py - Workflow nodes
app/core/agent/nodes.py - Query planning
app/core/agent/query_planner.py - Schema inspection
app/core/agent/schema_inspector.py - Intent processing
app/core/agent/nlp_processor.py - SQL generation
app/core/agent/sql_generator.py - SQL validation
app/core/agent/validator.py - SQL risk guard
app/core/sql_guard.py - SQL execution
app/core/agent/executor.py - Conversation memory
app/core/agent/memory_manager.py - Context pruning
app/core/agent/context_pruner.py - Semantic cache
app/core/semantic_cache.py
Connections and storage
- Dynamic DB connections
app/core/connection_manager.py - Application database
app/database.py - User records
app/models/user.py - Saved connections
app/models/user_connection.py
History and analytics
- Dashboard API
app/api/routes/dashboard.py - Query history
app/models/query_history.py
Other components
- User
- User database
- Groq language model
Connections 35
- User → FastAPI app: uses
app/main.py - FastAPI app → Auth routes: registers routes
app/main.py - FastAPI app → Query API: registers routes
app/main.py - FastAPI app → Connection API: registers routes
app/main.py - FastAPI app → Dashboard API: registers routes
app/main.py - Auth routes → Token security: hashes and signs
app/api/routes/auth.py - JWT auth dependency → Token security: decodes token
app/api/deps.py - JWT auth dependency → User records: looks up user
app/api/deps.py - Auth routes → User records: creates account
app/api/routes/auth.py - Query API → JWT auth dependency: requires identity
app/api/routes/agent.py - Query API → Saved connections: selects connection
app/api/routes/agent.py - Query API → Dynamic DB connections: gets DB engine
app/api/routes/agent.py - Query API → Schema inspection: inspects schema
app/api/routes/agent.py - Query API → Conversation memory: assembles context
app/api/routes/agent.py - Query API → Agent workflow: runs workflow
app/api/routes/agent.py - Agent workflow → Workflow nodes: dispatches steps
- Workflow nodes → Query planning: plans query
- Workflow nodes → Intent processing: interprets request
- Workflow nodes → SQL generation: generates SQL
- Workflow nodes → SQL validation: validates SQL
- Workflow nodes → SQL risk guard: checks risk
- Workflow nodes → SQL execution: executes SQL
- Workflow nodes → Context pruning: trims context
- Workflow nodes → Semantic cache: checks cache
- Query API → Query history: records query
app/api/routes/agent.py - Connection API → Saved connections: manages connections
- Dynamic DB connections → User database: opens connections
app/core/connection_manager.py - SQL execution → User database: runs SQL
- Workflow nodes → Groq language model: requests completion
- FastAPI app → Application database: initializes tables
app/main.py - Dashboard API → Query history: reads analytics
app/api/routes/dashboard.py - Dashboard API → Dynamic DB connections: reads telemetry
app/api/routes/dashboard.py - User records → Application database: persists records
app/models/user.py - Saved connections → Application database: persists records
app/models/user_connection.py - Query history → Application database: persists records
app/models/query_history.py