CoolFace
Apppublic

althafali/email-triage-env

sourceHugging Facebsd-3-clauseupdated 6mo agoView on Hugging Face
0likes
App README

๐Ÿ“ง Email Triage Environment

An OpenEnv environment simulating real-world email triage โ€” where an AI agent processes an inbox, classifying emails by urgency, setting priorities, archiving spam, and drafting professional replies.

![OpenEnv](https://github.com/meta-pytorch/OpenEnv) ![Python 3.10+](https://www.python.org/) ![License: BSD](LICENSE)


๐ŸŽฏ Motivation

Email overload is one of the most common productivity challenges in professional settings. The average knowledge worker receives 120+ emails per day and spends ~2.5 hours reading and responding. An AI agent that can intelligently triage emails โ€” sorting by urgency, filtering spam, and even drafting responses โ€” could save hours of human effort daily.

This environment provides a standardized testbed for evaluating how well AI agents handle this complex, multi-faceted task.


๐Ÿ—๏ธ Environment Description

The Email Triage Environment presents an AI agent with a simulated inbox of emails. The agent processes emails one at a time through the standard OpenEnv step() / reset() / state() API.

How It Works

  1. 1.`reset()` โ€” Initializes a new episode, loads the email dataset, returns the first email
  2. 2.`step(action)` โ€” Agent takes an action on the current email; receives the next email + reward
  3. 3.`state()` โ€” Returns episode metadata (progress, score, missed urgents, etc.)

Each email comes with ground-truth labels. The environment scores the agent's actions using a partial-credit reward function that rewards close guesses and penalizes critical mistakes (like missing an urgent email).


๐Ÿ“‹ Action Space

FieldTypeDescription
action_typeclassify \reply \archive \flag \escalate \skipWhat to do with the email
categoryurgent \follow_up \fyi \spam \meeting \approvalEmail classification
priority1 โ€“ 5 (1=lowest, 5=critical)Priority level
reply_contentstring (optional)Draft reply (required for reply action)
reasonstring (optional)Brief explanation of the decision

๐Ÿ‘๏ธ Observation Space

FieldTypeDescription
email_idstringUnique email identifier
senderstringSender email address
sender_domainstringSender's domain
subjectstringEmail subject line
bodystringFull email body
timestampstringISO timestamp
has_attachmentsboolWhether email has attachments
reply_tostring?Parent email if threaded
inbox_remainingintEmails left to process
emails_processedintEmails already handled
time_remainingfloatSeconds left in episode
task_descriptionstringInstructions for the agent
available_actionslist[str]Valid actions for this task

๐Ÿ“ Tasks

Task 1: Spam Detection (Easy)

  • โ€”Emails: 20
  • โ€”Time Limit: 2 minutes
  • โ€”Actions: classify only
  • โ€”Goal: Correctly identify spam vs. legitimate emails
  • โ€”Scoring: Binary accuracy (spam / not-spam)

Task 2: Multi-Label Categorization (Medium)

  • โ€”Emails: 30
  • โ€”Time Limit: 3 minutes
  • โ€”Actions: classify, flag, archive
  • โ€”Goal: Classify emails into 6 categories AND assign correct priority
  • โ€”Scoring: 60% category accuracy + 40% priority accuracy (with partial credit)

Task 3: Full Triage + Response Drafting (Hard)

  • โ€”Emails: 40
  • โ€”Time Limit: 5 minutes
  • โ€”Actions: classify, reply, flag, archive, escalate
  • โ€”Goal: Full professional email triage โ€” classify, prioritize, draft replies, handle urgents
  • โ€”Scoring: 40% category + 20% priority + 30% response quality + 10% urgency handling

๐Ÿ† Reward Function

Rewards provide partial credit throughout the episode (not just binary end scores):

ComponentPointsDescription
Category correct+0.50Exact category match
Category close+0.20Similar category neighborhood
Priority correct+0.30Exact priority match
Priority close (ยฑ1)+0.15Off by one
Action type correct+0.20Appropriate action chosen
Reply quality bonus+0.10Relevant keywords in drafted reply
Missing urgent-0.30Penalty for failing to identify urgent emails

๐Ÿš€ Setup & Usage

Prerequisites

  • โ€”Python 3.10+
  • โ€”pip

Installation

bash
# Clone the repository
git clone https://github.com/althafalimohommad/email-triage-env.git
cd email-triage-env

# Install dependencies
pip install -e .

Running the Server

bash
# Start the environment server
uvicorn server.app:app --host 0.0.0.0 --port 8000

# Or run directly
python -m server.app

Running the Inference Script

bash
# Set required env variables
export HF_TOKEN="hf_xxx"                 # Linux/Mac
$env:HF_TOKEN = "hf_xxx"                 # Windows PowerShell

# Run against local server
python inference.py

# Run against deployed HF Space
$env:ENV_URL = "https://althafali-email-triage-env.hf.space"
python inference.py

# Use a custom model
$env:MODEL_NAME = "meta-llama/Llama-3.3-70B-Instruct"
python inference.py

Using the Client

python
from email_triage_env import EmailTriageEnv, EmailTriageAction

with EmailTriageEnv(base_url="http://localhost:8000") as client:
    result = client.reset()
    print(f"First email: {result.observation.subject}")

    action = EmailTriageAction(
        action_type="classify",
        category="spam",
        priority=1,
        reason="Phishing attempt"
    )
    result = client.step(action)
    print(f"Reward: {result.reward}")

Docker

bash
# Build
docker build -f server/Dockerfile -t email-triage-env .

# Run
docker run -p 8000:8000 email-triage-env

๐Ÿ“Š Baseline Scores

TaskModelScore
Easy (Spam Detection)GPT-4~0.85
Medium (Multi-Label)GPT-4~0.72
Hard (Full Triage)GPT-4~0.58

Scores are approximate and may vary slightly between runs.


๐Ÿš€ Deploying to Hugging Face Spaces

This environment can be deployed as a containerized Hugging Face Space (required for submission).

Option A โ€” Using the OpenEnv CLI (recommended)

bash
# Install the CLI
pip install openenv-core

# Login to HF
huggingface-cli login

# Push to your HF account (tags the space with 'openenv' automatically)
openenv push --repo-id YOUR_HF_USERNAME/email-triage-env

Option B โ€” Manual Docker Build

bash
# Build locally
docker build -f server/Dockerfile -t email-triage-env .

# Test locally before pushing
docker run -p 8000:8000 email-triage-env

# Then create a Space at huggingface.co/new-space (type: Docker)
# and push with git
Tag your HF Space with openenv so it appears in the hackathon's leaderboard.

๐Ÿ“ Project Structure

email_triage_env/
โ”œโ”€โ”€ openenv.yaml              # Environment manifest
โ”œโ”€โ”€ pyproject.toml             # Python dependencies
โ”œโ”€โ”€ models.py                  # Pydantic models (Action, Observation, State)
โ”œโ”€โ”€ client.py                  # WebSocket client
โ”œโ”€โ”€ __init__.py                # Package exports
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ emails_easy.json       # 20 emails for spam detection
โ”‚   โ”œโ”€โ”€ emails_medium.json     # 30 emails for categorization
โ”‚   โ””โ”€โ”€ emails_hard.json       # 40 emails for full triage
โ”œโ”€โ”€ server/
โ”‚   โ”œโ”€โ”€ app.py                 # FastAPI application
โ”‚   โ”œโ”€โ”€ email_triage_env_environment.py  # Core environment logic
โ”‚   โ”œโ”€โ”€ email_generator.py     # Synthetic data generator
โ”‚   โ””โ”€โ”€ Dockerfile             # Container config
โ”œโ”€โ”€ tasks/
โ”‚   โ”œโ”€โ”€ task_easy.py           # Easy task grader
โ”‚   โ”œโ”€โ”€ task_medium.py         # Medium task grader
โ”‚   โ””โ”€โ”€ task_hard.py           # Hard task grader
โ”œโ”€โ”€ baseline/
โ”‚   โ””โ”€โ”€ inference.py           # Baseline LLM agent
โ””โ”€โ”€ README.md                  # This file

๐Ÿ”’ License

BSD License โ€” see LICENSE for details.