Spaces:
No application file

File size: 4,253 Bytes
b6f9e96
 
 
 
 
 
 
05b75ac
 
 
 
b6f9e96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05b75ac
b6f9e96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05b75ac
 
 
 
 
 
 
 
b6f9e96
 
 
 
 
 
 
 
 
 
 
 
 
 
05b75ac
 
 
 
b6f9e96
 
05b75ac
 
 
 
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
# PRD: SupportEnv – AI Customer Support RL Environment

## Overview

Build a complete OpenEnv-compliant environment that simulates a real-world customer support system where an AI agent can:

- Classify support tickets
- Search Knowledge Base (lookup_kb)
- Generate empathetic responses
- Decide escalation (de-escalate if possible)
- Resolve issues efficiently

### Requirements

- Follow OpenEnv spec: `reset()`, `step()`, `state()`
- Include 3 tasks (easy β†’ medium β†’ hard)
- Include deterministic graders (0.0–1.0)
- Include baseline inference
- Deploy via Docker + Hugging Face Spaces

---

## Task 1: Project Setup & Structure

Create full project structure:

SupportEnv/
β”œβ”€β”€ models.py                    # Typed Action, Observation, State
β”œβ”€β”€ client.py                    # WebSocket client for external use
β”œβ”€β”€ openenv.yaml                 # Environment metadata
β”œβ”€β”€ pyproject.toml               # Package dependencies
β”œβ”€β”€ requirements.txt             # Pip requirements
β”œβ”€β”€ README.md                    # Documentation
β”‚
β”œβ”€β”€ server/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ app.py                   # FastAPI application
β”‚   β”œβ”€β”€ environment.py           # Core RL logic
β”‚   β”œβ”€β”€ tasks.py                 # Task definitions (easy/medium/hard)
β”‚   β”œβ”€β”€ graders.py               # Deterministic scoring
β”‚   β”œβ”€β”€ reward.py                # Reward computation
β”‚   β”œβ”€β”€ ticket_generator.py      # Realistic ticket generation
β”‚   β”œβ”€β”€ utils.py                 # Helper functions
β”‚   └── Dockerfile               # Container definition
β”‚
β”œβ”€β”€ baseline/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ run_baseline.py          # Baseline execution script
β”‚   β”œβ”€β”€ policy.py                # Rule-based baseline agent
β”‚   └── results.json             # Saved baseline scores
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── gradio_ui.py             # Gradio interface
β”‚
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ test_environment.py
β”‚   β”œβ”€β”€ test_graders.py
β”‚   β”œβ”€β”€ test_api.py
β”‚   └── test_baseline.py
β”‚
└── scripts/
    β”œβ”€β”€ start_local.sh
    β”œβ”€β”€ validate.sh
    └── deploy.sh

### Requirements

- Follow OpenEnv structure
- All files created (no placeholders)
- Project runs locally without errors

---

## Task 2: Define Typed Models

### Action

- `action_type`: classify | respond | escalate | resolve | lookup_kb | request_info
- `content`: string  

### Observation

- `ticket_text`
- `history`
- `customer_sentiment`
- `issue_category`

### State

- `episode_id`
- `step_count`
- `resolved`

### Requirements

- Fully typed (Pydantic)
- OpenEnv compatible
- No missing fields

---

## Task 3: Implement Ticket Generator

### Features

Generate tickets for:
- Billing
- Technical
- Account

Include:
- Difficulty (easy / medium / hard)
- Sentiment score
- Keywords

### Requirements

- Minimum 20 tickets
- Include ambiguous hard cases
- Deterministic with seed

---

## Task 4: Implement Environment Core

### reset()

- Generate new ticket
- Initialize state
- Clear history

### step(action)

Handle:
- classify
- respond
- escalate
- resolve

Return:
- observation
- reward
- done

### state()

- Return metadata

### Requirements

- Multi-step interaction supported
- Episode ends correctly
- No crashes on invalid input

---

## Task 5: Implement Reward System

### Rewards

- Correct classification β†’ +0.25
- Hybrid Semantic Response Quality β†’ +0.30
- Appropriate KB usage β†’ +0.15
- Correct escalation decision β†’ +0.35
- Successful resolution β†’ +0.40
- Wrong escalation β†’ -0.20
- Missed mandatory escalation β†’ -0.35
- Harmful response β†’ -0.40

### Requirements

- Step-level rewards
- Not purely binary
- Penalizes bad behavior

---

## Task 6: Implement Grader System

### Evaluate

- Classification accuracy  
- Response quality (Semantic + Keyword)
- Escalation correctness (with mandatory de-escalation for hard tasks)
- Resolution Alignment
- Efficiency (Penalizing superficial handling of hard tasks)

### Output

- Scalar score [0.0, 1.0]
- Detailed breakdown by difficulty
- Passing status (score > 0.8)