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.
User Query + Data Files
|
v
+-----------+ +----------+ +--------+ +----------+
| Analyzer |--->| Planner |--->| Coder |--->| Executor |
+-----------+ +----------+ +--------+ +----------+
|
+----------+----------+
v v
+----------+ +----------+
| Debugger | | Verifier |
| (max 3x) | +----------+
+----------+ |
+----------+----------+
v v
+----------+ +-----------+
| Router | | Finalyzer |---> Answer
+----------+ +-----------+
|
+---> Planner (refine loop)
| 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 |
- Analyzer profiles each uploaded file (column names, dtypes, shape, sample rows)
- Planner proposes the first analysis step based on the query and data summary
- Coder generates Python code implementing the plan
- Executor runs the code in a sandboxed subprocess
- If execution fails, Debugger fixes the code (up to 3 attempts, then moves on)
- If execution succeeds, Verifier checks whether the result answers the query
- If insufficient, Router decides whether to revise an existing step or add a new one, then loops back to Planner
- If sufficient, Finalyzer writes a clean final script and produces the answer
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.
- Run the agent on a batch of training samples (questions with known answers)
- Score each run using a multi-signal reward function (correctness, code execution, efficiency)
- Group trajectories into high-reward (good) and low-reward (bad) sets
- Meta-optimize - the LLM analyzes failure patterns and rewrites the planner/coder prompts
- Repeat - run again with updated prompts and measure improvement
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 |
Works with any LLM API (Azure OpenAI, GPT-4o, GPT-5.5). No GPU required.
python -m src.training.apo_local --rounds 3 --samples 5APO 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:
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.
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| 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 |
- LangGraph - agent orchestration via
StateGraphwith 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+
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.txtcp .env.example .envEdit .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
streamlit run app.py- Upload a CSV, Excel, or JSON file
- Ask a question about your data (e.g., "What is the total revenue by region?")
- Watch the agents collaborate in the Pipeline tab
- See the final answer in the Analysis tab
- Evaluate the reward signal in the RL Reward tab
- View APO training results in the Training tab
python -m src.training.apo_local --rounds 2 --samples 5This runs the agent on training samples, optimizes prompts, and saves results to prompts_optimized.yaml.
| 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 |
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)
- DS-STAR: A Data Science Agent Framework using LLMs - Kwon et al., Google Research
- Microsoft Agent Lightning - RL framework for training AI agents
- LangGraph Documentation
- Azure OpenAI Service
MIT

