Views
No views yet
1{
2 "subject": str,
3 "email_text": str,
4 "sender": str,
5 "task_type": str # easy | medium | hard
6}
7
8🔹 Action Space
9
10The agent must return:
11```json
12{
13 "category": "support | spam | sales | personal",
14 "priority": "high | medium | low",
15 "action": "reply | archive | ignore",
16 "response": "string"
17}
18
19🔹 Reward Function
20
21Reward is calculated based on correctness:
22
23✅ Category match → +0.4
24✅ Priority match → +0.2
25✅ Action match → +0.2
26✅ Response quality → +0.2
27
28Penalties:
29
30❌ Empty response → -0.1
31❌ Invalid category → -0.1
32
33Final score: 0.0 → 1.0
34
35OpenEnv API
36reset()
37Loads a new email sample
38Returns initial observation
39
40step(action)
41Evaluates agent action
42Returns:
43
44observation, reward, done, info
45
46state()
47Returns current environment state
48
49Task Design
50
51The environment includes 3 difficulty levels:
52
53🟢 Easy
54Clean, structured emails
55Clear intent
56
57Example:
58
59"I want a refund for my order"
60
61🟡 Medium
62Slight ambiguity
63Requires interpretation
64
65Example:
66
67"The product quality is not good"
68
69🔴 Hard
70Noisy, informal, incomplete
71Requires reasoning
72
73Example:
74
75"hey ordered last wk… no update 😕"
76
77📈 Difficulty Progression
78
79The environment increases complexity by introducing:
80
81Typos and slang
82Missing context
83Ambiguous intent
84
85Grader Design
86
87The grader evaluates agent performance using:
88
89Component Weight
90Category 0.3
91Priority 0.2
92Action 0.2
93Response 0.3
94
95Features:
96Handles synonyms and variations
97Provides partial scores
98Fully deterministic
99
100🤖 Agents
1011. Gemini Agent
102Uses Gemini API
103Generates structured output
104
1052. Rule-Based Agent
106Simple keyword-based logic
107Used as baseline
108
1093. RL Agent (Q-Learning Inspired)
110Learns from rewards
111Stores state-action pairs
112Improves over time via experience
113
114Reinforcement Learning Loop
115
116for episode in range(N):
117 state = env.reset()
118 action = agent(state)
119 _, reward, _, _ = env.step(action)
120 update_q(state, action, reward)
121
122📊 Baseline Results
123Agent Average Score
124Gemini ~0.6–0.8
125Rule-based ~0.4–0.6
126RL Agent ~0.45-0.6
127
128⚙️ Setup Instructions
1291. Clone repository
130git clone <your-repo>
131cd email-triage-env
132
1332. Install dependencies
134pip install -r requirements.txt
1353. Set API Key
136
137Create .env file:
138
139GEMINI_API_KEY=your_api_key_here
140
1414. Run environment
142python run.py
143
144🐳 Docker Setup
145Build image
146docker build -t email-env .
147Run container
148docker run email-env
149
150🤗 Hugging Face Deployment
151Create a new Space
152Select Docker template
153Upload all project files
154Add environment variable:
155GEMINI_API_KEY
156
157Deploy 🚀
158📁 Project Structure
159Email-Triage/
160│
161├── environment.py
162├── data.py
163├── agents.py
164├── rl_agent.py
165├── train.py
166├── run.py
167├── openenv.yaml
168├── Dockerfile
169└── README.md
170
171Run locally
172python run.py
173
174Train RL agent
175python train.py
176
177## 🔐 API Key Setup
178
179This project uses Gemini API for advanced email understanding.
180
181Set your API key as an environment variable:
182
183### Local
184export GEMINI_API_KEY=your_api_key
185
186### Docker
187docker run -e GEMINI_API_KEY=your_api_key email-env
188
189### Hugging Face Spaces
190Add GEMINI_API_KEY in Space → Settings → Secrets
191
192If no API key is provided, the system automatically falls back to a rule-based agent.
193
194🏆 Key Features
195
196✅Real-world task simulation
197✅ OpenEnv compliant design
198✅ Reinforcement learning integration
199✅ Multi-agent comparison
200✅ Robust to API failures
201✅ Containerized deployment
202
203🔥 Future Improvements
204Use Deep Q-Learning instead of simple Q-table
205Add memory/context across emails
206Fine-tune LLM for domain-specific tasks
207Improve reward shaping
208
209📌 Conclusion
210
211This project demonstrates how AI agents can:
212
213Learn from interaction
214Adapt to real-world scenarios
215Improve decision-making over time
216
217It bridges LLMs + RL + Environment Design, making it a strong foundation for intelligent automation systems.