Skip to content

vineetbuilds/analytics-agent-agentic-workflow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Analytics Agent — Agentic Workflow for Business Intelligence

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).

What This Does

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:

  1. Queries the database to understand what data is available
  2. Pulls relevant metrics (subscribers, revenue, churn, channel performance)
  3. Runs statistical analyses (trend detection, t-tests, correlations)
  4. Identifies anomalies and root causes
  5. 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.

Architecture

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 Agentic Loop (Core Concept)

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 Claude

Claude 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.

Tools Available to the Agent

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

Sample Output

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

Setup

Prerequisites

  • Python 3.9+
  • Anthropic API key

Install

pip install anthropic pandas numpy scipy
export ANTHROPIC_API_KEY="your-key-here"

Run

python analytics_agent.py

The 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.

Try Different Questions

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?")

Tech Stack

  • 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

Why No LangChain?

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.

Author

Vineet Dalal — Data Scientist with 12+ years of experience in analytics, statistical modeling, and AI-enabled solutions.

About

AI-powered analytics agent that autonomously queries data, runs statistical analysis, and generates executive-ready reports. Built with Claude API + Tool Use. No LangChain dependency.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages