Agentic text-to-SQL backend for a telecommunications manufacturing plant that builds base station transceivers. The stack uses a controlled LangGraph workflow to enforce:
- Data dictionary search
- Schema probing
- Data sampling
- SQL generation, checking, execution, and synthesis
The repo ships with a normalized demo factory schema and seed data so you can run the system end to end without external SQL files.
sql/001_factory_schema.sql: normalized telecom factory schemasql/002_factory_seed.sql: demo production, quality, and sensor datasrc/factory_planning_ai/agent.py: controlled LangGraph SQL workflowsrc/factory_planning_ai/tools.py: data dictionary, schema probe, sample, and SQL execution toolssrc/factory_planning_ai/service.py: application service for UI and CLIapp.py: Streamlit interface
Use Python 3.11 or newer. Current LangChain and LangGraph releases require Python 3.10+ and this project targets 3.11.
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements-base.txt -r requirements-openai.txt
Copy-Item .env.example .env
python scripts\bootstrap_demo_db.py --reset
streamlit run app.py.\run.ps1Useful variants:
.\run.ps1 -Mode local-cli -Question "Which production line is most at risk of missing plan based on the last 3 shifts?"
.\run.ps1 -ResetDb
.\run.ps1 -Mode docker-uiIf you want Gemini or Anthropic instead of OpenAI, install the matching provider requirement file and change FACTORY_LLM_MODEL in .env.
python scripts\ask.py "Which base station model had the highest defect rate over the last 3 shifts?"Copy-Item .env.example .env
docker compose up --build- Which production line is most at risk of missing planned units based on the last 3 shifts?
- Which base station model has the highest defect rate and what defect is driving it?
- Show average RF output power by model and line.
- Compare completed units versus planned units by shift date.
- Which sensor metrics are most associated with failed inspections?
- The execution tool is read-only and rejects DDL/DML.
- The demo database is SQLite for portability, but the backend code accepts any SQLAlchemy URI.
- In production, connect the service to a least-privilege PostgreSQL or MySQL read-only user.