Spaces:
Sleeping
Sleeping
File size: 9,583 Bytes
d6a76d5 9619237 d6a76d5 014ab20 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 f619d4c 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 d6a76d5 9619237 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | ---
title: Customer Support OpenEnv Environment
emoji: ๐ค
colorFrom: blue
colorTo: green
sdk: docker
tags:
- openenv
- reinforcement-learning
- llm
- customer-support
---
# ๐ค Customer Support Agent โ OpenEnv Environment
## ๐ง Overview
This project implements a **real-world customer support simulation environment** built using the OpenEnv specification.
It is designed to evaluate and train intelligent agents capable of:
* Understanding noisy and ambiguous user queries
* Classifying issues correctly
* Gathering missing information efficiently
* Resolving tickets under uncertainty
Unlike toy environments, this system models **real operational complexity** found in production customer support workflows.
---
## ๐ฏ Objective
Build and evaluate an agent that can:
1. **Classify** customer issues (billing / technical / delivery)
2. **Collect required information** dynamically
3. **Resolve efficiently** under constraints
4. **Adapt behavior mid-episode** (self-correction)
---
## ๐๏ธ System Architecture
+----------------------+
| Customer Ticket |
| (noisy, ambiguous) |
+----------+-----------+
|
v
+----------------------+
| Environment (env.py)|
|----------------------|
| - State |
| - Reward |
| - Stochasticity |
+----------+-----------+
|
v
+----------------------+
| Observation Space |
|----------------------|
| message |
| known_info |
| required |
+----------+-----------+
|
v
+----------------------+
| Agent (LLM + Rule) |
|----------------------|
| - Reasoning (LLM) |
| - Constraints |
| - Fallback |
+----------+-----------+
|
v
+----------------------+
| Action |
|----------------------|
| classify |
| ask_info |
| resolve |
+----------+-----------+
|
v
+----------------------+
| Environment Step |
|----------------------|
| reward |
| next_state |
+----------------------+
## Interaction Loop
RESET โ OBSERVE โ ACT โ STEP โ REPEAT
Detailed Flow:
[RESET]
โ
[Observation]
โ
[Agent Decision]
โ
[Action]
โ
[Environment Step]
โ
[Reward + Next State]
โ
[Done?] โโ No โโ> Loop
โ
Yes
โ
[Episode End]
## Self-Correction Loop
Initial Flow:
classify โ ask_info โ resolve
With Self-Correction:
classify
โ
ask_info
โ
[New Information Arrives]
โ
re-evaluate decision
โ
re-classify (if needed)
โ
ask remaining info
โ
resolve
## Agent Decision Logic
IF not classified:
โ classify
ELIF missing required fields:
โ ask_info
ELIF uncertain:
โ re-classify
ELSE:
โ resolve
## Stochastic Behavior
Customer Message =
base_variant
+ noise injection
+ ambiguity
Required Info =
full_schema
- randomly masked fields
Difficulty Controls:
EASY โ low noise, clear signals
MEDIUM โ moderate noise
HARD โ high ambiguity + missing info
## Reward Flow
Action โ Immediate Reward โ Final Outcome
Examples:
ask_info (useful) โ +0.3
repeat ask โ -0.3
step penalty โ -0.05
correct classify โ +0.2
premature resolve โ -1.0 (hard)
successful resolve โ +0.2 to +1.0
## Example Episode
Step 1: classify โ reward -0.05
Step 2: ask_info โ reward +0.20
Step 3: re-classify โ reward -0.05
Step 4: resolve โ reward +0.45
Outcome:
โ success
โ self-correction observed
โ efficient resolution
### 1. Environment (`env.py`)
A **stateful, stochastic simulation** of customer support operations.
#### Key Features
* Multi-step interaction loop (`step`, `reset`, `state`)
* Partial observability (missing information)
* Stochastic noise injection
* Difficulty-aware configuration
* Multi-intent ticket handling
* Reward shaping with penalties for poor decisions
---
### 2. Observation Space
```json
{
"ticket_id": "string",
"customer_message": "string",
"known_info": {},
"required": ["fields"],
"missing_required": ["fields"],
"info_progress": 0.0,
"status": "open | resolved",
"step_count": 0,
"remaining_steps": 10,
"difficulty": "easy | medium | hard"
}
```
---
### 3. Action Space
| Action | Description |
| -------- | -------------------------- |
| classify | Assign category + priority |
| ask_info | Request missing field |
| resolve | Attempt to close ticket |
Example:
```json
{
"type": "ask_info",
"field": "order_id"
}
```
---
## ๐ฒ Difficulty & Stochastic Control
The environment dynamically adjusts complexity:
| Difficulty | Max Steps | Noise | Missing Info |
| ---------- | --------- | -------- | ------------ |
| Easy | Low | None | Minimal |
| Medium | Medium | Moderate | Partial |
| Hard | High | High | Significant |
### Stochastic Elements
* **Noise Injection**
Adds irrelevant or emotional phrases
* **Information Masking**
Required fields may be hidden
* **Ambiguity**
Messages may not clearly indicate category
---
## ๐งพ Dataset (Production-Style Tickets)
Each ticket includes:
```python
{
"ticket_id": "...",
"variants": [...], # multiple phrasings
"noise": [...], # real-world clutter
"ground_truth": {
"category": "...",
"priority": "...",
"required_info": [...],
"intents": [...] # multi-intent support
}
}
```
### Key Properties
* Multiple linguistic variations
* Realistic phrasing (not templated)
* Multi-intent issues (e.g., billing + technical)
* No explicit hints (agent must infer)
---
## ๐ Self-Correction Mechanism
The agent is designed to **adapt within an episode**.
### What this means:
* Can **re-classify after new information**
* Can **delay resolution under uncertainty**
* Can **recover from suboptimal actions**
### Example behavior:
```
classify โ ask_info โ re-classify โ resolve
```
This mimics real-world agent reasoning rather than fixed pipelines.
---
## ๐ง Agent Design (`agent_llm.py`)
### Hybrid Intelligence
| Component | Role |
| --------- | ---------------------- |
| LLM | High-level reasoning |
| Rules | Safety + constraints |
| Fallback | Deterministic recovery |
---
### Key Capabilities
* Structured JSON output
* Retry + validation loop
* Fallback policy (guarantees progress)
* Partial autonomy (not over-constrained)
---
## ๐งฎ Reward Design
Reward is **dense and shaped**, not binary.
| Behavior | Reward |
| ------------------------ | ------------ |
| Step penalty | -0.05 |
| Correct classification | +0.2 |
| Useful info collection | +0.3 |
| Redundant action | -0.3 |
| Premature resolve (hard) | -1.0 |
| Successful resolve | +0.2 to +1.0 |
---
## ๐ Metrics
Tracked per episode:
```json
{
"success_rate": 0.0,
"avg_steps": 0.0,
"avg_reward": 0.0,
"info_efficiency": 0.0
}
```
### Additional Behavioral Signals
* Self-correction frequency (re-classification)
* Resolution efficiency
* Failure modes under uncertainty
---
## ๐งช Tasks & Graders
Three evaluation tasks:
| Task | Difficulty | Objective |
| ------------------------- | ---------- | -------------------------------------- |
| easy-info-collection | Easy | Basic info gathering |
| medium-complete-info | Medium | Complete + accurate handling |
| hard-efficient-resolution | Hard | Efficient resolution under uncertainty |
### Grader Properties
* Deterministic
* Score range: **0.0 โ 1.0**
* Multi-factor scoring:
* success
* efficiency
* completeness
---
## โถ๏ธ Inference
Run baseline agent:
```bash
python inference.py
```
Outputs:
```
[START] task=easy-info-collection ...
[STEP] ...
[END] ...
{"task_id": "...", "score": 0.7}
```
---
## ๐ณ Deployment (Hugging Face Spaces)
### Build Docker
```bash
docker build -t openenv-customer-support-agent .
```
### Run
```bash
docker run -p 7860:7860 openenv-customer-support-agent
```
---
## ๐ API Endpoints
| Endpoint | Description |
| -------- | ---------------------- |
| `/reset` | Initialize environment |
| `/step` | Execute action |
---
## โ๏ธ Environment Variables
Required:
```
API_BASE_URL
MODEL_NAME
HF_TOKEN
```
---
## โ
OpenEnv Compliance
* Typed observation/action models
* step/reset/state implemented
* 3+ tasks with graders
* Deterministic scoring
* Dockerized deployment
* HF Space compatible
---
## ๐ Key Innovations
* Real-world task simulation (not toy)
* Stochastic difficulty scaling
* Multi-intent ticket modeling
* Self-correcting agent behavior
* Hybrid LLM + rule-based architecture
* Dense reward shaping
---
## ๐ฎ Future Improvements
* Multi-stage resolution pipelines
* Conversation memory (history utilization)
* Active uncertainty estimation
* Adaptive task generation
* Multi-agent coordination
---
## ๐ง Big Picture
This environment models:
> **Decision-making under uncertainty with partial information**
It is suitable for:
* RL agent training
* LLM agent evaluation
* benchmarking reasoning systems
---
## ๐ค Author
Built as part of an advanced OpenEnv submission focused on real-world agent intelligence and evaluation.
---
|