⚠️ To view live inference results in the demo, please select Nvidia A100 Large GPU in HuggingFace Space Settings before running.
🎯 The Problem
Personal emails are not equal. A message from your manager about a missed deadline is completely different from a dinner invite from a friend. Yet most LLMs treat every email the same — they reply generically, miss urgency signals, use the wrong tone, and sometimes reply to emails that should never be replied to (like spam).
What we built: A 2-step RL environment where a model learns to first understand an email, then respond to it appropriately — rewarded by 6 independent verifiable functions.
Why RL? You cannot write ideal replies for every scenario in advance. But you can verify whether a reply is good: Does it have a proper greeting? Does it address the key points? Is the tone right? RL with verifiable rewards is the perfect fit.
Built with OpenEnv + FastAPI — fully OpenEnv spec compatible.
OpenEnv Interface
python
1env.reset(scenario_id=None)# Start new episode, receive email2env.step(action)# Submit classification or reply → get reward3env.state()# Current episode state for monitoring
Training starts with easy scenarios only → progressively adds medium → then hard. This ensures the model sees successful trajectories early and avoids zero-reward stalls.
🏆 7 Independent Reward Functions
Using multiple independent reward functions is the core defense against reward hacking. Here is every function implemented:
Step 1 Rewards — Classification (30% of Episode)
Reward 1: classification_accuracy — 21% of Episode Total
Target: 40–150 words
✅ 40-150 words → 1.0 (perfect)
⚠️ 25-40 words → 0.7 (short)
⚠️ 150-250 words → 0.7 (long)
❌ <25 words → 0.3 (too short)
❌ >250 words → 0.4 (too long)
Reward 6: tone_matching — 15% of Episode Total
Tone detected via lexical signals:
professional → "please", "kindly", "regards", "sincerely"
friendly → "hey", "cheers", "sounds great", "would love"
assertive → "I expect", "immediately", "by end of"
apologetic → "I apologize", "deeply sorry", "I take full responsibility"
Reward 7: reply_clarity — 15% of Episode Total
✅ Actionable signals (timelines, action verbs, coordination phrases)
❌ Penalizes vague filler ("noted", "will revert", "as soon as possible")
✅ Unique word ratio ≥ 0.55 (not repetitive)
Episode Total Formula
Episode = 0.30 × Step1_total + 0.70 × Step2_total
Reply quality is weighted 70% because drafting a contextually appropriate reply is the harder, more valuable task.
🛡️ Anti-Reward-Hacking Measures
1. 7 Independent Signals — Cannot game any one without the others catching it.
3. Duplicate Action Detection — Repeated identical actions are penalized.
4. Spam Safeguard — Spam emails reward not replying. Replying to spam scores 0.
5. Reply Clarity Guard — Penalizes vague "polite-only" hacks like "noted, will revert."
6. Real Discovery During Training:
During GRPO training, we discovered the model learned to output "reason": ["some text"] (a list) instead of "reason": "some text" (a string) to exploit our format reward. The field was "present" but not actually a valid string. We identified this as reward hacking and fixed reward functions to be type-safe — a real RL failure mode caught and resolved.
Reply quality improved dramatically across all metrics:
+44% reply format — Model learned to always include greeting + body + closing
+43% tone matching — Model learned to match professional/friendly/apologetic tone correctly
+38% reply length — Model learned to write replies of appropriate length
+36% reply relevance — Model learned to address actual content of the email
+21% overall episode — Significant improvement in end-to-end email handling
Classification slightly degraded (expected tradeoff):
The base Qwen model already classifies emails reasonably. GRPO focused reward signal on reply quality (70% weight) so the model optimized for the harder, more valuable task. This is an expected behavior in weighted RL.
The agent classifies the email and receives immediate reward feedback.
Step 1 Reward: 0.762 on a conflict resolution email.
Live Demo
Live Demo
Live Demo — Step 2: Reply Drafting
The agent drafts a contextually appropriate reply.
Episode Complete with Total Reward: 0.681
Live Demo
Before vs After Comparison
Side-by-side comparison of Baseline vs GRPO-Trained model on the same email.
Before After
Megha: Conflict email — Meeting overlaps with client call
Baseline
Trained (GRPO)
Reply
"Hi Megha, I understand there's an overlap... Could we possibly rearrange things..."
"Hello Megha, I understand your concern about overlapping commitments. Let's try to find a mutually convenient time... If it's possible, we could adjust the design sync to another day or hour that doesn't clash with the client call. Please let me know if there's anything else I can assist with regarding scheduling adjustments. Best regards, [Your Name]"
Episode Reward
0.614
0.694
Improvement
+0.080 ✅
The trained model's reply is more structured, uses proper closing ("Best regards"), is more specific about solutions, and scores higher on clarity and format.
Environment Info Tab
Full checklist of all hackathon requirements — all green ✅
Environment Info
✅ Hackathon Requirements Checklist
Requirement
Status
OpenEnv-compatible FastAPI server
✅
TRL GRPO training script
✅
Unsloth QLoRA efficiency
✅
Google Colab notebook
✅
7 independent reward functions
✅
Clarity guardrail against vague "polite-only" hacks