Spaces:
Configuration error
Download README.md from ManojR19/scalarhackathon: direct link, hf CLI and curl.
- Browser
- Download file 7.85 kB
-
https://huggingface.co/spaces/ManojR19/scalarhackathon/resolve/main/README.md
- Command line
-
hf download hf://spaces/ManojR19/scalarhackathon/README.md
-
curl -L -o README.md https://huggingface.co/spaces/ManojR19/scalarhackathon/resolve/main/README.md
EmailTriage OpenEnv π
Real-world email support triage benchmark for AI agents.
Agents learn to classify, prioritize, draft replies, and escalate critical issues β mirroring actual $10B/year customer support workflows.
π― Why Email Triage?
Every support team processes hundreds of emails daily β spam, urgent bug reports, feature requests, billing issues. Training AI agents on this task develops:
- Classification (spam vs. legit, priority levels)
- Judgment (when to escalate a P0 production outage vs. a feature request)
- Communication (drafting concise, relevant replies)
- Hierarchy (label before draft, escalate before reply)
No existing OpenEnv benchmark covers this domain. This fills a real gap.
ποΈ Tasks
| Task | Emails | Description | Key Skill |
|---|---|---|---|
| easy | 5 | Binary classify: spam or legit (low/med/high) | Pattern recognition |
| medium | 10 | Prioritize mixed inbox + delete spam | Urgency judgment |
| hard | 15 | Full triage: classify + draft replies + escalate P0s | Compositionality |
Grader Weights
| Metric | Easy | Medium | Hard |
|---|---|---|---|
| Label Accuracy | 0.6 | 0.5 | 0.3 |
| Spam Recall | 0.1 | 0.2 | 0.1 |
| Reply Relevance | 0.2 | 0.2 | 0.2 |
| Escalation Recall | β | β | 0.3 |
| Inbox Cleared | 0.1 | 0.1 | 0.1 |
π Baseline Scores
| Agent | Easy | Medium | Hard |
|---|---|---|---|
| Rule-Based (keyword) | 0.75 | 0.55 | 0.40 |
| GPT-4o-mini | 0.82 | 0.62 | 0.48 |
| Human (simulated) | 0.95 | 0.91 | 0.87 |
π Quick Start
Option 1: Docker (Recommended)
docker build -t email-triage .
docker run -p 7860:7860 email-triage
Option 2: Local Dev
python -m venv .venv
# Windows: .venv\Scripts\activate
# Mac/Linux: source .venv/bin/activate
pip install -r requirements.txt
uvicorn server.app:app --host 0.0.0.0 --port 7860 --reload
Option 3: HuggingFace Space
huggingface-cli login
huggingface-cli repo create email-triage --type space --sdk docker
git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/email-triage
git push hf main
π API Reference
Base URL: http://localhost:7860
Interactive docs: http://localhost:7860/docs
GET /tasks
List all tasks with descriptions and grader weights.
curl http://localhost:7860/tasks
POST /reset
Reset environment with a specific task.
curl -X POST http://localhost:7860/reset \
-H "Content-Type: application/json" \
-d '{"task": "easy"}'
Response:
{
"observation": {
"current_emails": [
{"id": "e1", "subject": "WIN $1000 NOW!!!", "body": "...", "sender": "...", "labeled": false}
],
"stats": {"total": 5, "unread": 5, "labeled": 0, "deleted": 0, "escalated": 0, "drafts": 0},
"history": [],
"done": false,
"step": 0
}
}
POST /step
Take one action in the environment.
# Label an email
curl -X POST http://localhost:7860/step \
-H "Content-Type: application/json" \
-d '{"action": "{\"type\": \"label\", \"email_id\": \"e1\", \"value\": \"spam\"}"}'
# Delete spam
curl -X POST http://localhost:7860/step \
-H "Content-Type: application/json" \
-d '{"action": "{\"type\": \"delete\", \"email_id\": \"e1\"}"}'
# Draft a reply
curl -X POST http://localhost:7860/step \
-H "Content-Type: application/json" \
-d '{"action": "{\"type\": \"draft\", \"email_id\": \"e2\", \"value\": \"We are investigating your issue immediately.\"}"}'
# Escalate a P0 (hard task)
curl -X POST http://localhost:7860/step \
-H "Content-Type: application/json" \
-d '{"action": "{\"type\": \"escalate\", \"email_id\": \"h1\"}"}'
Response:
{
"observation": {...},
"reward": 0.3,
"done": false,
"info": {"step": 1, "task": "easy", "action_applied": "delete"}
}
POST /grader
Score the current episode (0.0 β 1.0).
curl -X POST http://localhost:7860/grader -H "Content-Type: application/json" -d '{}'
Response:
{
"score": 0.74,
"breakdown": {
"label_accuracy": 0.8,
"spam_recall": 1.0,
"reply_relevance": 0.65,
"escalation_recall": 0.0,
"inbox_cleared": 1.0
},
"details": {"task": "easy", "steps_used": "5", ...}
}
GET /state
Full internal state for debugging.
GET /health
Health check β returns {"status": "ok"}.
π€ Action Space
{
"type": "label | draft | delete | escalate | archive",
"email_id": "string",
"value": "string (label value or reply text, optional)"
}
Action Details
| Action | value |
Effect | Reward |
|---|---|---|---|
label |
spam|low|med|high|escalate |
Tag email | +0.2 correct, -0.1 wrong |
delete |
β | Remove from inbox | +0.3 if spam, -0.4 if legit |
draft |
reply text | Write reply | +0.05 to +0.35 (keyword match) |
escalate |
β | Mark as P0 | +0.4 if P0, -0.2 if not |
archive |
β | Archive email | +0.05/+0.1, -0.1 for high |
π§ Escalation Mechanic (Hard Task)
The escalate action is unique to production-ready support workflows. Emails requiring escalation are P0 incidents:
- π΄ Production database corruption
- π΄ Security vulnerability (SQL injection, etc.)
- π΄ All-user authentication failures
Escalating correctly gives the highest reward (+0.4). Missing an escalation significantly hurts the hard task score (escalation recall weight: 0.3).
π§ͺ Running Tests
pytest tests/ -v
Expected: All 40+ tests pass.
π Running the Baseline
# Rule-based (no API key needed)
python baseline.py --mode rule
# LLM-based (requires OpenAI API key)
OPENAI_API_KEY=sk-... python baseline.py --mode llm
# Both modes
OPENAI_API_KEY=sk-... python baseline.py --mode both
π Project Structure
email-triage-env/
βββ openenv.yaml # OpenEnv manifest (tasks, schemas, metadata)
βββ models.py # Pydantic schemas (Email, Action, Observation, State)
βββ environment.py # Core env logic (step, reset, grader, reward shaping)
βββ baseline.py # Rule-based + GPT-4o-mini baseline agents
βββ requirements.txt # Pinned dependencies
βββ pyproject.toml # Package metadata
βββ Dockerfile # HF Spaces compatible (port 7860)
βββ .gitignore
βββ server/
β βββ __init__.py
β βββ app.py # FastAPI server (all endpoints)
βββ data/
β βββ inboxes.json # Task emails + ground truth (easy/medium/hard)
βββ tests/
β βββ __init__.py
β βββ test_env.py # 40+ TDD tests
βββ README.md
π Key Design Decisions
- No external LLM in grader β All scoring is deterministic (keyword match, exact label comparison). Reproducible, fair, fast.
- Shaped rewards β Dense reward signal every step (progress bonus + action quality). Agents learn incrementally.
- Escalation mechanic β Novel action not found in any existing benchmark. Models judgment under pressure.
- Seeded randomness β
random.seed(42)in reset guarantees reproducible episodes. - Hard penalties for irreversible mistakes β Deleting a legit email (β0.4) teaches caution.
π License
MIT License β free to use, modify, and distribute.