Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Asad-Ismail/query-analysis-plot-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Data Analysis and Visualization Agent

Intelligent data analysis system that converts natural language queries into SQL, executes them, generates insights, and creates visualizations.

Features:

  • Natural Language to SQL: Ask questions in plain English, get accurate SQL queries
  • Multi-Database Support: Works with Chinook, Can be extended to new databases easily
  • Intelligent Visualizations: Auto-generates appropriate charts (bar, line, pie, scatter)
  • Role-Based Security: Fine-grained table access control by user role
  • Conversation Memory: Multi-turn conversations with context awareness
  • Intent Classification: Distinguishes data queries from off-topic questions
  • Self-Healing/Correction SQL: Automatic retry with error correction on query failures
  • Observability: Langfuse integration for tracing and monitoring

Architecture:

We are using Langgraph framework to orchestrate the workflow for agents

LangGraph Workflow:

Logo

Key Components:

  • Intent Classifier: Routes queries (data_query, follow_up, off_topic)
  • Analysis Agent: Generates and validates SQL with structured outputs
  • Visualization Agent: Recommends and creates charts based on data characteristics.
  • Conversation Manager: Maintains session context for follow-ups
  • Permission Manager: Enforces role-based table access

Demo:

Click to watch the demo video

🚀 Quick Start

Installation:

# Clone the repository
git clone https://github.com/Asad-Ismail/query-analysis-plot-agent.git
cd query-analysis-plot-agent

# Install dependencies
pip install -r requirements.txt

# Or use uv (faster and recommended)
bash uv_install.sh

Configuration:

Create a .env file:

OPENAI_API_KEY=your_api_key_here
OPENAI_API_BASE=https://api.openai.com/v1  # Optional custom endpoint
LANGFUSE_SECRET_KEY = langfuse_secret_here
LANGFUSE_PUBLIC_KEY = langfuse_key_here
LANGFUSE_BASE_URL = langfuse_base_url

Dataset Setup:

Download one or more of the test sql database from here

Place them in the root data/ directory

Usage:

CLI Mode

# Single query
python cli.py "Show top 5 artists by sales" --database chinook

# Interactive mode
python cli.py -i --database chinook

Web Interface

# Start backend
python app.py

# Open frontend
open index.html

Access at http://localhost:5000

Example Queries:

# Simple retrieval
"Show me top 3 artists by revenue"

# Aggregation
"How many customers do we have in total?"

# Filtering
"List all customers who live in Berlin"

"Who are our top 5 customers by total spending?"

Testing:

# Run functional tests
pytest -s -v tests/test_functional_chinook.py

Tools Used

  • LangChain & LangGraph: Workflow orchestration
  • OpenAI GPT-40-mini: LLM for SQL generation and insights
  • Langfuse: Observability and tracing
  • Pandas: Data manipulation
  • Matplotlib: Visualizations
  • Flask: Web backend
  • SQLite: Database engine

About

LLM agent to query analyze and plot results

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published