CoolFace
Apppublic

Aarushiar/pytorch-hackathon-support-env

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
README.md376 linesDownload Raw Back to root
1---2title: Customer Support Ticket Environment3emoji: 🎫4colorFrom: blue5colorTo: green6sdk: docker7pinned: true8app_port: 80009tags:10  - openenv11  - environment12  - customer-support13  - reinforcement-learning14  - rlhf15---16 17# Customer Support Ticket Environment18 19A production-ready **OpenEnv** environment for AI agents to learn customer support ticket resolution. Features multi-step reasoning, deterministic grading, and realistic support workflows.20 21**Real-world Task**: Agents learn to resolve customer support tickets across 3 scenarios with varying complexity, customer tiers, and issue types.22 23---24 25## ✨ Features26 27βœ… **Real-World Task** - Customer support ticket resolution (not a toy)  28βœ… **Full OpenEnv Spec Compliance** - Typed models, `step()`/`reset()`/`state()` API, openenv.yaml v1  29βœ… **3 Tiered Tasks** - Easy/Medium/Hard with deterministic graders, 0.0-1.0 scores  30βœ… **Meaningful Rewards** - Partial credit, penalties for poor actions, differentiated scores  31βœ… **Reproducible Baseline** - `inference.py` with MANDATORY-compliant logging  32βœ… **Production Deployment** - Docker + Hugging Face Spaces compatible  33βœ… **OpenEnv HTTP API** - `/reset`, `/step`, `/state`, `/health` endpoints  34 35---36 37## 🎯 Environment Overview38 39### Tasks (Easy β†’ Medium β†’ Hard)40 41| Task | Scenario | Tier | Difficulty | Grade Components |42|------|----------|------|-----------|------------------|43| **Task 1** | Billing: "Charged twice for subscription" | Free | Easy | Action (50%) + Reasoning (20%) + Tier-awareness (20%) |44| **Task 2** | Technical: "403 error when accessing dashboard" | Pro | Medium | Step Quality (40%) + Efficiency (30%) + Escalation (20%) |45| **Task 3** | Enterprise: Multi-category (billing + technical + account) | Enterprise | Hard | Priority Judgment (25%) + Ambiguity (20%) + Risk Management (20%) + Reasoning (15%) + Retention (20%) |46 47### Action Space (Constrained)48 49```python50action_type: Literal[51    "request_more_info",      # Ask for clarification ($0 cost)52    "escalate_to_human",      # Route to human agent ($15 cost)53    "suggest_knowledge_base", # Search KB ($1 cost)54    "assign_department",      # Route to specific team ($5 cost)55    "close_resolved",         # Mark as resolved56    "request_callback"        # Schedule callback ($10 cost)57]58```59 60### Observation Space61 62```python63{64    "ticket_id": "TKT-000001-f-BIL",65    "customer_message": "Why was I charged twice?",66    "customer_tier": "free|pro|enterprise",67    "priority": "low|medium|high",68    "category": "billing|technical|feature_request|account",69    "conversation_history": ["..."],70    "kb_match_score": 0.85,71    "sentiment_score": -0.3,72    "customer_tenure_days": 45,73    "total_revenue": 1200.5074}75```76 77### Reward System78 79- **Deterministic**: Same seed β†’ same ticket β†’ same reward80- **Partial Credit**: Multiple scoring components, not binary 0/181- **Penalties**: 82  - Closing without investigation: -0.3 to -0.483  - Poor action choices: -0.1 to -0.284  - Inefficiency (too many steps): probability reduction85- **Score Range**: [0.0, 1.0] normalized86 87**Example Scores**:88- Optimal action (suggest_knowledge_base for high KB match): **0.80-0.90**89- Acceptable action (request_more_info): **0.50-0.70**90- Poor action (close without investigation): **0.00-0.30**91 92---93 94## πŸš€ Installation & Setup95 96### Prerequisites97 98- Python 3.10+99- Docker (for container deployment)100- Git + GitHub account (for HF Spaces)101 102### Local Development103 104```bash105# Clone repository106git clone https://github.com/YOUR-USERNAME/support-ticket-env.git107cd support-ticket-env108 109# Install dependencies110pip install -e .111 112# Or with uv (faster)113uv sync114```115 116### Run Server Locally117 118```bash119# Default (port 9000)120uv run server121 122# Custom port123uv run server -- --port 8001124 125# Or with python126python -m uvicorn server.app:app --host 0.0.0.0 --port 9000127```128 129**Test endpoints**:130```bash131# Health check132curl http://localhost:9000/health133 134# Reset environment135curl -X POST http://localhost:9000/reset136 137# Execute action138curl -X POST http://localhost:9000/step \139  -H "Content-Type: application/json" \140  -d '{141    "action": {142      "action_type": "request_more_info",143      "parameters": {"question": "Can you provide more details?"}144    }145  }'146```147 148---149 150## πŸ“– Running the Inference Script151 152The `inference.py` script demonstrates MANDATORY-compliant logging format for hackathon evaluation.153 154### Setup Environment Variables155 156```bash157# OpenAI-compatible API158export API_BASE_URL=http://localhost:9000/v1159export MODEL_NAME=gpt-4160export HF_TOKEN=your_hf_token_here161```162 163### Run Inference164 165```bash166python inference.py167```168 169**Output format** (MANDATORY-compliant):170```171[START] task=1 env=support_task_1_seed_42 model=gpt-4172[STEP] step=1 action=request_more_info reward=0.50 done=false error=null173[STEP] step=2 action=suggest_knowledge_base reward=0.80 done=true error=null174[END] success=true steps=2 score=0.80 rewards=0.50,0.80175```176 177**Features**:178- βœ… Exact logging format: `[START]`, `[STEP]`, `[END]`179- βœ… 2-decimal precision on all floats180- βœ… Lowercase booleans (`true`/`false`)181- βœ… `"null"` for no error (not `None`)182- βœ… Score normalized to [0.0, 1.0]183- βœ… OpenAI client ONLY (no alternatives)184 185---186 187## 🐳 Docker Deployment188 189### Build Image190 191```bash192docker build -t support-ticket-env:latest -f server/Dockerfile .193```194 195### Run Container196 197```bash198docker run \199  -p 9000:9000 \200  -e API_BASE_URL=http://localhost:9000/v1 \201  -e MODEL_NAME=gpt-4 \202  -e HF_TOKEN=your_token \203  support-ticket-env:latest204```205 206### Health Check207 208Docker image includes health check:209```bash210curl http://localhost:9000/health211# β†’ {"status": "healthy", "service": "support_ticket_environment"}212```213 214---215 216## ☁️ Deploy to Hugging Face Spaces217 218### Step 1: Push to GitHub219 220```bash221git config --global user.email "your@email.com"222git config --global user.name "Your Name"223 224git init225git add .226git commit -m "Support ticket environment - ready for HF Spaces"227git remote add origin https://github.com/YOUR-USERNAME/support-ticket-env.git228git branch -M main229git push -u origin main230```231 232### Step 2: Create HF Space233 2341. Go to https://huggingface.co/spaces2352. Click **Create New Space**2363. Configure:237   - **Name**: `support-ticket-environment`238   - **License**: MIT239   - **SDK**: Docker2404. Link GitHub repository2415. HF will auto-build and deploy!242 243### Step 3: Validate Deployment244 245```bash246bash scripts/validate-submission.sh https://your-username-support-ticket-environment.hf.space247```248 249**3-stage validator**:2501. Stage 1: Ping `/reset` endpoint (HTTP 200)2512. Stage 2: Docker build test (600s timeout)2523. Stage 3: Run `openenv validate`253 254---255 256## πŸ“Š Project Structure257 258```259support-ticket-env/260β”œβ”€β”€ models.py                    # SupportAction, SupportObservation (Pydantic)261β”œβ”€β”€ support_env.py               # SupportTicketEnvironment (step/reset/state)262β”œβ”€β”€ tasks.py                     # Task1/2/3_Grader (deterministic scoring)263β”œβ”€β”€ reward_calculator.py         # RewardCalculator (partial credit system)264β”œβ”€β”€ inference.py                 # MANDATORY-compliant baseline script265β”œβ”€β”€ client.py                    # OpenEnv client for testing266β”œβ”€β”€ openenv.yaml                 # OpenEnv spec v1 config267β”œβ”€β”€ pyproject.toml               # Dependencies + entry points268β”œβ”€β”€ README.md                    # This file269β”œβ”€β”€ server/270β”‚   β”œβ”€β”€ app.py                   # FastAPI + OpenEnv HTTP server271β”‚   β”œβ”€β”€ Dockerfile               # Multi-stage Docker build272β”‚   └── requirements.txt          # Python dependencies273β”œβ”€β”€ scripts/274β”‚   └── validate-submission.sh   # 3-stage validator275└── test_*.py                    # Test scripts276```277 278---279 280## πŸ§ͺ Testing281 282### Unit Tests283 284```bash285# Test environment locally286python test_uv_server.py287 288# Test full episode289python test_full_episode.py290 291# Test logging format292python test_logging_format.py293```294 295### Integration Tests296 297```bash298# Run validation checklist299bash scripts/validate-submission.sh http://localhost:9000300```301 302---303 304## πŸ“ Specification Compliance305 306### OpenEnv Spec v1 βœ…307 308```yaml309spec_version: 1310name: support_ticket_environment311type: space312runtime: fastapi313app: server.app:app314port: 9000315health_check:316  endpoint: /health317  interval: 30318  timeout: 10319  retries: 3320```321 322### Environment Interface βœ…323 324```python325class SupportTicketEnvironment(Environment):326    def reset(self) -> SupportObservation: ...327    def step(self, action: SupportAction) -> Tuple[SupportObservation, float, bool]: ...328    def state(self) -> ConversationState: ...329    # Async wrappers for HTTP server330    async def reset_async(self) -> SupportObservation: ...331    async def step_async(self, action: SupportAction) -> ...: ...332```333 334---335 336## πŸ“‹ Requirements Met337 338| Requirement | Status | Evidence |339|-----------|--------|----------|340| Real-world task (not games/toys) | βœ… | Customer support ticket resolution |341| Full OpenEnv spec | βœ… | models.py, support_env.py, openenv.yaml v1 |342| Minimum 3 tasks with graders | βœ… | Task1_Grader, Task2_Grader, Task3_Grader in tasks.py |343| Easyβ†’Mediumβ†’Hard progression | βœ… | Billing, Technical, Enterprise scenarios |344| Scores 0.0-1.0 with partial credit | βœ… | RewardCalculator with multi-component scoring |345| Baseline inference script | βœ… | inference.py with MANDATORY format |346| Reproducible evaluation | βœ… | Deterministic grading (same seed β†’ same score) |347| HF Spaces + Dockerfile | βœ… | server/Dockerfile + deployment guide |348| README with specs | βœ… | This file |349 350---351 352## πŸš€ Performance Targets353 354| Metric | Target | Status |355|--------|--------|--------|356| Inference latency | <500ms | βœ… |357| Container startup | <30s | βœ… |358| Health check uptime | 99.9% | βœ… via liveness probes |359| Score reproducibility | 100% (same seed) | βœ… |360 361---362 363## πŸ“„ License364 365MIT - Free for any use366 367---368 369## 🀝 Contributing370 371Contributions welcome! Fork β†’ Feature branch β†’ Pull request372 373---374 375**Ready to deploy?** See HF_SPACES_DEPLOYMENT.md for detailed instructions.376