trial1 / GUIDE.md
priyaaaaaasharmaaaaa's picture
Upload trained LoRA adapter from Kaggle
35e9f20 verified
|
Raw
History Blame Contribute Delete
10.2 kB
# πŸ“– Complete Guide β€” AI Sprint Manager OpenEnv
**What we built, how to test it, how to demo it, and how to explain it.**
---
## πŸ€” What Are We Building β€” Plain English
Imagine you're the Tech Lead of a software company. Every 2 weeks (called a "sprint"), your team gets a list of tasks β€” new features, bug fixes, tech debt. Your job is to decide:
- Which developer gets which task?
- What's most urgent when a new bug appears?
- What do you do when someone calls in sick?
- How do you avoid burning out your best developer?
**We built a simulation of this scenario** so an AI agent can practice making these decisions thousands of times and learn to get better β€” just like how AlphaGo learned to play Go by playing millions of games against itself.
The AI plays the role of the Tech Lead. It looks at the sprint state and decides what to do. The environment tells it how well it did (reward). Over time, it learns better strategies.
---
## πŸ—οΈ How It's Built β€” Layer by Layer
```
YOU / AI AGENT
↓ makes decisions (assign, skip, reprioritize...)
FASTAPI SERVER (ui.py / server/app.py)
↓ receives actions, returns results
SPRINT ENVIRONMENT (sprint_env/environment.py)
↓ core logic: tracks tasks, devs, days, rewards
DATA (data/sprint_data.json)
↓ tasks and developers β€” fully customizable
GRADIO UI (ui.py)
visual sprint board, charts, controls
```
---
## πŸ“ What Each File Does
| File | Purpose | Change it to... |
|------|---------|----------------|
| `data/sprint_data.json` | All scenario data | Add your own tasks/devs |
| `sprint_env/models.py` | Data contracts (Action/Observation/State) | Add new fields |
| `sprint_env/tasks.py` | Task & Developer classes | Add new task types |
| `sprint_env/environment.py` | Core RL logic | Change simulation rules |
| `sprint_env/graders.py` | Scoring (easy/medium/hard) | Change scoring weights |
| `sprint_env/data_loader.py` | Loads JSON data with caching | Point to custom data |
| `server/app.py` | OpenEnv HTTP API entry point | Add new endpoints |
| `client.py` | Typed Python client for RL training | Use in training scripts |
| `ui.py` | Gradio UI + combined server | Change UI layout |
| `inference.py` | Baseline LLM agent | Change model/strategy |
| `openenv.yaml` | OpenEnv spec metadata | Update task list |
---
## πŸ”„ What Happens Each Step
```
Day 1 β†’ Day 2 β†’ Day 3 β†’ ... β†’ Day 10 β†’ DONE
↑ ↑ ↑
agent agent agent
acts acts acts
```
**One step = one day in the sprint:**
1. Agent receives observation (all tasks, all devs, current day)
2. Agent picks an action (e.g. "assign T1 to dev1")
3. Environment validates the action
4. Developers work on assigned tasks β€” progress increases
5. Random events fire (dev goes sick, new bug appears)
6. Reward is calculated and returned
7. Repeat until Day 10 or all tasks resolved
---
## πŸ’° Reward Design β€” Why It Works for RL
The reward function is **shaped** (signal at every step) not **sparse** (only at the end):
```
Good actions β†’ positive reward immediately
Bad actions β†’ negative reward immediately
Task done on time β†’ bonus
Task missed deadline β†’ penalty
Sprint ends β†’ final_score Γ— 10 bonus
```
This means a learning agent gets feedback on every single decision β€” critical for efficient RL training with GRPO, PPO, or any policy gradient algorithm.
---
## βœ… How To Know Everything Is Working
### Quick 60-second check
```bash
# 1. Start server
python ui.py
# 2. In another terminal β€” health check
curl http://localhost:7860/health
# Expected: {"status":"ok","env":"ai-sprint-manager"}
# 3. Reset
curl -X POST http://localhost:7860/reset \
-H "Content-Type: application/json" \
-d '{"task_name":"easy_sprint","seed":42}'
# Expected: JSON with current_day=1, 5 tasks in backlog
# 4. Step
curl -X POST http://localhost:7860/step \
-H "Content-Type: application/json" \
-d '{"action":{"action_type":"assign","task_id":"T1","dev_id":"dev1"}}'
# Expected: reward around +1.2, T1 now in_progress
# 5. Validate
openenv validate
# Expected: [OK] ai-sprint-manager: Ready for multi-mode deployment
# 6. Run inference
python inference.py
# Expected: [START]/[STEP]/[END] lines, scores for all 3 tasks
```
### Full test checklist
| # | Test | How | Pass Condition |
|---|------|-----|---------------|
| 1 | Server health | `GET /health` | `{"status":"ok"}` |
| 2 | Reset works | `POST /reset` | day=1, tasks in backlog |
| 3 | Assign works | `POST /step` assign T1β†’dev1 | reward +1.2, T1 in_progress |
| 4 | Skill mismatch rejected | Assign backend task to frontend dev | reward -0.15, error message |
| 5 | Sprint ends | 10 skip steps | `done: true` |
| 6 | Grader runs | Check final_score in info | value between 0.0 and 1.0 |
| 7 | OpenEnv valid | `openenv validate` | `[OK]` message |
| 8 | Inference output | `python inference.py` | `[START]` `[STEP]` `[END]` lines |
| 9 | Docker build | `docker build .` | Exit code 0 |
| 10 | Docker run | `docker run -p 7860:7860 ...` then health | `{"status":"ok"}` |
| 11 | Live Space | `curl https://sejal-k-ai-sprint-manager.hf.space/health` | `{"status":"ok"}` |
| 12 | UI loads | Open http://localhost:7860 | Gradio UI visible |
| 13 | UI reset | Click Reset Sprint | Sprint board populates |
| 14 | Auto-assign | Click Auto-Assign All | Tasks move to in_progress |
| 15 | Reward chart | Take 3+ actions | Sparkline appears |
---
## 🎀 Project Demo Script (10 minutes)
### Before Demo
```bash
python ui.py
# Open http://localhost:7860 in browser β€” full screen
# Have terminal with inference.py output ready
```
### [0:00 β€” 1:30] The Problem
> "Software teams waste hours every sprint on planning. Which developer gets which task? What happens when someone goes sick? What if a critical bug appears on day 5? These decisions directly affect delivery speed and developer burnout."
> "We built an RL environment that simulates exactly this β€” so an AI agent can learn to make these decisions better."
### [1:30 β€” 3:00] Show the UI
- Select `easy_sprint` β†’ **πŸ”„ Reset Sprint**
- Point to sprint board: *"5 tasks in backlog, 3 developers, 10 day sprint"*
- Point to Skill Guide: *"This tells you which dev is right for which task. Backend tasks need Alice, frontend tasks need Bob."*
### [3:00 β€” 4:30] Manual Play β€” Good vs Bad Decision
- Assign T3 (frontend) β†’ dev1 (backend): *"Wrong skill β€” negative reward, task rejected"*
- Assign T3 (frontend) β†’ dev2 (frontend): *"Correct match β€” positive reward, task starts"*
- Point to reward chart: *"See the reward signal? This is exactly what the AI learns from."*
### [4:30 β€” 6:00] Auto-Assign
- Click **πŸ€– Auto-Assign All**
- *"Rule-based auto-assign picks the best skill match for every task."*
- Click **▢️ Take Action** (skip) a few times
- *"Each day the sprint advances, tasks progress, deadlines approach."*
### [6:00 β€” 7:30] Hard Sprint
- Reset with `hard_sprint`
- *"12 tasks, 5 developers, random events β€” developers go sick, urgent bugs appear mid-sprint."*
- Auto-assign, then skip a few times
- When a 🚨 event fires: *"There β€” urgent bug on day 4. A trained agent needs to react and reassign resources."*
### [7:30 β€” 9:00] Inference Output
- Show terminal with inference.py output
- *"This is our Llama 3.1 baseline running against all 3 scenarios automatically."*
- Point to structured output: *"`[START]` `[STEP]` `[END]` β€” machine-parseable format the judges require."*
- Point to scores: *"Easy sprint perfect score of 1.0 β€” validates the environment works. Hard sprint 0.0 β€” shows it genuinely challenges frontier models."*
### [9:00 β€” 10:00] Technical Highlights
> "What makes this submission stand out:"
- **Real-world domain** β€” not CartPole, not a game β€” actual software engineering
- **External data file** β€” `data/sprint_data.json` β€” anyone can plug in their own team
- **Typed Python client** β€” `client.py` makes it plug-and-play with TRL, Stable-Baselines3
- **OpenEnv compliant** β€” passes all 3 validation checks
- **Shaped rewards** β€” signal at every step, enables efficient RL training
---
## πŸ› Common Issues & Fixes
| Problem | Cause | Fix |
|---------|-------|-----|
| `ModuleNotFoundError` | Missing package | `pip install -r requirements.txt` |
| Port 7860 in use | Other process | Kill it or change port in ui.py |
| `401 Unauthorized` in inference | Bad HF token | Regenerate at hf.co/settings/tokens |
| Validate step 3 fails | openenv not in PATH | Activate venv before running script |
| Tasks not progressing | No devs assigned | Auto-Assign or assign manually |
| Score always 0.0 | All tasks missed | Assign earlier, prioritize urgent tasks |
| Docker timeout | venv in context | Check `.dockerignore` has `venv/` |
---
## πŸ”¬ Is This a Real RL Environment?
| Criterion | Our Environment |
|-----------|----------------|
| Sequential decisions | βœ… Each day depends on previous assignments |
| Large state space | βœ… Tasks Γ— Developers Γ— Day β€” combinatorial |
| Non-trivial action space | βœ… 5 types Γ— 12 tasks Γ— 5 devs |
| Shaped reward | βœ… Signal every step, not just episode end |
| Stochastic transitions | βœ… Random dev absences, mid-sprint bugs |
| Clean episode boundaries | βœ… reset() gives fresh state every time |
| Partial observability | βœ… Agent can't predict future events |
| Trainable with RL | βœ… GRPO / PPO / any policy gradient |
**A trained RL agent (not zero-shot LLM) should score 0.7+ on medium and 0.4+ on hard** after sufficient training β€” currently it scores 0.42 and 0.0 with baseline Llama 3.1. That's the gap RL training is meant to close.
---
## πŸ“Š Baseline Score Interpretation
```
easy_sprint: 1.00 ← LLM figured out skill matching perfectly
medium_sprint: 0.42 ← Partial success, random events hurt performance
hard_sprint: 0.00 ← Cascade failures overwhelm baseline LLM
average: 0.47
```
These scores are intentional and show the difficulty curve works correctly:
- Easy solvable by any agent β†’ environment is correct
- Medium shows partial success β†’ reward shaping works
- Hard challenges frontier models β†’ difficulty is genuine