CoolFace
Apppublic

AMD21/codefixerenv

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

CodeFixerEnv ๐Ÿ”ง

An OpenEnv reinforcement learning environment for Python code-debugging tasks.

Built for the Meta ร— PyTorch ร— Hugging Face OpenEnv Hackathon โ€” Round 1.

What is CodeFixerEnv?

CodeFixerEnv is a reinforcement learning environment that teaches an AI agent how to debug Python code. The agent receives a buggy function, reads a description of what the function should do, and submits corrected code. The environment runs the code against a deterministic test suite, grades the submission on multiple weighted criteria, and returns a dense reward signal that guides the agent toward a correct and efficient solution.


Architecture

codefixer-final/
โ”œโ”€โ”€ env/
โ”‚   โ”œโ”€โ”€ models.py         โ† Pydantic: Observation, Action, Reward, StepResult
โ”‚   โ””โ”€โ”€ environment.py    โ† CodeFixerEnv class (reset / step / state)
โ”œโ”€โ”€ tasks/
โ”‚   โ””โ”€โ”€ tasks.py          โ† 3 tasks + deterministic graders
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ test_env.py       โ† 20 unit tests
โ”œโ”€โ”€ server.py             โ† FastAPI REST server (port 7860)
โ”œโ”€โ”€ inference.py          โ† Baseline agent using OpenAI client
โ”œโ”€โ”€ openenv.yaml          โ† OpenEnv spec metadata
โ”œโ”€โ”€ Dockerfile
โ””โ”€โ”€ requirements.txt

Observation Space

FieldTypeDescription
inputstrThe buggy Python code the agent must fix
contextstrPlain-English description of what the correct code should do
historylist[dict]Previous action/feedback pairs this episode
step_numberintSteps elapsed since reset
max_stepsintEpisode length cap (default 5)

Action Space

`type`Effect
"fix"Submit corrected code โ€” graded immediately
"explain"Request a hint โ€” costs โˆ’0.05 reward
"give_up"End episode early โ€” costs โˆ’0.10 reward

Reward Space

Dense rewards โ€” meaningful signal every step, not just at the end.

fix action:
  reward = grader_score โˆ’ previous_best   (improvement delta)
  +0.20 efficiency bonus if solved in โ‰ค 2 steps
  โˆ’0.05 if no improvement (redundancy penalty)

explain: โˆ’0.05
give_up: โˆ’0.10

Tasks

๐ŸŸข Easy โ€” sum_range(n)

Fix an off-by-one error. range(n) โ†’ range(1, n+1). Grading: syntax 20% + correctness 70% + no hardcoding 10%

๐ŸŸก Medium โ€” flatten(lst)

Fix two bugs in a nested list flattener. Grading: syntax 15% + correctness 75% + isinstance usage 10%

๐Ÿ”ด Hard โ€” longest_unique(s)

Rewrite O(nยฒ) brute-force as O(n) sliding window. Grading: syntax 10% + correctness 70% + linear complexity 20%


API Endpoints

MethodPathDescription
GET/healthLiveness check
POST/resetStart new episode {"difficulty": "easy"}
POST/stepSubmit action {"action_type": "fix", "action_content": "..."}
GET/stateInternal env state
GET/tasksList all tasks
GET/docsSwagger UI

Setup

bash
pip install -r requirements.txt
python server.py
# Server at http://localhost:7860

Docker

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

Running the Baseline Agent

bash
export API_BASE_URL=http://localhost:7860
export MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
export HF_TOKEN=hf_...
python inference.py

Running Tests

bash
python -m pytest tests/test_env.py -v
# Expected: 20 passed