This project is a FastAPI application built with LangGraph for telecom analytics. It turns natural-language business questions into SQL, executes them against the Cockpit PostgreSQL database, and returns a readable answer.
The project now uses PostgreSQL for Cockpit data instead of SQLite. The current workflow focuses on supervisor-driven SQL analysis and no longer includes the research agent or Tavily-based external enrichment.
The application is organized around a small, focused workflow:
SupervisorAgenthandles the incoming chat request, planning, human-in-the-loop review, and final reasoning.Text2SQLgenerates SQL, validates it, and executes it against the Cockpit PostgreSQL database.
Retrieval still relies on Qdrant. The scripts under retrieve/ index schema, values, evidence, and examples from the JSON files in context/.
Run PostgreSQL locally in Docker before starting the application:
docker run -d --name cockpit-postgres -e POSTGRES_USER=username -e POSTGRES_PASSWORD=password -e POSTGRES_DB=cockpit_db -p 5432:5432 postgres:latestThis command creates a container named cockpit-postgres and exposes PostgreSQL on localhost:5432.
After the database is running, create the Cockpit tables and seed the mock data by running the database setup script used by the project.
If you maintain your own initialization script, the expected database is:
- Host:
localhost - Port:
5432 - Database:
cockpit_db - Username:
username - Password:
password
Create a .env file in the repository root and configure the services used by the app:
COCKPIT_DB_URI=postgresql://root:1234@localhost:5432/cockpit_db
GROQ_API_KEY=your_groq_api_key_here
# Langfuse tracing
LANGFUSE_PUBLIC_KEY=pk-lf-...
LANGFUSE_SECRET_KEY=sk-lf-...
LANGFUSE_HOST=https://cloud.langfuse.comNotes:
COCKPIT_DB_URIis required for the PostgreSQL connection.GROQ_API_KEYis required for the LLM calls.LANGFUSE_HOSTcan point to Langfuse Cloud or a self-hosted instance.
The JSON files that feed the retrieval pipeline should be placed in context/:
context/db_schema.jsoncontext/db_values.jsoncontext/evidence.jsoncontext/question-example.json
Keep these files in context/ so the scripts in retrieve/ can load them without changing paths.
Run Qdrant locally in Docker before populating the vector collections:
docker volume create qdrant_storage
docker pull qdrant/qdrant
docker run -d --name qdrant -p 6333:6333 -p 6334:6334 -v qdrant_storage:/qdrant/storage --restart unless-stopped qdrant/qdrantThe application connects to Qdrant on localhost:6333.
The retrieve/ folder contains the indexing scripts that build the Qdrant collections used by the app:
store_db_schema.pyindexes the database schema fromcontext/db_schema.json.store_category_db.pyindexes distinct column values fromcontext/db_values.json.store_evidence.pyindexes domain evidence fromcontext/evidence.json.store_examples.pyindexes few-shot question and SQL examples fromcontext/question-example.json.
Run these scripts directly as modules after Qdrant is running and the JSON files are in place.
Example:
python -m retrieve.store_category_db
python -m retrieve.store_db_schema
python -m retrieve.store_evidence
python -m retrieve.store_examples- Create and activate a Python environment.
- Install dependencies with
pip install -r requirements.txt. - Start PostgreSQL with the Docker command above.
- Create the
.envfile withCOCKPIT_DB_URIand the remaining secrets. - Start Qdrant with the Docker commands above.
- Make sure the JSON files are present in
context/. - Run the retrieval scripts in
retrieve/to populate Qdrant. - Start the API with
fastapi dev main.py --reload.
The app exposes two main endpoints:
POST /chats/newcreates a new chat session and returns achat_id.POST /chats/{chat_id}/asksends a user message through the supervisor workflow.
Example:
curl -X POST http://127.0.0.1:8000/chats/new -H "Content-Type: application/json"
curl -X POST http://127.0.0.1:8000/chats/<chat_id>/ask -H "Content-Type: application/json" -d "{\"message\":\"Give me the MTD comparison for product *6\"}"main.py # FastAPI app and request lifecycle
models.py # LLM, embeddings, and Qdrant configuration
prompts.py # Prompt templates used by the agents
states.py # LangGraph state definitions
agents/
supervisor_agent.py # Main orchestrator and reasoning flow
text2sql.py # SQL generation and execution agent
retrieve/ # Qdrant indexing scripts for schema, values, evidence, and examples
context/ # JSON source files used to populate Qdrant collections
assets/ # Static assets and local storage
requirements.txt # Python dependencies
README.md # Project documentation
- The supervisor workflow supports human review pauses before querying the database.
- The PostgreSQL checkpointer keeps conversation state aligned with the
chat_idthread. - Langfuse is the recommended place to inspect execution traces when debugging agent behavior.
- If a sub-query returns an empty result, verify that Qdrant is running, the retrieval scripts have been executed, and the JSON files in
context/contain the expected data.