abhishekd17/spreadsheet-formula-env
Spreadsheet Formula Environment
An OpenEnv RL environment where AI agents learn to write spreadsheet formulas from natural-language instructions.
Overview
Given a data grid and a task description, the agent must produce the correct spreadsheet formula (e.g., =SUM(B2:B5), =VLOOKUP(D2,A2:B5,2,FALSE)). The environment evaluates formulas using a safe, sandboxed evaluator and provides partial-credit scoring.
Action Space
Example: =SUMIF(A2:A7,"East",D2:D7)
Observation Space
Tasks (3 Difficulty Levels)
Easy (4 tasks)
Basic aggregation formulas:
- SUM — total sales across rows
- AVERAGE — average quantity
- COUNT — count numeric entries
- MAX — find maximum value
Medium (4 tasks)
Conditional and lookup formulas:
- SUMIF — sum with single condition
- IF — conditional text output
- COUNTIF — count matching criteria
- SUMPRODUCT — weighted average calculation
Hard (4 tasks)
Advanced multi-step formulas:
- Nested IF — grade assignment with 5 tiers
- INDEX/MATCH or VLOOKUP — lookup from a table
- SUMPRODUCT with conditions — conditional revenue calculation
- COUNTIFS — multi-criteria counting
Grading (0.0 – 1.0 with Partial Credit)
The agent gets up to 3 attempts per task. Best score per task is kept.
Supported Formula Functions
SUM, AVERAGE, COUNT, COUNTA, MAX, MIN, IF, SUMIF, COUNTIF, COUNTIFS, SUMIFS, VLOOKUP, INDEX, MATCH, XLOOKUP, SUMPRODUCT, ROUND, ABS, CONCATENATE, LEN, UPPER, LOWER
Plus arithmetic (+, -, *, /), comparisons (>, <, >=, <=, <>, =), and string concatenation (&).
Setup
# Install dependencies
pip install openenv-core[core] openai requests
# Or with uv
cd spreadsheet_formula_env
uv syncRun Locally
# Start the environment server
cd spreadsheet_formula_env
uv run server
# In another terminal, run inference
export API_BASE_URL="https://api.openai.com/v1"
export MODEL_NAME="gpt-4o-mini"
export HF_TOKEN="your-api-key"
export ENV_URL="http://localhost:8000"
python inference.pyRun with Docker
cd spreadsheet_formula_env
docker build -t spreadsheet-formula-env -f server/Dockerfile .
docker run -p 8000:8000 spreadsheet-formula-envDeploy to Hugging Face Spaces
openenv push --repo-id your-username/spreadsheet-formula-envEnvironment Variables
Architecture
spreadsheet_formula_env/
├── models.py ← Pydantic types: Action, Observation, State
├── client.py ← WebSocket client
├── server/
│ ├── environment.py ← Core reset/step/state logic
│ ├── app.py ← FastAPI server
│ ├── tasks.py ← 12 task definitions with grids
│ ├── evaluator.py ← Safe formula parser & evaluator
│ ├── graders.py ← Partial-credit grading logic
│ └── Dockerfile
├── inference.py ← LLM agent script
├── openenv.yaml ← OpenEnv manifest
└── README.md