CoolFace
Apppublic

The-Myth/DeepThinkers

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

๐Ÿ“ง 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:

FieldTypeDescription
email_idstringUnique email identifier
subjectstringEmail subject line
senderstringSender email address
sender_domainstringSender's domain (credibility signal)
bodystringFull email body text
timestampstringISO 8601 timestamp
thread_lengthintNumber of emails in thread
has_attachmentsboolWhether attachments are present
stepintCurrent step number
previous_actionslistLast 3 actions for context
feedbackstringFeedback from previous step
task_namestringActive task name

๐ŸŽฏ Action Space

Agents submit a JSON object with any/all of these fields:

FieldTypeValues
priorityenumcritical, high, medium, low
categoryenumsupport, billing, sales, legal, hr, engineering, spam, other
route_tostringTeam queue name (e.g., "legal-team", "engineering-oncall")
action_itemslist[str]Concrete actions to take
sla_hoursintSLA deadline in hours
sentimentenumpositive, neutral, negative, urgent
flagslist[str]From: pii, legal_risk, financial, escalate
reasoningstringAgent's explanation

๐Ÿ“‹ 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 escalate or legal_risk flags 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

bash
# 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.py

Docker

bash
# 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.py

Run a specific task

bash
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

EndpointMethodDescription
/healthGETHealth check
/resetPOSTStart new episode
/stepPOSTSubmit triage action
/stateGETCurrent environment state
/tasksGETList all tasks

Example: Reset

bash
curl -X POST http://localhost:7860/reset \
  -H "Content-Type: application/json" \
  -d '{"task": "priority-classification", "session_id": "my-agent"}'

Example: Step

bash
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:

TaskDifficultyBaseline Score
priority-classificationEasy~0.58
category-routingMedium~0.51
full-triage-pipelineHard~0.58

โœ… 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.yaml with 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

VariableRequiredDescription
HF_TOKENYesHuggingFace API key
API_BASE_URLYesLLM API endpoint
MODEL_NAMEYesModel identifier
ENV_BASE_URLNoEnvironment server URL (default: http://localhost:7860)
EMAIL_TRIAGE_TASKNoTask to run: all, priority-classification, category-routing, full-triage-pipeline (default: all)

๐Ÿ“œ License

MIT