This repository demonstrates a production-ready architecture for a multi-step Financial SQL Agent using cutting-edge LLM tooling. It leverages a combination of:
- LangGraph: For orchestrating multi-step agent logic.
- LangChain: For creating SQL agents and handling database toolkits.
- OpenAI LLMs: Used via
ChatOpenAIto interpret user intent and generate SQL queries. - FAISS-based Vector Store: Stores and retrieves semantic memory to provide historical context.
- SQLite: A lightweight SQL database backend with sample financial data.
- Accept natural language questions about financial data (e.g., "Show me total expenses in January").
- Retrieve contextual memory from a vector database to enrich SQL generation.
- Use LangGraph to orchestrate query steps.
- Translate the result into a clear and useful output.
financial-sql-agent/
├── agents/
│ ├── query_agent.py # Builds the SQL agent using LangChain + OpenAI + memory
│ └── orchestrator.py # Orchestrates query handling
│
├── data/
│ ├── init_db.py # Initializes SQLite with sample financial transactions
│ └── sample_financial_data.db
│
├── memory/
│ └── vector_store.py # FAISS vector memory using OpenAI embeddings
│
├── prompts/
│ └── financial_prompt.txt # System prompt that guides the agent
│
├── langgraph_app/
│ └── langgraph_flow.py # LangGraph setup for execution flow
│
├── main.py # CLI app entry point
├── requirements.txt # Dependencies
└── README.md # Project documentation
git clone https://github.com/your-username/financial-sql-agent.git
cd financial-sql-agentCreate a .env file in the root folder:
OPENAI_API_KEY=your_openai_api_key
pip install -r requirements.txtpython data/init_db.pyThis will create sample_financial_data.db with mock transactions.
python main.pyThen enter questions like:
- "What were my grocery expenses in January?"
- "Total salary received in 2024?"
LangGraph allows stateful orchestration between agents. Here it's used to:
- Trigger the query agent
- Manage memory and execution flow
- Automatically translates user queries into optimized SQL
- Uses
SQLDatabaseToolkitto explore schema and generate SQL - Uses
AgentType.ZERO_SHOT_REACT_DESCRIPTIONfor efficiency
- Stores and retrieves past context semantically
OpenAIEmbeddings+ FAISS power fast and relevant memory lookup
- Uses
ChatOpenAI(temperature=0)for deterministic query generation - Context is injected into the prompt dynamically
- Lightweight and easy to explore
- Schema:
CREATE TABLE transactions (
id INTEGER PRIMARY KEY,
date TEXT,
amount REAL,
category TEXT,
account TEXT
);- Add multi-table schema support
- Integrate LangSmith for debugging
- Expose via REST API or Streamlit UI
- Add user authentication and persistent memory
Crafted by Adad — Machine Learning Engineer.
Need help deploying this project or scaling it with real data? Feel free to ask!