Skip to content
HrushiYadavPublic

About

Multiagent data science system inspired by google's DS STAR paper.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

DS-Agents

Multi-agent data science system inspired by Google's DS-STAR research paper. 7 specialized AI agents collaborate to answer complex data analysis questions, built with LangGraph for orchestration and Azure OpenAI for inference.

The original paper (docs/ds-star-paper.pdf) proposes a multi-agent framework where agents iteratively plan, code, verify, and refine solutions to open-ended data science problems. This project reimplements that architecture using LangGraph's StateGraph with Azure OpenAI as the LLM backend and a Streamlit UI for interactive use.

Architecture

User Query + Data Files
         |
         v
   +-----------+    +----------+    +--------+    +----------+
   |  Analyzer  |--->|  Planner  |--->|  Coder  |--->| Executor  |
   +-----------+    +----------+    +--------+    +----------+
                                                       |
                                            +----------+----------+
                                            v                     v
                                      +----------+         +----------+
                                      | Debugger  |         | Verifier  |
                                      | (max 3x)  |         +----------+
                                      +----------+               |
                                                      +----------+----------+
                                                      v                     v
                                                +----------+         +-----------+
                                                |  Router   |         | Finalyzer  |---> Answer
                                                +----------+         +-----------+
                                                      |
                                                      +---> Planner (refine loop)

Agents

Agent Role
Analyzer Profiles uploaded data files: columns, types, stats, sample rows
Planner Creates an iterative step-by-step analysis plan
Coder Generates Python code to execute each plan step
Executor Runs generated code in a sandboxed subprocess
Verifier Checks if the current output sufficiently answers the query
Router Decides to revise an existing step or add a new one
Debugger Fixes code execution errors (max 3 attempts before moving on)
Finalyzer Produces the final answer code and executes it

How the loop works

  1. Analyzer profiles each uploaded file (column names, dtypes, shape, sample rows)
  2. Planner proposes the first analysis step based on the query and data summary
  3. Coder generates Python code implementing the plan
  4. Executor runs the code in a sandboxed subprocess
  5. If execution fails, Debugger fixes the code (up to 3 attempts, then moves on)
  6. If execution succeeds, Verifier checks whether the result answers the query
  7. If insufficient, Router decides whether to revise an existing step or add a new one, then loops back to Planner
  8. If sufficient, Finalyzer writes a clean final script and produces the answer

Agent Lightning RL Training

DS-Agents integrates Microsoft Agent Lightning for reinforcement learning-based prompt optimization. Instead of hand-tuning prompts, the system automatically evaluates agent performance and rewrites prompts to improve accuracy.

How it works

  1. Run the agent on a batch of training samples (questions with known answers)
  2. Score each run using a multi-signal reward function (correctness, code execution, efficiency)
  3. Group trajectories into high-reward (good) and low-reward (bad) sets
  4. Meta-optimize - the LLM analyzes failure patterns and rewrites the planner/coder prompts
  5. Repeat - run again with updated prompts and measure improvement

Reward Function

Each agent run produces a reward score in [0.0, 1.0]:

Signal Weight Description
Correctness 0.6 Fuzzy match of agent answer vs ground truth (exact, numeric tolerance, substring, word overlap)
Code execution 0.2 Did the generated code run without errors?
Efficiency 0.2 Fewer refinement rounds = higher score

RL Reward Evaluation

APO (Automatic Prompt Optimization)

Works with any LLM API (Azure OpenAI, GPT-4o, GPT-5.5). No GPU required.

python -m src.training.apo_local --rounds 3 --samples 5

APO runs the agent pipeline on training samples, collects reward scores, and uses the LLM itself to rewrite prompts based on failure patterns. In our first training run (2 rounds, 5 samples each), APO identified that the planner and coder prompts were blindly aggregating raw columns without validating data types or transaction grain. It rewrote 4 of 9 prompts to add data validation steps before aggregation:

APO Training Results

Training results (Round 1):

[1/5] Total revenue across all regions    -> 440760 (reward: 0.33)
[2/5] Highest revenue region              -> East   (reward: 1.00)
[3/5] Total profit for Widget A           -> 81900  (reward: 0.33)
[4/5] Units of Widget B sold              -> 980    (reward: 0.33)
[5/5] Average revenue per transaction     -> 18365  (reward: 0.33)
Average reward: 0.467

APO then analyzed the failures and updated planner_init, planner_next, coder_init, and coder_next prompts to enforce data cleaning and metric validation before aggregation. Optimized prompts are saved to prompts_optimized.yaml with a side-by-side diff in the Training tab.

VERL (RL with weight updates)

For local open-source models with GPU. Uses GRPO/PPO to update model weights directly.

python -m src.training.train --algorithm verl --model Qwen/Qwen2.5-7B-Instruct

v0.2.0 Changes

What changed from v0.1.0

Before (v0.1.0) After (v0.2.0)
New Azure client per LLM call Singleton client, reused across calls
_extract_code() duplicated in 5 files Shared utility in src/utils/shared.py
_summaries_str() duplicated in 5 files Shared utility in src/utils/shared.py
Debugger loops forever on persistent errors Max 3 debug attempts, then moves on
No training/optimization Agent Lightning RL integration (APO + VERL)
No reward evaluation Multi-signal reward function (correctness + execution + efficiency)
3-tab UI 5-tab UI with RL Reward and Training tabs
langchain-openai/langchain-core in deps Removed (never used, raw OpenAI SDK only)
No ground truth evaluation Training dataset with 12 Q&A pairs
Fixed prompts only APO auto-optimizes prompts based on reward signals

Tech Stack

  • LangGraph - agent orchestration via StateGraph with conditional edges
  • Azure OpenAI (AI Foundry) - LLM inference
  • Streamlit - interactive web UI with pipeline visualization
  • Agent Lightning - RL-based prompt optimization
  • Pandas - data processing
  • Python 3.11+

Quick Start

1. Clone and install

git clone https://github.com/HrushiYadav/ds-agents.git
cd ds-agents
python -m venv .venv
.venv/Scripts/activate   # Windows
# source .venv/bin/activate  # macOS/Linux
pip install -r requirements.txt

2. Configure Azure OpenAI

cp .env.example .env

Edit .env with your Azure AI Foundry credentials:

AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_API_KEY=your-api-key
AZURE_OPENAI_DEPLOYMENT=gpt-4o
AZURE_OPENAI_API_VERSION=2025-01-01-preview

3. Run the app

streamlit run app.py

4. Use it

  1. Upload a CSV, Excel, or JSON file
  2. Ask a question about your data (e.g., "What is the total revenue by region?")
  3. Watch the agents collaborate in the Pipeline tab
  4. See the final answer in the Analysis tab
  5. Evaluate the reward signal in the RL Reward tab
  6. View APO training results in the Training tab

5. Train with APO (optional)

python -m src.training.apo_local --rounds 2 --samples 5

This runs the agent on training samples, optimizes prompts, and saves results to prompts_optimized.yaml.

Differences from the Paper

DS-STAR Paper This Implementation
Gemini models Azure OpenAI
Sequential function calls LangGraph StateGraph with conditional edges
CLI only Streamlit web UI with pipeline visualization
Single provider Extensible provider pattern with base_url overrides
No UI feedback Real-time agent activity log
No training loop Agent Lightning RL with APO and VERL support
No debug limits Max 3 debug attempts per execution cycle

Project Structure

ds-agents/
├── app.py                    # Streamlit UI (5 tabs)
├── prompts.yaml              # Prompt templates for all agents
├── prompts_optimized.yaml    # APO-optimized prompts (generated)
├── .env.example              # Azure credentials template
├── requirements.txt
├── pyproject.toml
├── docs/
│   └── ds-star-paper.pdf     # Original DS-STAR research paper
├── data/
│   ├── sample_sales.csv      # Demo dataset
│   └── training_samples.json # Training Q&A pairs
└── src/
    ├── agents/               # Agent node implementations
    │   ├── analyzer.py
    │   ├── planner.py
    │   ├── coder.py
    │   ├── verifier.py
    │   ├── router.py
    │   ├── debugger.py
    │   └── finalyzer.py
    ├── graph/
    │   ├── state.py          # LangGraph TypedDict state + DSConfig
    │   └── workflow.py       # StateGraph with conditional routing
    ├── providers/
    │   └── azure.py          # Singleton Azure OpenAI client
    ├── training/
    │   ├── agent.py          # LitDSAgent (Agent Lightning wrapper)
    │   ├── apo_local.py      # Local APO trainer (no GPU needed)
    │   ├── reward.py         # Multi-signal reward function
    │   └── train.py          # CLI training script
    └── utils/
        ├── code_executor.py  # Sandboxed code execution
        ├── prompts.py        # Prompt template loader
        └── shared.py         # Shared utilities (extract_code, summaries_str)

References

License

MIT

About

Multiagent data science system inspired by google's DS STAR paper.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages