File size: 4,166 Bytes
a4842a8
 
 
 
 
 
 
 
 
eb2459b
 
 
a4842a8
 
eb2459b
fd10391
eb2459b
82ae7a6
eb2459b
fd10391
eb2459b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd10391
eb2459b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd10391
 
 
 
eb2459b
fd10391
 
eb2459b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82ae7a6
eb2459b
 
 
 
 
 
 
fd10391
eb2459b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
---
title: AI Code Review Environment
emoji: ๐Ÿ’ป
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
tags:
  - openenv
  - code-review
  - reinforcement-learning
  - ai-agent
---

# ๐Ÿ’ป AI Code Review Environment

> A production-grade OpenEnv environment where AI agents learn to review code like senior software engineers.

## ๐ŸŽฏ Overview

This environment simulates **real-world code review** โ€” one of the most critical tasks in software engineering. An AI agent is presented with code snippets and must identify bugs, security vulnerabilities, and quality issues across multiple programming languages.

This is not a toy problem. Code review is a skill that takes years for humans to master. This environment provides a structured way to train and evaluate AI agents on this task.

## ๐ŸŒ Supported Languages
| Language | Coverage |
|----------|----------|
| Python ๐Ÿ | Syntax, quality, security, bugs |
| JavaScript ๐ŸŒ | Security, quality, best practices |
| Java โ˜• | Null safety, resource management |

## ๐Ÿ“Š Task Difficulty Levels

### ๐ŸŸข Easy โ€” Syntax Detection
Agent must identify basic syntax errors.
- Missing colons, brackets, parentheses
- Baseline score: **0.85**

### ๐ŸŸก Medium โ€” Code Quality
Agent must identify quality issues.
- Poor naming, too many parameters
- Functions doing too many things
- Baseline score: **0.65**

### ๐Ÿ”ด Hard โ€” Security & Bugs
Agent must identify critical issues.
- SQL injection vulnerabilities
- Hardcoded passwords
- Division by zero
- Null pointer exceptions
- No error handling
- Baseline score: **0.45**

## ๐ŸŽฎ Action Space
| Field | Type | Range | Description |
|-------|------|-------|-------------|
| has_syntax_error | bool | true/false | Does code have syntax errors? |
| quality_score | float | 0.01-0.99 | Overall code quality |
| issues | list | 1-5 items | List of issues found |
| severity | str | low/medium/high | Overall severity |

## ๐Ÿ‘๏ธ Observation Space
| Field | Type | Description |
|-------|------|-------------|
| code_snippet | str | Code to review |
| language | str | Programming language |
| task_type | str | easy/medium/hard |
| task_description | str | What to look for |
| score | float | Score for last action |
| feedback | str | Detailed feedback |
| episode_step | int | Current step number |

## ๐Ÿ† Reward Function
| Correct Action | Reward |
|---------------|--------|
| Syntax detection | +0.30 |
| Severity assessment | +0.20 |
| Issues identified | +0.50 |
| **Maximum per step** | **0.99** |
| **Minimum per step** | **0.01** |

## ๐Ÿ“ˆ Baseline Results
| Task | Baseline Score | Difficulty |
|------|---------------|------------|
| Easy | 0.85 | Beginner |
| Medium | 0.65 | Intermediate |
| Hard | 0.45 | Expert |
| **Average** | **0.65** | - |

## ๐Ÿš€ API Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | /reset | Start new episode |
| POST | /step | Execute action |
| GET | /state | Get current state |
| GET | /schema | Get action/observation schemas |
| GET | /health | Health check |
| GET | /docs | Swagger UI |

## ๐Ÿ› ๏ธ Setup & Installation
```bash
pip install openenv-core
openenv init code_review
uvicorn server.app:app --host 0.0.0.0 --port 7860
๐Ÿค– Example Agent Interaction
import requests

# Reset environment
obs = requests.post('https://boobesh007-code-review.hf.space/reset').json()

# Take action
action = {
    'has_syntax_error': True,
    'quality_score': 0.8,
    'issues': ['missing colon after function definition'],
    'severity': 'high'
}
result = requests.post('https://boobesh007-code-review.hf.space/step', json=action).json()
print(result['reward'])
๐Ÿ“ Project Structure
code_review/
โ”œโ”€โ”€ models.py          # Action and Observation models
โ”œโ”€โ”€ inference.py       # Baseline inference script
โ”œโ”€โ”€ server/
โ”‚   โ”œโ”€โ”€ app.py         # FastAPI application
โ”‚   โ””โ”€โ”€ code_review_environment.py  # Environment logic
โ”œโ”€โ”€ Dockerfile         # Container configuration
โ””โ”€โ”€ README.md          # Documentation
๐Ÿ‘จโ€๐Ÿ’ป Built With
Python 3.11
FastAPI
OpenEnv Core
Pydantic
Docker
Hugging Face Spaces
๐Ÿ“œ License
BSD-3-Clause