CoolFace
Apppublic

sumit01-sj/Email_Triage_OpenEnv

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

๐Ÿ“ง Email Triage OpenEnv

A production-grade reinforcement learning environment simulating real-world email triage and management โ€” the kind of work that takes hours of human attention every day in every company.

![OpenEnv Compatible](https://github.com/meta-pytorch/OpenEnv) ![Python 3.11+](https://python.org) ![License: MIT](LICENSE)


๐ŸŽฏ Motivation

Email overload is a universal workplace problem. Professionals spend 28% of their workday managing email. Effective triage โ€” classifying urgency, routing to the right team, detecting sensitive information, and crafting appropriate responses โ€” requires both domain knowledge and nuanced judgment.

This environment challenges agents to perform this full pipeline, providing rich incremental feedback and progressively harder tasks.


๐Ÿ—๏ธ Environment Overview

PropertyValue
Environment IDemail-triage-v1
TypeText / NLP
Tasks3 (easy โ†’ medium โ†’ hard)
Max Steps10 / 15 / 20
Reward Range[0.0, 1.0]
OpenEnv Compliantโœ…

๐Ÿ“‹ Action Space

Actions are JSON objects with the following types:

Action TypeRequired FieldsDescription
classifyemail_id, urgency, categoryAssign urgency + category to an email
routeemail_id, departmentRoute email to correct department
flag_piiemail_id, pii_fieldsFlag personally identifiable information
draft_responseemail_id, response_textWrite a professional response
submit_reportreportSubmit a summary triage report (hard task)
skipโ€”Take no action

Urgency levels: low | medium | high | critical

Categories: billing | support | inquiry | complaint | spam | hr | legal | internal

Departments: billing | technical-support | sales | hr | legal | general


๐Ÿ‘๏ธ Observation Space

Each observation is a JSON object containing:

json
{
  "inbox": [...],
  "processed": [...],
  "step": 3,
  "task_id": "email-triage-hard",
  "instructions": "...",
  "available_actions": ["classify", "route", "flag_pii", "draft_response", "submit_report", "skip"],
  "progress": 0.4,
  "errors": []
}

๐Ÿ“Œ Tasks

Task 1: Email Classification (Easy)

  • โ€”ID: email-triage-easy
  • โ€”Emails: 5 realistic business emails
  • โ€”Objective: Classify each email by urgency and category
  • โ€”Max Steps: 10
  • โ€”Score Threshold: 0.75

Task 2: Email Routing + PII Detection (Medium)

  • โ€”ID: email-triage-medium
  • โ€”Emails: 8 emails (HR, legal, enterprise sales scenarios)
  • โ€”Objective: Classify + route to correct department + flag any PII
  • โ€”Max Steps: 15
  • โ€”Score Threshold: 0.70

Task 3: Full Email Triage Pipeline (Hard)

  • โ€”ID: email-triage-hard
  • โ€”Emails: 10 emails including a CEO emergency and a regulatory compliance notice
  • โ€”Objective: Full pipeline: classify โ†’ route โ†’ PII โ†’ draft critical responses โ†’ submit summary report
  • โ€”Max Steps: 20
  • โ€”Score Threshold: 0.65

๐Ÿ† Reward Function

Rewards are incremental โ€” given after every action, not just at episode end.

ActionCorrectWrong
Classify urgency+0.05โ€“0.120
Classify category+0.03โ€“0.080
Route to department+0.04โ€“0.08โˆ’0.01
Flag PII (true positive)+0.06โ€“0.09โ€”
Flag PII (false positive)โ€”โˆ’0.03โ€“0.05
Draft response (critical)+0.00โ€“0.10โ€”
Draft response (spam/low)โ€”โˆ’0.02
Exceed max stepsโ€”โˆ’0.02/step
Invalid email_idโ€”โˆ’0.02โ€“0.03

๐Ÿ“Š Baseline Performance

TaskScoreStepsSuccess
email-triage-easy~0.825โœ…
email-triage-medium~0.7112โœ…
email-triage-hard~0.6319โœ…

๐Ÿš€ Setup & Usage

Local Setup

bash
git clone <your-repo>
cd email-triage-openenv
pip install -r requirements.txt
python server.py

Running Inference

bash
export HF_TOKEN="your-api-key"
export API_BASE_URL="https://api.openai.com/v1"
export MODEL_NAME="gpt-4.1-mini"
export TASK_ID="email-triage-hard"

python inference.py

Docker

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

๐Ÿ”Œ API Reference

EndpointMethodDescription
/healthGETHealth check
/tasksGETList all tasks
/resetPOSTStart a new episode
/stepPOSTExecute an action
/stateGETGet current state
/closePOSTEnd episode and get final score

๐Ÿงช Running Tests

bash
python -m pytest tests/ -v

40 tests covering: reset, all three tasks, grader accuracy, reward correctness, and edge cases.


๐Ÿ“ Project Structure

.
โ”œโ”€โ”€ inference.py          # Hackathon submission entry point
โ”œโ”€โ”€ server.py             # FastAPI OpenEnv HTTP server
โ”œโ”€โ”€ openenv.yaml          # Environment metadata
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ env/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ environment.py    # EmailTriageEnv (main class)
โ”‚   โ”œโ”€โ”€ models.py         # Pydantic models
โ”‚   โ”œโ”€โ”€ email_data.py     # Realistic email datasets + ground truth
โ”‚   โ””โ”€โ”€ graders.py        # Deterministic scoring functions
โ””โ”€โ”€ tests/
    โ””โ”€โ”€ test_environment.py