CSQL-Agent is an intelligent cricket analytics assistant powered by LangGraph and LangChain. It allows users to analyze cricket data through natural language queries, SQL generation, and data visualization.
This project implements a conversational AI system that can:
- Search for cricket-related entities (players, teams, grounds, etc.)
- Execute SQL queries against cricket databases
- Generate visualizations of cricket statistics
- Provide insights and analysis through a chat interface
The system follows an OpenAI-compatible API format, making it easy to integrate with various frontends.
The project is built with a modular agent-based architecture:
- Supervisor Agent: Orchestrates the workflow and routes queries to specialized agents
- Search Agent: Looks up specific entities in the cricket database
- SQL Agent: Generates and executes SQL queries to analyze cricket statistics
- Visualization Agent: Creates charts and graphs from cricket data
The system uses LangGraph to manage the agent workflows and state transitions.
- Natural Language Processing: Understands cricket-specific terminology and queries
- Database Integration: Connects to cricket databases with different schemas
- Multi-step Reasoning: Uses a supervisor to determine the optimal processing strategy
- Data Visualization: Creates charts and visualizations on demand
The system works with multiple cricket databases:
- hdata: Primary T20 Ball-By-Ball Database (includes IPL matches) from 2015 onwards
- ipl_hawkeye: IPL Hawkeye Data with detailed tracking data for IPL matches from 2022 onwards
- odata_2403: Mixed Format Ball-By-Ball Data covering Tests, FC, List A, ODI, T20, and T20I from 2019 onwards
- Python 3.9+
- Required packages listed in
requirements.txt
- Access to cricket databases
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables in
.env
file (see.env.example
for reference)
uvicorn backend.app.main:app --host=0.0.0.0 --port=8000
Or use the provided Procfile for deployment:
web: uvicorn backend.app.main:app --host=0.0.0.0 --port=$PORT
- User submits a query about cricket statistics
- Supervisor analyzes the query and routes to appropriate agent(s)
- Search agent verifies entities mentioned in the query
- SQL agent generates and executes appropriate database queries
- Visualization agent creates charts if needed
- Results are combined and presented to the user
The codebase is organized as follows:
agents/
- Contains all agent implementationssearch/
- Entity search functionalitysql/
- SQL generation and executionsql_with_preprocess/
- Enhanced SQL agent with preprocessingvisualiser/
- Data visualization capabilitiestools/
- Shared utilities for the agents
backend/
- FastAPI server implementationchatbot/
- Frontend chat interface
Built with:
- LangGraph
- LangChain
- FastAPI
- Google Gemini API (and other LLM providers) -Himanish Ganjoo for providing ball by ball dataset (https://x.com/hganjoo_153)