CoolFace
Apppublic

Grish2114/email-prioritization-env

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

Email Prioritization & Response — OpenEnv Environment

Python FastAPI Docker OpenEnv

Overview

This is a standard OpenEnv environment simulating corporate email triage. AI agents trained in this environment must learn to classify the urgency of incoming emails, route them to the correct internal department, and draft appropriate, professional replies.

This environment strictly adheres to the OpenEnv specification, providing deterministic step(), reset(), and state() API functions via a FastAPI backend, designed for seamless containerized deployment on Hugging Face Spaces.

Real-World Motivation

Every modern enterprise processes hundreds to thousands of emails daily from customers, partners, and internal staff. Misclassifying an urgent production outage or dropping a critical legal notice causes immense financial and reputational damage. This environment challenges AI agents with a highly realistic, measurable simulation of this exact problem, allowing researchers to evaluate an agent's reasoning, routing, and drafting capabilities safely.

Environment at a Glance

PropertyValue
DomainCorporate Email Triage
Tasks3 (Easy → Medium → Hard)
Episode Length10 emails per episode
ObservationEmail content + task context
Actionpriority + department + reply
RewardPartial credit, 0.0–1.0 per step
Baseline Modelclaude-sonnet-4-20250514

Tasks

#NameDifficultyAction RequiredThreshold
1Priority ClassificationEasypriority only0.75
2Priority + RoutingMediumpriority + department0.65
3Full ResponseHardpriority + department + reply0.55

Reward Function

Rewards are calculated using a cumulative partial credit system designed to naturally guide policy learning.

  • —Task 1: score = priority_score / 0.4 (normalized)
  • —Task 2: score = (priority_score + dept_score) / 0.7 (normalized)
  • —Task 3: score = priority_score + dept_score + reply_score (direct sum, max 1.0)

Penalties (applied directly to the raw priority score): | Mistake | Penalty | |---------|---------| | Urgent classified as Low | -0.2 | | Low classified as Urgent | -0.1 | | Off-by-one priority | -0.05 |

Action Space

FieldTypeValuesTasks
prioritystringurgent, normal, lowAll
departmentstringbilling, technical, hr, general2, 3
replystringAny text (30+ words recommended)3 only

Observation Space

FieldTypeDescription
email_idstringUnique ID (E001-E030)
subjectstringEmail subject
bodystringFull email body
senderstringSender address
timestampstringISO-8601 datetime
task_idintActive task (1-3)
task_descriptionstringAgent instructions
inbox_remainingintEmails left this episode
episode_stepintCurrent step (0-indexed)

API Endpoints

MethodEndpointDescription
GET/healthHealth check
POST/resetStart new episode
POST/stepTake action, get reward
GET/stateCurrent environment state
GET/tasksList tasks + action schema
POST/graderScore standalone action
POST/baselineRun Claude agent, get scores

Quick Start

Local

bash
git clone <repo-url>
cd email-env
pip install -r requirements.txt
uvicorn api.server:app --host 0.0.0.0 --port 7860

Docker

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

Test the API

bash
# Health check
curl http://localhost:7860/health

# List tasks
curl http://localhost:7860/tasks

# Start episode
curl -X POST http://localhost:7860/reset \
  -H "Content-Type: application/json" \
  -d '{"task_id": 1, "seed": 42}'

# Take a step
curl -X POST http://localhost:7860/step \
  -H "Content-Type: application/json" \
  -d '{"task_id": 1, "priority": "urgent", "department": "technical", "reply": ""}'

# Run baseline agent
curl -X POST http://localhost:7860/baseline \
  -H "Content-Type: application/json" \
  -d '{"api_key": "sk-ant-...", "tasks": [1,2,3], "seed": 42}'

Run Baseline Script

bash
export ANTHROPIC_API_KEY=sk-ant-...
python baseline/inference.py

Baseline Scores

TaskDifficultyAvg ScoreThresholdPass
1EasyTBD0.75TBD
2MediumTBD0.65TBD
3HardTBD0.55TBD

Project Structure

  • —api/server.py — FastAPI application providing standard endpoints.
  • —env/environment.py — Core OpenEnv logic (reset, step, state).
  • —env/graders.py — Deterministic reward mechanisms.
  • —env/models.py — Pydantic schemas enforcing input validation.
  • —env/tasks.py — Metadata describing the 3 difficulty tasks.
  • —env/data/emails.json — Evaluative corpus of 30 synthetic emails.
  • —baseline/inference.py — Python script executing the autonomous agent.
  • —tests/test_environment.py — 12 robust Pytest unit tests.
  • —openenv.yaml — Complete metadata specification file.
  • —main.py — Standard application entry point.
  • —Dockerfile — Configuration for direct Hugging Face Spaces deployment.

OpenEnv Spec Compliance

  • —[x] Real-world task simulation (corporate email triage)
  • —[x] Typed Pydantic models (Observation, Action, Reward)
  • —[x] step() / reset() / state() implemented
  • —[x] openenv.yaml with full metadata
  • —[x] 3 tasks with difficulty progression (easy/medium/hard)
  • —[x] Deterministic graders scoring 0.0-1.0
  • —[x] Partial credit reward function
  • —[x] Baseline inference script (Claude agent)
  • —[x] /baseline /grader /tasks endpoints
  • —[x] Dockerfile (HF Spaces compatible)
  • —[x] Deployed to Hugging Face Spaces