Adityasharma4287/email-triage-grpo
012
๐ง Email Triage Agent โ GRPO Fine-tuned (Llama-3.1-8B)
A LoRA adapter for meta-llama/Llama-3.1-8B-Instruct, trained using GRPO (Group Relative Policy Optimization) to autonomously triage emails โ assigning priority, category, and action with human-level accuracy.
GRPO is the same RL technique used in DeepSeek-R1. Instead of supervised labels, the model learns by receiving reward signals from an environment โ just like how humans learn from feedback.
๐ง What This Model Does
Given an email (subject + sender + body), the model outputs:
๐๏ธ Training Details
Reward Function
The model was trained on a reward signal (not supervised labels):
reward = priority_score ร 0.35
+ category_score ร 0.25
+ action_score ร 0.30
+ sentiment_bonus (up to +0.08)
+ tag_bonus (up to +0.08)
- sla_breach_penalty (-0.15 if urgent email archived)
- urgent_archive_penalty (-0.35)๐ Quick Start
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
base_model = "meta-llama/Llama-3.1-8B-Instruct"
adapter = "Adityasharma4287/email-triage-grpo"
tokenizer = AutoTokenizer.from_pretrained(adapter)
model = AutoModelForCausalLM.from_pretrained(base_model, device_map="auto")
model = PeftModel.from_pretrained(model, adapter)
email = """
Subject: URGENT - Server is DOWN
From: cto@bigclient.com
Body: Our entire application is down. 50,000 users affected.
Need immediate response from engineering.
"""
messages = [
{"role": "system", "content": "You are an expert email triage agent. Classify the email and decide the best action."},
{"role": "user", "content": f"Triage this email:\n{email}\n\nRespond with JSON: priority, category, action, notes"}
]
input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
output = model.generate(input_ids, max_new_tokens=256, temperature=0.1)
print(tokenizer.decode(output[0][input_ids.shape[-1]:], skip_special_tokens=True))Expected output:
{
"priority": "urgent",
"category": "technical",
"action": "escalate",
"notes": "Production outage affecting 50k users. Immediate engineering response needed.",
"custom_tags": ["VIP"]
}๐ Benchmark Results
Scores measured on Email Triage OpenEnv v2.0 with seed=42
๐ Live Demo & Environment
๐ Advanced Features (v2.0 Environment)
The model was trained on an advanced environment with:
- โฑ SLA Tracking โ urgent emails with โค2h deadlines trigger extra penalties
- ๐ง Sentiment Scoring โ angry customers (-0.95 score) get urgency boost
- ๐ท๏ธ Custom Tags โ VIP, churn-risk, legal-review, follow-up
- ๐ค Snooze Action โ new action type for low-priority deferrals
- ๐ Multilingual โ Spanish email test cases included
- โ๏ธ Legal/HR Categories โ GDPR requests, lawsuit threats, HR emails
๐ Repository Structure
email-triage-grpo/
โโโ adapter_config.json โ LoRA config
โโโ adapter_model.safetensors โ Trained weights (27.3 MB)
โโโ tokenizer.json โ Llama-3.1 tokenizer
โโโ tokenizer_config.json
โโโ chat_template.jinja โ Chat prompt template
โโโ env/ โ Training environment
โ โโโ email_triage_env.py โ OpenEnv environment
โโโ smart_agent.py โ Agent inference script
โโโ inference.py โ Inference utilities๐ Training Your Own Agent
The full training environment is included. Run your own GRPO training:
git clone https://huggingface.co/Adityasharma4287/email-triage-grpo
cd email-triage-grpo
pip install -r requirements.txt
# Set env vars
export API_KEY="your-openai-or-local-key"
export MODEL_NAME="gpt-4o-mini" # or your local model
export ENV_BASE_URL="http://localhost:7860"
# Start the environment server
python app.py &
# Run the smart agent
python smart_agent.py๐ Citation
@misc{email-triage-grpo-2026,
title = {Email Triage Agent: RL Fine-tuning with GRPO on Llama-3.1-8B},
author = {Adityasharma4287},
year = {2026},
url = {https://huggingface.co/Adityasharma4287/email-triage-grpo},
note = {LoRA adapter trained with Group Relative Policy Optimization}
}โ ๏ธ Limitations
- Trained on synthetic email templates โ real-world email diversity may differ
- Best results with structured JSON output prompting
- Base model (Llama-3.1-8B) requires ~16GB VRAM for full inference; use 4-bit quantization for smaller GPUs
Built with โค๏ธ using GRPO + LoRA + OpenEnv
