Skip to content

JLiang126/Conversational-Text-to-SQL-Agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Text to SQL Agent made for the Insight Factory Delivery Challenge

An intelligent, conversational data agent capable of querying a local SQL database to answer business questions about customers, orders, and deliveries.

Built with Python, LangGraph, Groq (Llama 3), and Streamlit.

Features

  • Natural Language to SQL: Translates plain English questions into secure SQL queries.
  • Dynamic Schema Awareness: The agent reads the database structure in real-time instantly adapting if the tables change.
  • Read-Only Safety: Uses strictly read-only connections to prevent accidental data modification.
  • Dual Interface:
    • Web UI: A user-friendly chat interface built with Streamlit.
    • CLI: A terminal-based mode for developer testing.
  • Memory: Retains conversation context to answer follow-up questions.

Tech Stack

  • LLM: Llama 3.3 (via Groq API)

  • Orchestration: LangGraph & LangChain

  • Database: SQLite

  • Frontend: Streamlit

  • Environment: Python 3.9+

Setup, Installation & Use

1. Clone the Repository.

git clone <your-repo-url>
cd Conversational-Text-to-SQL-Agent

2. Create a virtual environment.

  • For MacOS/Linux.
python -m venv venv
source venv/bin/activate

3. Install dependacies.

pip install -r requirements.txt

4. Configure .env variables.

  • Rename .env.local -> .env.
  • Fill with your API Keys as requested in the .env file.

5. Create the database.

python3 ingest.py

6. Run the app.

  • For the app:
streamlit run app.py
  • For the CLI:
python3 main.py

Project Structure

.
├── agent/                  # The Agent
│   ├── graph.py            # LangGraph workflow definition
│   ├── prompt.py           # System prompts and rules
│   ├── state.py            # AgentState definition
│   └── tools.py            # SQL execution tools
├── data/                   # The data
│   ├── data.csv
│   └── ...
├── database/               # Data storage
│   └── database.sqlite     # The SQLite file
├── .env                    # API Keys (GitIgnored)
├── app.py                  # Streamlit App
├── ingest.py               # Data loading script
├── main.py                 # CLI App
└── requirements.txt        # Python dependencies

About

An intelligent, conversational data agent capable of querying a local SQL database to answer business questions about customers, orders, and deliveries.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages