π© Email Triage OpenEnv Environment
π Overview
This project implements a real-world Email Triage System as an OpenEnv-compatible environment, where an AI agent learns to classify and respond to emails using Reinforcement Learning (RL).
The system simulates tasks that humans perform daily:
- Categorizing emails (support, spam, sales, personal)
- Assigning priority (low, medium, high)
- Deciding actions (reply, archive, ignore)
- Generating appropriate responses
π― Objective
Build an intelligent agent that:
- Understands incoming emails
- Takes correct actions
- Learns from rewards over time
- Improves performance using RL
π§ Environment Design
π₯ Observation Space (State)
{
"subject": str,
"email_text": str,
"sender": str,
"task_type": str # easy | medium | hard
}
πΉ Action Space
The agent must return:
```json
{
"category": "support | spam | sales | personal",
"priority": "high | medium | low",
"action": "reply | archive | ignore",
"response": "string"
}
πΉ Reward Function
Reward is calculated based on correctness:
β
Category match β +0.4
β
Priority match β +0.2
β
Action match β +0.2
β
Response quality β +0.2
Penalties:
β Empty response β -0.1
β Invalid category β -0.1
Final score: 0.0 β 1.0
OpenEnv API
reset()
Loads a new email sample
Returns initial observation
step(action)
Evaluates agent action
Returns:
observation, reward, done, info
state()
Returns current environment state
Task Design
The environment includes 3 difficulty levels:
π’ Easy
Clean, structured emails
Clear intent
Example:
"I want a refund for my order"
π‘ Medium
Slight ambiguity
Requires interpretation
Example:
"The product quality is not good"
π΄ Hard
Noisy, informal, incomplete
Requires reasoning
Example:
"hey ordered last wkβ¦ no update π"
π Difficulty Progression
The environment increases complexity by introducing:
Typos and slang
Missing context
Ambiguous intent
Grader Design
The grader evaluates agent performance using:
Component Weight
Category 0.3
Priority 0.2
Action 0.2
Response 0.3
Features:
Handles synonyms and variations
Provides partial scores
Fully deterministic
π€ Agents
1. Gemini Agent
Uses Gemini API
Generates structured output
2. Rule-Based Agent
Simple keyword-based logic
Used as baseline
3. RL Agent (Q-Learning Inspired)
Learns from rewards
Stores state-action pairs
Improves over time via experience
Reinforcement Learning Loop
for episode in range(N):
state = env.reset()
action = agent(state)
_, reward, _, _ = env.step(action)
update_q(state, action, reward)
π Baseline Results
Agent Average Score
Gemini ~0.6β0.8
Rule-based ~0.4β0.6
RL Agent ~0.45-0.6
βοΈ Setup Instructions
1. Clone repository
git clone <your-repo>
cd email-triage-env
2. Install dependencies
pip install -r requirements.txt
3. Set API Key
Create .env file:
GEMINI_API_KEY=your_api_key_here
4. Run environment
python run.py
π³ Docker Setup
Build image
docker build -t email-env .
Run container
docker run email-env
π€ Hugging Face Deployment
Create a new Space
Select Docker template
Upload all project files
Add environment variable:
GEMINI_API_KEY
Deploy π
π Project Structure
Email-Triage/
β
βββ environment.py
βββ data.py
βββ agents.py
βββ rl_agent.py
βββ train.py
βββ run.py
βββ openenv.yaml
βββ Dockerfile
βββ README.md
Run locally
python run.py
Train RL agent
python train.py
## π API Key Setup
This project uses Gemini API for advanced email understanding.
Set your API key as an environment variable:
### Local
export GEMINI_API_KEY=your_api_key
### Docker
docker run -e GEMINI_API_KEY=your_api_key email-env
### Hugging Face Spaces
Add GEMINI_API_KEY in Space β Settings β Secrets
If no API key is provided, the system automatically falls back to a rule-based agent.
π Key Features
β
Real-world task simulation
β
OpenEnv compliant design
β
Reinforcement learning integration
β
Multi-agent comparison
β
Robust to API failures
β
Containerized deployment
π₯ Future Improvements
Use Deep Q-Learning instead of simple Q-table
Add memory/context across emails
Fine-tune LLM for domain-specific tasks
Improve reward shaping
π Conclusion
This project demonstrates how AI agents can:
Learn from interaction
Adapt to real-world scenarios
Improve decision-making over time
It bridges LLMs + RL + Environment Design, making it a strong foundation for intelligent automation systems.
Inference Providers NEW
This model isn't deployed by any Inference Provider. π Ask for provider support