| name | data-analysis-agent-business-intelligence |
| description | Use the Data Analysis Agent to perform natural language business analytics, auto-generate SQL queries, create visualizations, and produce business insights from Excel/CSV/databases |
| triggers | ["analyze sales data with natural language queries","generate charts and insights from business data automatically","connect to database and query with plain English","build data analysis agent for business intelligence","create interactive data visualizations with AI","auto-generate SQL from natural language questions","perform business analytics without writing SQL","build conversational BI dashboard with streaming output"] |
Data Analysis Agent — Business Intelligence Skill
Skill by ara.so — AI Agent Skills collection.
Data Analysis Agent is a conversational business intelligence system that enables non-technical users to perform data analysis through natural language. Users can upload Excel/CSV files or connect to databases, then ask questions in plain language. The system automatically understands intent, generates SQL, executes queries, recommends charts, and provides business insights with real-time SSE (Server-Sent Events) streaming output.
What It Does
- Natural Language Queries: Ask questions in plain English instead of writing SQL
- Auto SQL Generation: Converts natural language to optimized SQL queries
- Smart Visualization: Automatically recommends from 43+ chart types based on data patterns
- Multi-Source Support: Excel, CSV, SQLite, MySQL, PostgreSQL, SQL Server, Google Sheets
- Streaming Analysis: Real-time SSE output showing analysis progress
- Advanced Analytics: K-Means clustering, decision trees, outlier handling, decile analysis
- Report Generation: Export to Excel, Word, PowerPoint
- MCP Integration: Extend capabilities with Model Context Protocol tools
- Knowledge Base: Upload business documents to improve domain understanding
Installation
Method 1: Download Release Package (Recommended)
start.bat
chmod +x start.command
./start.command
Method 2: Clone from GitHub
git clone https://github.com/Zafer-Liu/Data-Analysis-Agent.git
cd Data-Analysis-Agent
pip install -r requirements.txt
python app.py
Method 3: One-Line Install
Windows (PowerShell):
iwr -useb https://raw.githubusercontent.com/Zafer-Liu/Data-Analysis-Agent/main/install.ps1 | iex
macOS/Linux:
curl -fsSL https://raw.githubusercontent.com/Zafer-Liu/Data-Analysis-Agent/main/install.sh | sh
data-analysis-agent
Configuration
LLM Setup
Configure your LLM provider in the web UI sidebar (⚙ icon):
providers = {
"deepseek": {
"base_url": "https://api.deepseek.com",
"model": "deepseek-chat",
"api_key": os.getenv("DEEPSEEK_API_KEY")
},
"openai": {
"base_url": "https://api.openai.com/v1",
"model": "gpt-4o-mini",
"api_key": os.getenv("OPENAI_API_KEY")
},
"anthropic": {
"base_url": "https://api.anthropic.com",
"model": "claude-3-5-haiku-20241022",
"api_key": os.getenv("ANTHROPIC_API_KEY")
}
}
Database Connection
MySQL/PostgreSQL:
mysql_connection = "mysql+pymysql://{username}:{password}@{host}:{port}/{database}"
postgres_connection = "postgresql://{username}:{password}@{host}:{port}/{database}"
import os
db_url = f"mysql+pymysql://{os.getenv('DB_USER')}:{os.getenv('DB_PASS')}@localhost:3306/sales_db"
Google Sheets:
Slash Commands
Core commands for specialized analysis:
/chart
/sql
/analyze
/tree
/kmeans
/data
/inset
/winsorize
/trimming
/export
/report
/ppt
/status
Code Examples
Natural Language Query
user_query = "What is the sales trend for the last 12 months?"
Programmatic API Usage
from flask import Flask
from modules.agent_core import analyze_query
import os
app = Flask(__name__)
llm_config = {
"provider": "deepseek",
"api_key": os.getenv("DEEPSEEK_API_KEY"),
"base_url": "https://api.deepseek.com",
"model": "deepseek-chat"
}
def query_data(question, data_source):
"""
Question: Natural language query
data_source: Path to CSV/Excel or database connection string
"""
result = analyze_query(
question=question,
data_source=data_source,
llm_config=llm_config,
stream=True
)
return result
response = query_data(
question="Which region has the highest profit?",
data_source="./data/sales_data.csv"
)
Chart Generation
user_input = "/chart user growth over time"
Advanced Analytics: K-Means Clustering
query = "/kmeans segment customers by purchase behavior"
MCP Tool Integration
mcp_config = {
"enabled": True,
"tools": [
{
"name": "calculator",
"endpoint": "http://localhost:8000/mcp/calculator"
},
{
"name": "code_executor",
"endpoint": "http://localhost:8000/mcp/execute"
}
]
}
Knowledge Base Integration
query = "Analyze Q4 sales using last year's strategic priorities"
Common Patterns
Pattern 1: Time Series Analysis
"Show me monthly revenue trend with year-over-year comparison"
"""
SELECT
DATE_FORMAT(order_date, '%Y-%m') as month,
SUM(revenue) as current_revenue,
LAG(SUM(revenue), 12) OVER (ORDER BY DATE_FORMAT(order_date, '%Y-%m')) as prev_year_revenue,
((SUM(revenue) - LAG(SUM(revenue), 12) OVER (ORDER BY DATE_FORMAT(order_date, '%Y-%m'))) /
LAG(SUM(revenue), 12) OVER (ORDER BY DATE_FORMAT(order_date, '%Y-%m'))) * 100 as yoy_growth
FROM orders
GROUP BY month
ORDER BY month
"""
Pattern 2: Outlier Detection & Handling
query = "Find outliers in customer spending data"
query = "/winsorize cap extreme values at 5th and 95th percentile"
query = "/trimming remove values beyond 3 standard deviations"
Pattern 3: Cohort Analysis
query = "Create cohort analysis for user retention by signup month"
Pattern 4: Export Workflow
"/export save cleaned data to Excel"
"/report create analysis report with all charts and insights"
"/ppt generate executive summary presentation"
Chart Types Reference
The system auto-selects from 43 chart types:
chart_categories = {
"COMPARING": [
"Bar_Chart", "Grouped_Bar_Chart", "Stacked_Bar_Chart",
"Diverging_Bar_Chart", "Marimekko_ABS", "Waterfall", "Sankey_Chart"
],
"TIME": [
"Line_Chart", "Area_Chart", "Stacked_Area_Chart",
"Slope_Chart", "Bump_Chart", "Sparkline"
],
"DISTRIBUTION": [
"Histogram_Pareto_chart", "Box-and-Whisker_Plot",
"Violin_Chart", "Ridgeline_Plot", "Beeswarm_Plot"
],
"GEOSPATIAL": [
"Choropleth_Map", "Dot_Density_Map", "Flow_Map"
],
"RELATIONSHIP": [
"Scatter_Plot", "Bubble_Plot", "Network_Diagram",
"Chord_Diagram", "Parallel_Coordinates_Plot"
],
"PART-TO-WHOLE": [
"Pie_Chart", "Treemap", "Sunburst_Diagram", "Nightingale_Chart"
]
}
Troubleshooting
Issue: "LLM Not Configured"
Solution:
export DEEPSEEK_API_KEY="your-key-here"
Issue: Database Connection Failed
Solution:
connection_string = "mysql+pymysql://user:password@host:port/database"
import pymysql
conn = pymysql.connect(
host=os.getenv('DB_HOST'),
user=os.getenv('DB_USER'),
password=os.getenv('DB_PASS'),
database=os.getenv('DB_NAME')
)
conn.close()
Issue: Charts Not Displaying
Solution:
./outputs/charts/
Issue: Slow Query Performance
Solution:
"""
CREATE INDEX idx_order_date ON orders(order_date);
CREATE INDEX idx_customer_id ON orders(customer_id);
"""
Issue: Incorrect SQL Generation
Solution:
/sql SELECT region, SUM(amount) FROM sales WHERE YEAR(date) = 2024 GROUP BY region
Issue: Memory Error on Large Files
Solution:
import pandas as pd
chunks = pd.read_csv('large_file.csv', chunksize=10000)
for chunk in chunks:
pass
Advanced Usage
Custom Chart Configuration
def create_custom_chart(data, chart_type):
import plotly.graph_objects as go
fig = go.Figure()
fig.update_layout(
template="plotly_white",
title_font_size=20,
)
return fig
Extend Analysis Functions
def custom_analysis(df, params):
"""
Custom statistical analysis
"""
from scipy import stats
result = stats.ttest_ind(
df[params['group1']],
df[params['group2']]
)
return {
"statistic": result.statistic,
"p_value": result.pvalue,
"interpretation": "Significant" if result.pvalue < 0.05 else "Not significant"
}
Streaming Response Handler
import requests
def stream_analysis(query):
response = requests.get(
'http://localhost:5001/api/analyze',
params={'query': query},
stream=True
)
for line in response.iter_lines():
if line:
decoded = line.decode('utf-8')
if decoded.startswith('data: '):
data = decoded[6:]
print(data)
Environment Variables Reference
DEEPSEEK_API_KEY=your_deepseek_key
OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key
DB_HOST=localhost
DB_PORT=3306
DB_USER=your_username
DB_PASS=your_password
DB_NAME=your_database
GOOGLE_SHEETS_CREDENTIALS_PATH=/path/to/credentials.json
FLASK_PORT=5001
FLASK_ENV=production
Resources
- Repository: https://github.com/Zafer-Liu/Data-Analysis-Agent
- Documentation: See README.md and Information/ directory
- MCP Tutorial: Information/MCP_tutorial.md
- Knowledge Base Guide: Information/repository_tutorial.md
- Version History: Information/Version_Update_Log.md