Spaces:
Sleeping
Sleeping
|
Download README.md from Shivacode/rl-hackathon: direct link, hf CLI and curl.
- Browser
- Download file 8.73 kB
-
https://huggingface.co/spaces/Shivacode/rl-hackathon/resolve/main/README.md
- Command line
-
hf download hf://spaces/Shivacode/rl-hackathon/README.md
-
curl -L -o README.md https://huggingface.co/spaces/Shivacode/rl-hackathon/resolve/main/README.md
8.73 kB
metadata
title: Email Triage RL Environment
emoji: π§
colorFrom: blue
colorTo: indigo
sdk: docker
app_port: 7860
pinned: false
license: apache-2.0
short_description: RL env to classify, route and reply to emails
tags:
- openenv
- email-triage
- rl
- real-world
- nlp
- reinforcement-learning
- environment
π§ Email Triage Environment
Meta Γ PyTorch OpenEnv Hackathon β Round 1 An RL environment where an AI agent learns to triage real-world emails.
π― What Is This?
This environment simulates an email triage system β a task every business performs daily. An agent receives a queue of emails and must:
- Classify the email (spam / billing / technical / hr / general)
- Assign a priority (low / medium / high / urgent)
- Route to the correct department (support / finance / engineering / hr / management)
- Draft a professional reply (required for medium and hard tasks)
Rewards are continuous and partial β agents earn credit for getting each dimension right, incentivising learning even when the full answer isn't perfect.
ποΈ Action Space
| Field | Type | Values |
|---|---|---|
category |
string | spam Β· billing Β· technical Β· hr Β· general |
priority |
string | low Β· medium Β· high Β· urgent |
department |
string | support Β· finance Β· engineering Β· hr Β· management |
reply |
string | Free-text reply draft (empty string for easy tasks) |
ποΈ Observation Space
| Field | Type | Description |
|---|---|---|
email_id |
string | Unique email identifier |
subject |
string | Email subject line |
body |
string | Full email body |
sender |
string | Sender's email address |
task_level |
string | easy Β· medium Β· hard |
feedback |
string | Natural-language grader feedback |
score |
float | Cumulative average score (0.0β1.0) |
emails_remaining |
int | Number of emails left in the episode |
done |
bool | Episode complete flag |
reward |
float | Per-step reward (0.0β1.0) |
π Task Descriptions
π’ Easy β Classification Only
- 5 emails per episode (spam, billing, technical, HR, general)
- Agent must correctly classify category, priority, and department
- No reply required
- Score:
category(0.4) + priority(0.3) + department(0.3)
π‘ Medium β Classification + Short Reply
- 3 emails per episode (billing urgency, technical incident, HR complaint)
- Agent must classify AND write a professional 2-4 sentence reply
- Score:
classification(0.5) + reply_quality(0.5) - Reply graded on: professional tone, keyword coverage
π΄ Hard β Classification + Detailed Accurate Reply
- 3 emails per episode (enterprise escalations, security incidents, board complaints)
- Agent must classify AND write a detailed, accurate reply covering specific required points
- Score:
classification(0.4) + reply_depth(0.6) - Reply graded on: length, tone, keyword coverage (9 required keywords per email)
π Reward Function
Rewards are partial and continuous β agents earn credit at every step:
| Condition | Reward |
|---|---|
| Correct category | +0.15 β +0.40 |
| Correct priority | +0.13 β +0.30 |
| Correct department | +0.12 β +0.30 |
| Reply provided (non-trivial) | +0.05 β +0.10 |
| Professional tone in reply | +0.05 β +0.10 |
| Each required keyword matched | proportional |
| Missing reply on medium/hard | β0.10 penalty |
π Quick Start
1. Install dependencies
git clone https://huggingface.co/spaces/Shivacode/rl-hackathon
cd rl-hackathon
pip install -e email_triage_rl_hackathon/
2. Run the server locally
# Easy task (default)
uvicorn email_triage_rl_hackathon.server.app:app --host 0.0.0.0 --port 8000 --reload
# Medium task
TASK_LEVEL=medium uvicorn email_triage_rl_hackathon.server.app:app --port 8000
# Hard task
TASK_LEVEL=hard uvicorn email_triage_rl_hackathon.server.app:app --port 8000
3. Interact with the environment (Python)
import asyncio
from email_triage_rl_hackathon import EmailTriageEnv, TriageAction
async def main():
env = EmailTriageEnv(base_url="http://localhost:8000")
obs = await env.reset(seed=42, task_level="easy")
print(obs.subject)
result = await env.step(TriageAction(
category="billing", priority="urgent",
department="finance",
reply="Dear customer, we apologize and will investigate within 24 hours."
))
print(result.reward, result.observation.feedback)
await env.close()
asyncio.run(main())
4. Run with Docker
docker build -t email-triage-env .
docker run -p 7860:7860 -e TASK_LEVEL=easy email-triage-env
5. Run inference against this Space
HF_TOKEN=hf_your_token_here \
ENV_BASE_URL=https://Shivacode-rl-hackathon.hf.space \
TASK_LEVEL=easy \
python inference.py
π Scores (Qwen/Qwen2.5-72B-Instruct via HF Router)
| Task Level | Steps | Score |
|---|---|---|
| Easy | 5 | 0.880 |
| Medium | 3 | 0.830 |
| Hard | 3 | 0.800 |
| Overall | 0.837 |
ποΈ Project Structure
rl-hackathon/
βββ Dockerfile # HF Spaces Docker deployment (port 7860)
βββ inference.py # Run agent against this environment
βββ baseline.py # Baseline script (OpenAI models)
βββ email_triage_rl_hackathon/
βββ __init__.py # Public exports
βββ models.py # TriageAction, TriageObservation
βββ client.py # EmailTriageEnv (EnvClient)
βββ openenv.yaml # Environment manifest
βββ pyproject.toml # Package config + scripts entry point
βββ uv.lock # Locked dependencies
βββ server/
βββ app.py # FastAPI app (uvicorn entry point)
βββ my_environment.py # EmailTriageEnvironment (reset/step/state)
βββ email_data.py # 11 curated emails across 3 levels
βββ graders.py # Deterministic graders (easy/medium/hard)
βββ requirements.txt
π Environment Variables
| Variable | Default | Description |
|---|---|---|
TASK_LEVEL |
easy |
Task difficulty: easy / medium / hard |
PORT |
7860 |
Server port |
HF_TOKEN |
β | Required for inference.py (HF router) |
MODEL_NAME |
Qwen/Qwen2.5-72B-Instruct |
Model for inference |
ENV_BASE_URL |
http://localhost:8000 |
Environment server URL |
Structure
hackathon-sst/
βββ email_triage_rl_hackathon/
β βββ models.py β Action / Observation / State
β βββ client.py β EnvClient
β βββ server/
β β βββ my_environment.py β reset(), step(), state()
β β βββ app.py β FastAPI server
β βββ Dockerfile
β βββ openenv.yaml
βββ pyproject.toml
βββ .venv/ β Python virtual environment
Getting Started
# Activate venv
source .venv/bin/activate
# Install dependencies
pip install openenv-core fastapi uvicorn pydantic
# Run the server
uvicorn email_triage_rl_hackathon.server.app:app --reload --port 8000