CoolFace
Apppublic

rdx11py/email-triage-env

sourceHugging Facemitupdated 5mo agoView on Hugging Face
0likes
App README

๐Ÿ“ง Email Triage OpenEnv

A real-world OpenEnv environment simulating corporate inbox management. An AI agent must classify, prioritize, route, and reply to realistic business emails with increasing complexity across 3 tasks.

Why Email Triage?

Email triage is one of the most time-consuming knowledge-work tasks:

  • โ€”Knowledge workers spend 28% of their workday on email (McKinsey)
  • โ€”Misrouted emails cost enterprises significant time and money
  • โ€”Urgency misjudgment causes SLA breaches and customer churn

This environment provides a realistic, graded signal for training agents to handle real inbox management.


Environment Description

PropertyValue
DomainCorporate email triage
Tasks3 (easy โ†’ hard)
Emails1 / 10 / 25 per task
Actionsclassify, route, reply, archive, escalate, mark_spam, defer, flag
RewardContinuous [0.0, 1.0] per email
EpisodeDone when inbox empty or max steps reached

Observation Space

json
{
  "task_id": "string",
  "step_number": "int",
  "inbox": [
    {
      "id": "string",
      "subject": "string",
      "sender": "string",
      "sender_name": "string",
      "body": "string",
      "timestamp": "ISO8601",
      "has_attachment": "bool",
      "thread_id": "string"
    }
  ],
  "current_email": "EmailObject | null",
  "processed_count": "int",
  "pending_count": "int",
  "sla_breaches": "int",
  "escalated_count": "int",
  "done": "bool",
  "message": "string"
}

Action Space

json
{
  "action_type": "classify|route|reply|archive|escalate|mark_spam|defer|flag",
  "email_id": "string",
  "urgency": "critical|high|medium|low",
  "category": "support|sales|internal|spam|legal|finance|hr|engineering",
  "department": "string",
  "reply_text": "string | null",
  "reason": "string | null"
}

Tasks

Task 1 โ€” classify_urgency (Easy)

Goal: Given a single email, classify its urgency level and category.

  • โ€”Inbox size: 1 email
  • โ€”Max steps: 5
  • โ€”Graded on: urgency accuracy (60%), category accuracy (40%)
  • โ€”Expected baseline score: ~0.70

Task 2 โ€” triage_and_route (Medium)

Goal: Process 10 mixed emails โ€” classify each, route to correct department, and take appropriate action.

  • โ€”Inbox size: 10 emails
  • โ€”Max steps: 20
  • โ€”Graded on: urgency (30%), routing (30%), action choice (30%), reply quality (10%)
  • โ€”Expected baseline score: ~0.50

Task 3 โ€” inbox_zero (Hard)

Goal: Manage a realistic inbox of 25 emails with:

  • โ€”Duplicate thread detection
  • โ€”SLA deadline awareness
  • โ€”Spam filtering
  • โ€”Legal/finance escalations
  • โ€”Reply drafting for support queries
  • โ€”Inbox size: 25 emails
  • โ€”Max steps: 60
  • โ€”Graded on: urgency (20%), routing (20%), action (25%), reply quality (15%), duplicate detection (20%)
  • โ€”SLA breach penalty: -0.05 per breach
  • โ€”Expected baseline score: ~0.35

Reward Function

Each email action yields a composite reward:

reward = w_urgency ร— urgency_score
       + w_routing ร— routing_score
       + w_action  ร— action_score
       + w_reply   ร— reply_score
       + w_dup     ร— duplicate_score

Weights vary by task. All component scores โˆˆ [0, 1].

Partial credit is awarded for near-misses (e.g. predicting "high" for a "critical" email scores 0.5 rather than 0).

Penalties:

  • โ€”Archiving/deferring a critical email: action_score can go negative (โˆ’0.2)
  • โ€”SLA breach: โˆ’0.05 per breach from final score

Setup & Usage

Docker

bash
docker build -t email-triage-env .
docker run -p 7860:7860 email-triage-env

Local

bash
pip install -r requirements.txt
touch data/__init__.py
python server.py

API

bash
# Reset for a task
curl -X POST http://localhost:7860/reset \
  -H "Content-Type: application/json" \
  -d '{"task_id": "classify_urgency"}'

# Take a step
curl -X POST http://localhost:7860/step \
  -H "Content-Type: application/json" \
  -d '{
    "session_id": "<session_id>",
    "action": {
      "action_type": "escalate",
      "email_id": "e001",
      "urgency": "critical",
      "category": "engineering",
      "department": "engineering",
      "reason": "Production outage affecting all customers"
    }
  }'

# Get state
curl http://localhost:7860/state?session_id=<session_id>

# Validate spec compliance
curl http://localhost:7860/validate

Run Baseline

bash
# Start server in background
python server.py &

# Run inference
export HF_TOKEN=your_token
export MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
export API_BASE_URL=https://router.huggingface.co/v1
python inference.py

Baseline Scores (Qwen2.5-72B-Instruct)

TaskScoreStatus
classify_urgency~0.72โœ… PASS
triageandroute~0.51โœ… PASS
inbox_zero~0.38โœ… PASS
Overall~0.54โœ…

OpenEnv Spec Compliance

  • โ€”โœ… Typed Pydantic models: Observation, Action, Reward, State
  • โ€”โœ… reset() โ†’ clean state + initial observation
  • โ€”โœ… step(action) โ†’ observation, reward โˆˆ [0,1], done, info
  • โ€”โœ… state() โ†’ full episode state
  • โ€”โœ… openenv.yaml with metadata
  • โ€”โœ… GET /validate endpoint
  • โ€”โœ… 3+ tasks with graders (easy โ†’ medium โ†’ hard)
  • โ€”โœ… Partial reward signal (not just binary)
  • โ€”โœ… Dockerfile builds + HF Space deploys

License

MIT