Team Ai
Apppublic

Palak6106/email-sorting-openenv

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

Email Sorting OpenEnv ๐Ÿ“ง

A real-world OpenEnv environment where an AI agent learns to classify emails as spam, important, or promotion. Built for the Meta x PyTorch OpenEnv Hackathon.


What This Project Does

In today's world, people receive hundreds of emails daily. This environment trains an AI agent to automatically sort emails by reading the subject, body, and sender โ€” just like a smart inbox.

The agent learns:

  • โ€”Correct classification = reward
  • โ€”Wrong classification = penalty
  • โ€”Harder emails = higher reward (to encourage learning)

Environment Details

PropertyValue
Task TypeEmail Classification
Action Spacespam / important / promotion
Max Steps10 per episode
Reward Range-0.5 to +1.0
Difficulty LevelsEasy / Medium / Hard

Action Space

The agent can take exactly one of these actions per step:

ActionMeaning
spamEmail is unwanted, scam, or phishing
importantEmail needs attention (work, orders, real alerts)
promotionGenuine sale or discount from real shops

Observation Space

Each step the agent receives:

json
{
  "email": {
    "subject": "You won $1,000,000!",
    "body": "Click here to claim your prize.",
    "sender": "prize@randomsite.xyz"
  },
  "step": 1,
  "max_steps": 10,
  "total_reward": 0.0,
  "done": false,
  "valid_actions": ["spam", "important", "promotion"]
}

Tasks

TaskDifficultyDescriptionExpected Score
easy_sortingEasyClassify obvious spam vs important emails0.6 โ€“ 0.8
medium_sortingMediumDistinguish spam, promotion, and important0.5 โ€“ 0.7
hard_sortingHardDetect subtle phishing and tricky promotions0.4 โ€“ 0.6

Reward Function

EventReward
Easy correct+0.5
Medium correct+0.75
Hard correct+1.0
Easy wrong-0.5
Medium wrong-0.3
Hard wrong-0.1
Invalid action-0.2

Baseline Scores

Scores achieved by the rule-based baseline agent (baseline_agent in graders.py):

TaskScore
easy_sorting0.8
medium_sorting0.67
hard_sorting0.5
Average0.657

Setup & Usage

Local

bash
pip install -r requirements.txt
python server.py           # starts server at http://localhost:7860
python graders.py          # run graders with baseline agent
python inference.py        # run inference loop

Docker

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

API

bash
curl -X POST http://localhost:7860/reset
curl -X POST http://localhost:7860/step -H "Content-Type: application/json" -d '{"action":"spam"}'
curl http://localhost:7860/state
curl http://localhost:7860/graders

Environment Variables

VariableDescriptionDefault
API_BASE_URLLLM API base URLhttps://api.openai.com/v1
MODEL_NAMEModel to usegpt-4o-mini
HF_TOKENHuggingFace / API tokenโ€”