This repository contains a dual-agent system designed to interact with enterprise data using natural language. It demonstrates two distinct approaches to AI data retrieval and management: querying a relational SQLite database (Inventory Bot) using LangGraph, and managing a Neo4j graph database (Knowledge Graph Agent) using LlamaIndex.
The project is split into two primary terminal-based chatbots, each optimized for a specific type of database architecture. Additionally, an experimental Jupyter Notebook is included for Gemini-powered SQL generation via FastAPI.
An AI agent built with LangGraph that translates natural language into SQLite queries. It features a robust self-correction routing loop that automatically catches and fixes syntactically incorrect SQL queries before returning the final answer.
- Natural Language to SQL: Converts questions about assets, locations, and vendors into executable SQLite code.
- Self-Correction Loop: Uses an AI corrector node to detect execution errors and regenerate the query autonomously.
- Structured State Management: Uses LangGraph's
StateGraphto pass the user question, generated SQL, execution results, and errors between isolated nodes.
graph TD
A[User Input] -->|Question| B(Generator Node)
B -->|Generates SQL| C(Executor Node)
C -->|Runs Query on SQLite| D{Execution Error?}
D -- Yes --> E(Corrector Node)
E -->|Fixes SQL Syntax| C
D -- No --> F(Responder Node)
F -->|Synthesizes Results| G[Final NL Output to User]
subgraph LangGraph State Workflow
B
C
E
F
end
A complete CRUD-capable agent that allows users to manage facts, entities, and relationships within a Neo4j graph database using natural language commands.
- Two-Step Intent & Entity Classification: Precisely identifies if the user wants to
add,inquire,edit, ordeletedata, and then dynamically extracts the required entities (entity,relation,value). - Dynamic Cypher Translation: Automatically generates and executes complex Cypher queries (using
MERGE,MATCH, and conditionalFOREACHloops for orphaned node deletion). - Natural Synthesis: Provides human-readable summaries of the database actions via a dedicated LlamaIndex Synthesis Engine.
graph TD
A[User Input] --> B(Intent Classifier)
B -->|add, inquire, edit, delete| C(Entity Extractor)
C -->|JSON: entity, relation, value| D(Cypher Engine)
D <-->|Executes Structured Query| E[(Neo4j AuraDB)]
D -->|Raw Database Result| F(Synthesis Engine)
F -->|Human-Readable Summary| G[Final NL Output to User]
subgraph LlamaIndex & Groq Workflow
B
C
D
F
end
- Python 3.10+
- SQLite3
- Neo4j Database (Local or AuraDB)
- API Keys (Groq / OpenAI)
git clone [https://github.com/MalakHisham121/AI--powered-Chatbots.git](https://github.com/MalakHisham121/AI--powered-Chatbots.git)
cd AI--powered-ChatbotsInstall the required packages (including LlamaIndex, LangGraph, and Neo4j drivers) from the requirements file:
pip install -r requirements.txtCreate a .env file in the root directory and add your database and LLM credentials:
# LLM Provider
GROQ_API_KEY=your_groq_api_key_here
# Neo4j Database Configuration
NEO4J_URI=neo4j+s://your-instance.databases.neo4j.io
NEO4J_USER=neo4j
NEO4J_PASSWORD=your_neo4j_password
NEO4J_DATABASE=neo4jFirst, initialize the SQLite database with the sample schema:
cd "AI inventory Chatbot"
python db-setup.pyThen, start the interactive terminal agent:
python main.pyEnsure your Neo4j instance is running, then execute the agent:
cd "AI Knowledge Graph Agent"
python main.pyExample Graph Commands:
- Add: "Cairo University is located in Egypt."
- Inquire: "Where is Cairo University located?"
- Edit: "Update the located_in relation for Cairo University to Giza."
- Delete: "Remove the located_in relation from Cairo University."
The repository also includes AI_Agent_to_convert_from_SQL_to_NL.ipynb, an experimental Jupyter Notebook. It demonstrates how to wrap a Gemini 1.5 Pro model in a FastAPI endpoint to generate SQL, execute it against a local SQLite database, and return a natural language explanation alongside performance metrics (latency) in a clean JSON response.