How sheily899/querypilot-data-agent works
Purpose and entry points
QueryPilot is a local natural-language-to-SQL agent for a single structured database. It turns business questions and follow-ups into guarded, read-only SQL, executes it, and presents answers in a Vue workbench. Backend startup is backend/run.py, which serves the application assembled in backend/app/main.py; the browser client starts at frontend/src/main.ts and mounts frontend/src/App.vue.
API and application boundary
HTTP routes in backend/app/api/routes.py expose the query/session-facing backend contract. backend/app/main.py initializes the API application, while backend/app/config.py and backend/app/database.py provide environment-driven runtime configuration and database integration. The frontend calls this contract through frontend/src/api.ts, rendering typed responses defined in frontend/src/types.ts.
Query orchestration workflow
The core request pipeline is a stateful workflow:
• backend/app/services/askdata_service.py coordinates a user request.
• backend/app/workflows/query_graph.py defines the staged query graph.
• backend/app/workflows/state.py carries request, retrieval, SQL, execution, and response state across stages.
• backend/app/workflows/result_builder.py shapes the final client result.
This separates transport/API concerns from agent control flow and result presentation.
Retrieval and schema grounding
Before SQL generation, the agent retrieves relevant schema fields and relationship context. backend/app/retrieval/service.py orchestrates keyword/semantic retrieval, rank fusion, and reranking; backend/app/retrieval/store.py holds retrieval data; backend/app/retrieval/graph.py builds schema relationship graphs. Retrieved evidence is a boundary between broad database metadata and the constrained context supplied to generation.
Model-driven SQL agent and tools
backend/app/querying/single_database_agent.py implements the single-database agent loop, with query-domain types in backend/app/querying/models.py. It uses backend/app/model_client.py to call the configured external model endpoint and backend/app/querying/response_generator.py to form user-facing explanations. Local Model Context Protocol-style tool infrastructure resides in backend/app/mcp_runtime/client.py, backend/app/mcp_runtime/server.py, and tools such as backend/app/mcp_runtime/tools/database_tools.py; this is the controlled mechanism for model-initiated database/time operations.
Execution and security controls
backend/app/querying/duckdb_engine.py is the concrete local query execution layer. Security modules—backend/app/security/access_control.py and backend/app/security/auth.py—provide authorization-related boundaries, while the query path enforces the product’s read-only, single-statement, permitted-table, and dangerous-operation constraints before execution. The included demo-data path is represented by backend/app/demo_data.py and backend/seed_demo_data.py.
Conversation context and UI
Multi-turn behavior is managed independently of query planning: backend/app/services/session_context.py builds usable context, backend/app/services/short_term_memory.py maintains recent turns, and backend/app/services/session_archive.py persists/archive-oriented history. The Vue workbench in frontend/src/App.vue displays conversation and SQL/results; frontend/src/components/ResultTableCard.vue handles tabular result presentation/export-oriented UI. Runtime infrastructure is Python 3.11 with a model service configured via backend environment variables, plus a Vite/Vue frontend.
Main entry points: query_graph.py Staged query graph · single_database_agent.py Single-database SQL agent · askdata_service.py Request coordinator · service.py Evidence retrieval
Components 21
Vue workbench
- Vue application · Conversation and query workbench.
frontend/src/App.vue - API client
frontend/src/api.ts - Results table
frontend/src/components/ResultTableCard.vue
Application API
- Backend launcher
backend/run.py - Application assembly
backend/app/main.py - Query and session routes
backend/app/api/routes.py
Query workflow
- Request coordinator
backend/app/services/askdata_service.py - Staged query graph
backend/app/workflows/query_graph.py - Workflow state · Carries retrieval, SQL, execution, and response state.
backend/app/workflows/state.py - Client result builder
backend/app/workflows/result_builder.py
Agent and execution
- Single-database SQL agent · Generates guarded SQL using grounded evidence and tools.
backend/app/querying/single_database_agent.py - Model client
backend/app/model_client.py - Controlled tool runtime · Controls model-initiated database and time operations.
backend/app/mcp_runtime/server.py - DuckDB executor · Executes validated single-database queries.
backend/app/querying/duckdb_engine.py - Local structured database
Schema retrieval
- Evidence retrieval · Fuses keyword and semantic schema retrieval.
backend/app/retrieval/service.py - Schema retrieval store
backend/app/retrieval/store.py - Schema relationships
backend/app/retrieval/graph.py
Session context
- Conversation context
backend/app/services/session_context.py - Recent-turn memory
backend/app/services/short_term_memory.py - Session archive
backend/app/services/session_archive.py
Connections 25
- Vue application → API client: submits questions
- API client → Query and session routes: HTTP
- Backend launcher → Application assembly: starts
- Application assembly → Query and session routes: mounts
- Query and session routes → Request coordinator: dispatches
- Request coordinator → Staged query graph: runs
- Staged query graph → Workflow state: updates
- Staged query graph → Conversation context: builds context
- Conversation context → Recent-turn memory: reads recent turns
- Conversation context → Session archive: reads history
- Staged query graph → Evidence retrieval: grounds request
- Evidence retrieval → Schema retrieval store: retrieves metadata
- Evidence retrieval → Schema relationships: uses relationships
- Staged query graph → Single-database SQL agent: plans and generates
- Evidence retrieval → Single-database SQL agent: constrained evidence
- Single-database SQL agent → Model client: model calls
- Single-database SQL agent → Controlled tool runtime: tool calls
- Controlled tool runtime → DuckDB executor: database tool
- Single-database SQL agent → DuckDB executor: validated SQL
- DuckDB executor → Local structured database: read-only queries
- Staged query graph → Client result builder: builds response
- Client result builder → Query and session routes: client result
- Vue application → Results table: renders tabular results
- Request coordinator → Recent-turn memory: records turn
- Request coordinator → Session archive: archives turn