CoolFace
Apppublic

training-monkey/dataoncallenv

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

DataOnCallEnv

An RL benchmark that simulates the workflow of an on-call data analyst debugging broken reports. The agent investigates realistic data pipeline bugs across three difficulty tiers — diagnosing root causes, writing corrected SQL, and earning a multi-dimensional reward score.

Why This Exists

AI agents are being deployed as data analysts. But there is no benchmark that measures whether these agents can actually debug — not just query. DataOnCallEnv fills that gap by simulating exactly the workflow a real on-call analyst performs, scored against deterministic ground truth.

Features

FeatureDescription
Partial ObservabilityTables are hidden at reset. Agent must call list_tables() to discover schema before inspecting or querying.
Query Cost BudgetEach tool has a fixed cost (run_sql=2.0, inspect_schema=1.0, etc). Total budget: 20.0 per episode.
Realistic LogsExpanded dbt pipeline logs (8–15 rows per task) with noise entries + Airflow DAG run history table.
Anti-CheatSELECT * blocked, results capped at 50 rows, minimum 2 tool calls before submit, memorized-answer detection.
Tiered EvaluationDiagnosis scored by depth of understanding (exact → category → symptom), not binary pass/fail.
DeterministicAll tasks and grading are fully deterministic. Same actions always produce the same score.

Tasks

IDDifficultyTitleRoot CauseOptimal StepsOptimal Cost
1EasyRevenue shows $0 for international salesCurrency code casing mismatch (USD vs usd) causes silent NULL JOIN57.0
2MediumMAU dropped 8% on Feb 1stUTC→local timezone migration double-counts events at month boundary710.0
3HardCloud Storage revenue overstated by 3.7xNon-unique key in product_promotions causes fanout on JOIN813.0

Action Space

Every action has tool, query, and an optional reasoning field (rewarded by the grader).

ToolQuery FormatCostDescription
list_tables""0.5Discover available tables (must be called first)
inspect_schema"table_name"1.0Column names and types for a discovered table
check_logs""1.0dbt pipeline changelog (ordered by most recent)
check_airflow""1.0Airflow DAG run history
run_sql"SELECT col FROM ..."2.0Execute a SELECT query (no SELECT *)
diff_report"date1,date2"1.5Compare revenue totals between two dates
submit"ROOT CAUSE: ... CORRECTED SQL: ..."0.0Submit diagnosis and fix. Ends episode.

Observation Space

json
{
  "task_id": 1,
  "result": { "...tool output..." },
  "steps_taken": 3,
  "done": false,
  "max_steps": 15,
  "cost_spent": 4.5,
  "budget_remaining": 15.5
}

Reward Function

ComponentRangeDescription
diagnosis_correct0.00–0.25Tiered: exact root cause (0.25), category match (0.15), symptom only (0.08)
fix_valid0.00–0.25Agent's proposed SQL returns correct output vs ground truth
efficiency0.00–0.15Combined step + cost efficiency relative to optimal
reasoning_quality0.00–0.10Fraction of actions that include a reasoning field
investigation_quality0.00–0.10Logical methodology: discovery → schema → logs → hypothesis → verify
false_positive_penalty0.00–0.15Deducted for irrelevant table access, duplicate queries, or cheating

Total: 0.0–1.0 (dense reward — every action contributes signal)

API Endpoints

MethodEndpointDescription
GET/healthHealth check, returns env metadata and version
GET/Root info with available endpoints
GET/tasksList all tasks with metadata
GET/stateFull current episode state
GET/docsInteractive Swagger UI
POST/resetStart a fresh episode. Body: {"task_id": 1}
POST/stepSend one action. Body: {"tool": "...", "query": "...", "reasoning": "..."}

Setup

Prerequisites

  • Python 3.10+
  • pip

Install and Run Locally

bash
git clone https://github.com/ajaypushparaj5/dataoncallenv.git
cd dataoncallenv
pip install -r requirements.txt

# Start the API server
uvicorn api.app:app --reload --port 8000

Quick API Test

bash
# Health check
curl http://localhost:8000/health

# Start Task 1
curl -X POST http://localhost:8000/reset \
  -H "Content-Type: application/json" \
  -d '{"task_id": 1}'

# Discover tables
curl -X POST http://localhost:8000/step \
  -H "Content-Type: application/json" \
  -d '{"tool": "list_tables", "query": "", "reasoning": "Discover available tables"}'

# Inspect schema
curl -X POST http://localhost:8000/step \
  -H "Content-Type: application/json" \
  -d '{"tool": "inspect_schema", "query": "sales", "reasoning": "Check sales table structure"}'

Run with Docker

bash
docker build -t dataoncallenv .
docker run -p 7860:7860 dataoncallenv

Run Baseline Inference

Requires an API key for an OpenAI-compatible inference provider.

bash
# Create .env file
cat > .env << EOF
HF_TOKEN=your_hf_token_here
API_BASE_URL=https://router.huggingface.co/v1
MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
EOF

python inference.py

Run Tests

bash
python test_env.py
# Expected: 36 passed, 0 failed

Environment Variables

VariableRequiredDefaultDescription
HF_TOKENYesHugging Face API token (used as OPENAI_API_KEY)
API_BASE_URLNohttps://router.huggingface.co/v1OpenAI-compatible inference endpoint
MODEL_NAMENoQwen/Qwen2.5-72B-InstructModel identifier for the inference provider

Hugging Face Spaces Deployment

  1. 1.Create a new Space on huggingface.co/new-space
  2. 2.Select Docker as the SDK
  3. 3.Upload the project files (or connect via Git)
  4. 4.Add HF_TOKEN as a secret in Space Settings
  5. 5.The Space will auto-build using the Dockerfile and expose the API on port 7860

Project Structure

dataoncallenv/
├── models.py          # Pydantic types: Action, Observation, Reward, EnvState
├── tasks.py           # Task definitions with ground truth and diagnosis tiers
├── database.py        # SQLite database builder, tool implementations, anti-cheat
├── environment.py     # Core RL env: partial obs, query costs, step/reset/state
├── graders.py         # Tiered scoring, investigation quality, penalties
├── inference.py       # Baseline agent using OpenAI-compatible API
├── test_env.py        # 36 integration tests
├── api/
│   └── app.py         # FastAPI server with /health, /reset, /step, /state
├── openenv.yaml       # OpenEnv spec metadata
├── Dockerfile         # HF Spaces container (port 7860)
├── requirements.txt   # Python dependencies
├── baseline_scores.json  # Reproducible baseline results
└── .env               # API credentials (not committed)

OpenEnv Spec

This environment implements the full OpenEnv specification:

  • Typed Pydantic models for Action, Observation, Reward, and EnvState
  • reset() / step() / state() API
  • openenv.yaml with full metadata
  • Minimum 3 tasks with agent graders (easy → medium → hard)
  • Scores in range 0.0–1.0 with partial progress signals
  • Deterministic evaluation
  • Baseline inference script with reproducible scores

Anti-Cheat Constraints

ConstraintEffect
SELECT * blockedAgent must specify columns explicitly
Row cap (50)Large result dumps are truncated
Min 2 tools before submitPrevents skipping investigation
Memorized-answer detectionCorrect diagnosis without investigation incurs penalty
Duplicate query penaltyRepeated identical queries are penalized
Irrelevant table penaltyAccessing tables unrelated to the task is penalized