An autonomous analytics agent that investigates business questions by deciding what data to query, what statistical analyses to run, and generating executive-ready insight reports — all without human intervention between steps.
Built with Claude API + Tool Use (no LangChain dependency).
You give the agent a business question like:
"Investigate our business performance over the last 90 days. Are we growing or shrinking? Is there anything concerning? Which channels are most efficient? Give me a report I can present to leadership."
The agent autonomously:
- Queries the database to understand what data is available
- Pulls relevant metrics (subscribers, revenue, churn, channel performance)
- Runs statistical analyses (trend detection, t-tests, correlations)
- Identifies anomalies and root causes
- Generates a formatted executive report with findings and recommendations
The key: the AI decides the steps, not the developer. The agent reasons through the problem, picks the right tools, and iterates until it has a complete answer.
User Question
│
▼
┌─────────────┐
│ Claude AI │ ◄── The "brain" that reasons and decides
│ (Agent) │
└──────┬──────┘
│ decides which tool to use
▼
┌──────────────────────────────────┐
│ Tool Layer │
│ │
│ run_sql_query() ← Query database
│ run_statistical_analysis() ← Trend, t-test, correlation
│ generate_report() ← Executive report
│ │
└──────────────────────────────────┘
│ results sent back to Claude
▼
┌─────────────┐
│ Claude AI │ ◄── Reviews results, decides next step
│ (Agent) │ or generates final report
└─────────────┘
│
▼ (loops until done)
Final Report
The heart of the workflow is a simple loop:
while not done:
response = claude.generate(messages, tools)
if response.stop_reason == "end_turn":
# Agent is done, return final answer
break
for tool_call in response.tool_calls:
result = execute_tool(tool_call)
messages.append(result) # Feed back to ClaudeClaude receives the question, decides what tool to call first, gets the results back, thinks about what to do next, and keeps going until it has enough information to answer. This is what makes it "agentic" — the AI controls the flow, not hardcoded logic.
| Tool | What It Does | When the Agent Uses It |
|---|---|---|
run_sql_query |
Executes SQL against the database | To pull metrics, explore tables, filter data |
run_statistical_analysis |
Runs trend, comparison, correlation, summary stats | To validate patterns, test significance |
generate_report |
Creates formatted executive report | When analysis is complete |
The agent typically takes 5-10 steps to complete an analysis:
--- Agent Step 1 ---
Tool: run_sql_query
Purpose: Understand available data and date range
--- Agent Step 2 ---
Tool: run_sql_query
Purpose: Pull weekly subscriber and revenue trends
--- Agent Step 3 ---
Tool: run_statistical_analysis
Analysis: Testing for significant trend in churn rate
--- Agent Step 4 ---
Tool: run_sql_query
Purpose: Channel performance comparison for acquisition efficiency
--- Agent Step 5 ---
Tool: run_statistical_analysis
Analysis: Comparing pre-March vs March churn rates
--- Agent Step 6 ---
Tool: generate_report
Report: Q1 2026 Business Performance Analysis
AGENT COMPLETED in 6 steps
- Python 3.9+
- Anthropic API key
pip install anthropic pandas numpy scipy
export ANTHROPIC_API_KEY="your-key-here"python analytics_agent.pyThe script creates a sample SQLite database with 90 days of simulated business data (subscribers, revenue, channel performance, customer segments) and runs the agent against it.
Modify the questions list in the script or call the agent directly:
from analytics_agent import run_analytics_agent, create_sample_database
create_sample_database()
run_analytics_agent("Why did churn spike in March? Root cause it.")
run_analytics_agent("Which customer segment should we prioritize for retention?")
run_analytics_agent("Compare channel efficiency and recommend budget reallocation.")
run_analytics_agent("Is there a correlation between support ticket volume and churn?")- Claude claude-sonnet-4-20250514 — The AI brain (reasoning, tool selection, report generation)
- Anthropic Python SDK — API client with native tool use support
- SQLite + Pandas — Data storage and manipulation
- SciPy — Statistical analysis (regression, t-tests, correlation)
- No LangChain — Built directly on the Claude API for full transparency
This project uses Claude's API directly to show the agentic pattern clearly without framework abstraction. The loop is ~30 lines of Python. You can see exactly how the agent reasons, calls tools, and iterates. Once you understand this pattern, adding LangChain or LangGraph for more complex workflows is straightforward.
Vineet Dalal — Data Scientist with 12+ years of experience in analytics, statistical modeling, and AI-enabled solutions.
- Email: vineet.dalal.work@gmail.com
- LinkedIn: linkedin.com/in/vineet-dalal
- GitHub: github.com/vineetbuilds