The-Myth/DeepThinkers
๐ง Email Triage OpenEnv
An OpenEnv benchmark environment where AI agents learn to prioritize, categorize, and route emails using contextual understanding. Agents interact with realistic email scenarios and receive reward signals that encourage accurate triage decisions.
๐งฉ Environment Description
Email triage is a high-value real-world task performed by operations teams, customer support, legal departments, and executives every day. Poor email triage leads to missed SLA deadlines, legal exposure, revenue loss, and operational inefficiency.
This environment challenges agents to:
- Detect urgency and priority signals (sender authority, keywords, deadlines)
- Classify emails into business categories (support, billing, legal, etc.)
- Route emails to the correct team queue
- Extract concrete action items
- Identify compliance and legal risks (GDPR, HIPAA, DMCA, financial)
- Assign appropriate SLA deadlines
๐๏ธ Architecture
โโโ inference.py # Baseline inference script (required at root by OpenEnv spec)
โโโ validate.py # Pre-submission validation script
โโโ openenv.yaml # OpenEnv metadata and spec
โโโ Dockerfile # Container definition for HF Spaces
โโโ requirements.txt
โโโ test_environment.py # Self-contained test suite
โโโ run_local.sh # Local run script (Linux/Mac)
โโโ run_local.bat # Local run script (Windows)
โโโ .env.example # Sample environment variable config
โโโ server/
โ โโโ __init__.py
โ โโโ app.py # FastAPI HTTP server (OpenEnv API)
โ โโโ environment.py # Core env logic: reset/step/state
โ โโโ models.py # Pydantic typed models
โ โโโ graders.py # Task-specific grading functions
โโโ data/
โโโ __init__.py
โโโ emails.py # Data loader (loads JSON files dynamically)
โโโ easy.json # 8 ambiguous emails for priority-classification
โโโ medium.json # 6 emails for category-routing
โโโ hard.json # 5 high-stakes emails for full-triage-pipeline๐ Observation Space
Each observation contains:
๐ฏ Action Space
Agents submit a JSON object with any/all of these fields:
๐ Tasks
Task 1: priority-classification ๐ข Easy
Goal: Classify each email's urgency level and sentiment.
Graded fields: priority (85%), sentiment (15%)
Scoring:
- Priority uses an adjacency matrix โ adjacent priorities get partial credit (e.g.,
criticalโhigh= 0.5) - No penalty for missing optional fields
Dataset: 8 emails ranging from production outages to newsletter subscriptions
Expected baseline score: 0.60โ0.80
Task 2: category-routing ๐ก Medium
Goal: Classify priority + category, route to correct team, extract action items, identify risk flags.
Graded fields: priority (25%), category (30%), route_to (20%), action_items (15%), flags (10%)
Scoring:
- Category is exact match only
- Routing has partial credit for keyword overlap
- Action items scored by keyword coverage (โฅ50% match per item)
- Missing
escalateorlegal_riskflags incur penalty
Dataset: 6 emails including API issues, billing disputes, partnership inquiries, DMCA notices
Expected baseline score: 0.35โ0.60
Task 3: full-triage-pipeline ๐ด Hard
Goal: Complete end-to-end triage across all dimensions.
Graded fields: priority (20%), category (20%), route_to (15%), action_items (20%), sla_hours (10%), sentiment (5%), flags (10%)
Scoring:
- All 7 fields contribute to score
- Extra penalty (-0.15) for missing critical priority on critical-grade emails
- SLA tolerance varies by priority tier (critical: ยฑ2h, high: ยฑ8h, etc.)
Dataset: 5 high-stakes emails including HIPAA violations, M&A interest, ransomware attacks, GDPR requests
Expected baseline score: 0.20โ0.45
๐ Reward Function
Rewards are provided after every step (not just at episode end), enabling agents to learn from trajectory:
- Each email is an independent triage decision
- Reward = weighted sum of dimension scores โ penalties
- Penalties: false flag escalations, missing critical flags, misclassifying critical emails
- Episode score = mean reward across all steps (normalized to [0, 1])
Partial progress signals:
- Getting priority right earns reward even if category is wrong
- Correct action items earn reward even with wrong routing
- Adjacent priorities get partial credit
๐ Setup & Usage
Local Development
# Clone the repo
git clone https://huggingface.co/spaces/your-team/email-triage-env
cd email-triage-env
# Install dependencies
pip install -r requirements.txt
# Start the environment server
uvicorn server.app:app --host 0.0.0.0 --port 7860 --reload
# In another terminal, run the baseline inference script
export HF_TOKEN=your_token
export API_BASE_URL=https://router.huggingface.co/v1
export MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
python inference.pyDocker
# Build
docker build -t email-triage-env .
# Run the environment
docker run -p 7860:7860 email-triage-env
# Run inference against it
export ENV_BASE_URL=http://localhost:7860
python inference.pyRun a specific task
export EMAIL_TRIAGE_TASK=priority-classification # easy
export EMAIL_TRIAGE_TASK=category-routing # medium
export EMAIL_TRIAGE_TASK=full-triage-pipeline # hard
export EMAIL_TRIAGE_TASK=all # all three
python inference.py๐ API Reference
Example: Reset
curl -X POST http://localhost:7860/reset \
-H "Content-Type: application/json" \
-d '{"task": "priority-classification", "session_id": "my-agent"}'Example: Step
curl -X POST http://localhost:7860/step \
-H "Content-Type: application/json" \
-d '{
"action": {
"priority": "critical",
"category": "engineering",
"route_to": "engineering-oncall",
"action_items": ["page on-call engineer", "check monitoring dashboard"],
"sla_hours": 1,
"sentiment": "urgent",
"flags": ["escalate"],
"reasoning": "Production outage affecting all users"
},
"session_id": "my-agent"
}'๐ Baseline Scores
Tested with Qwen/Qwen2.5-72B-Instruct via HuggingFace router:
โ OpenEnv Compliance
- โ
Typed Pydantic models:
EmailObservation,TriageAction,TriageReward - โ
step(action)โ returns observation, reward, done, info - โ
reset()โ returns initial observation - โ
state()โ returns full episode state - โ
openenv.yamlwith full metadata - โ 3 tasks with deterministic graders, scores in [0.0, 1.0]
- โ Meaningful per-step reward (not just binary end-of-episode)
- โ
Baseline inference script (
inference.py) using OpenAI client - โ Dockerfile + HuggingFace Space deployment
- โ Runtime < 20 minutes, compatible with 2 vCPU / 8GB RAM
๐ Environment Variables
๐ License
MIT
