Aarushiar/pytorch-hackathon-support-env
Customer Support Ticket Environment
A production-ready OpenEnv environment for AI agents to learn customer support ticket resolution. Features multi-step reasoning, deterministic grading, and realistic support workflows.
Real-world Task: Agents learn to resolve customer support tickets across 3 scenarios with varying complexity, customer tiers, and issue types.
✨ Features
✅ Real-World Task - Customer support ticket resolution (not a toy) ✅ Full OpenEnv Spec Compliance - Typed models, step()/reset()/state() API, openenv.yaml v1 ✅ 3 Tiered Tasks - Easy/Medium/Hard with deterministic graders, 0.0-1.0 scores ✅ Meaningful Rewards - Partial credit, penalties for poor actions, differentiated scores ✅ Reproducible Baseline - inference.py with MANDATORY-compliant logging ✅ Production Deployment - Docker + Hugging Face Spaces compatible ✅ OpenEnv HTTP API - /reset, /step, /state, /health endpoints
🎯 Environment Overview
Tasks (Easy → Medium → Hard)
Action Space (Constrained)
action_type: Literal[
"request_more_info", # Ask for clarification ($0 cost)
"escalate_to_human", # Route to human agent ($15 cost)
"suggest_knowledge_base", # Search KB ($1 cost)
"assign_department", # Route to specific team ($5 cost)
"close_resolved", # Mark as resolved
"request_callback" # Schedule callback ($10 cost)
]Observation Space
{
"ticket_id": "TKT-000001-f-BIL",
"customer_message": "Why was I charged twice?",
"customer_tier": "free|pro|enterprise",
"priority": "low|medium|high",
"category": "billing|technical|feature_request|account",
"conversation_history": ["..."],
"kb_match_score": 0.85,
"sentiment_score": -0.3,
"customer_tenure_days": 45,
"total_revenue": 1200.50
}Reward System
- Deterministic: Same seed → same ticket → same reward
- Partial Credit: Multiple scoring components, not binary 0/1
- Penalties:
- Closing without investigation: -0.3 to -0.4
- Poor action choices: -0.1 to -0.2
- Inefficiency (too many steps): probability reduction
- Score Range: [0.0, 1.0] normalized
Example Scores:
- Optimal action (suggestknowledgebase for high KB match): 0.80-0.90
- Acceptable action (requestmoreinfo): 0.50-0.70
- Poor action (close without investigation): 0.00-0.30
🚀 Installation & Setup
Prerequisites
- Python 3.10+
- Docker (for container deployment)
- Git + GitHub account (for HF Spaces)
Local Development
# Clone repository
git clone https://github.com/YOUR-USERNAME/support-ticket-env.git
cd support-ticket-env
# Install dependencies
pip install -e .
# Or with uv (faster)
uv syncRun Server Locally
# Default (port 9000)
uv run server
# Custom port
uv run server -- --port 8001
# Or with python
python -m uvicorn server.app:app --host 0.0.0.0 --port 9000Test endpoints:
# Health check
curl http://localhost:9000/health
# Reset environment
curl -X POST http://localhost:9000/reset
# Execute action
curl -X POST http://localhost:9000/step \
-H "Content-Type: application/json" \
-d '{
"action": {
"action_type": "request_more_info",
"parameters": {"question": "Can you provide more details?"}
}
}'📖 Running the Inference Script
The inference.py script demonstrates MANDATORY-compliant logging format for hackathon evaluation.
Setup Environment Variables
# OpenAI-compatible API
export API_BASE_URL=http://localhost:9000/v1
export MODEL_NAME=gpt-4
export HF_TOKEN=your_hf_token_hereRun Inference
python inference.pyOutput format (MANDATORY-compliant):
[START] task=1 env=support_task_1_seed_42 model=gpt-4
[STEP] step=1 action=request_more_info reward=0.50 done=false error=null
[STEP] step=2 action=suggest_knowledge_base reward=0.80 done=true error=null
[END] success=true steps=2 score=0.80 rewards=0.50,0.80Features:
- ✅ Exact logging format:
[START],[STEP],[END] - ✅ 2-decimal precision on all floats
- ✅ Lowercase booleans (
true/false) - ✅
"null"for no error (notNone) - ✅ Score normalized to [0.0, 1.0]
- ✅ OpenAI client ONLY (no alternatives)
🐳 Docker Deployment
Build Image
docker build -t support-ticket-env:latest -f server/Dockerfile .Run Container
docker run \
-p 9000:9000 \
-e API_BASE_URL=http://localhost:9000/v1 \
-e MODEL_NAME=gpt-4 \
-e HF_TOKEN=your_token \
support-ticket-env:latestHealth Check
Docker image includes health check:
curl http://localhost:9000/health
# → {"status": "healthy", "service": "support_ticket_environment"}☁️ Deploy to Hugging Face Spaces
Step 1: Push to GitHub
git config --global user.email "your@email.com"
git config --global user.name "Your Name"
git init
git add .
git commit -m "Support ticket environment - ready for HF Spaces"
git remote add origin https://github.com/YOUR-USERNAME/support-ticket-env.git
git branch -M main
git push -u origin mainStep 2: Create HF Space
- Go to https://huggingface.co/spaces
- Click Create New Space
- Configure:
- Name:
support-ticket-environment - License: MIT
- SDK: Docker
- Link GitHub repository
- HF will auto-build and deploy!
Step 3: Validate Deployment
bash scripts/validate-submission.sh https://your-username-support-ticket-environment.hf.space3-stage validator:
- Stage 1: Ping
/resetendpoint (HTTP 200) - Stage 2: Docker build test (600s timeout)
- Stage 3: Run
openenv validate
📊 Project Structure
support-ticket-env/
├── models.py # SupportAction, SupportObservation (Pydantic)
├── support_env.py # SupportTicketEnvironment (step/reset/state)
├── tasks.py # Task1/2/3_Grader (deterministic scoring)
├── reward_calculator.py # RewardCalculator (partial credit system)
├── inference.py # MANDATORY-compliant baseline script
├── client.py # OpenEnv client for testing
├── openenv.yaml # OpenEnv spec v1 config
├── pyproject.toml # Dependencies + entry points
├── README.md # This file
├── server/
│ ├── app.py # FastAPI + OpenEnv HTTP server
│ ├── Dockerfile # Multi-stage Docker build
│ └── requirements.txt # Python dependencies
├── scripts/
│ └── validate-submission.sh # 3-stage validator
└── test_*.py # Test scripts🧪 Testing
Unit Tests
# Test environment locally
python test_uv_server.py
# Test full episode
python test_full_episode.py
# Test logging format
python test_logging_format.pyIntegration Tests
# Run validation checklist
bash scripts/validate-submission.sh http://localhost:9000📝 Specification Compliance
OpenEnv Spec v1 ✅
spec_version: 1
name: support_ticket_environment
type: space
runtime: fastapi
app: server.app:app
port: 9000
health_check:
endpoint: /health
interval: 30
timeout: 10
retries: 3Environment Interface ✅
class SupportTicketEnvironment(Environment):
def reset(self) -> SupportObservation: ...
def step(self, action: SupportAction) -> Tuple[SupportObservation, float, bool]: ...
def state(self) -> ConversationState: ...
# Async wrappers for HTTP server
async def reset_async(self) -> SupportObservation: ...
async def step_async(self, action: SupportAction) -> ...: ...📋 Requirements Met
🚀 Performance Targets
📄 License
MIT - Free for any use
🤝 Contributing
Contributions welcome! Fork → Feature branch → Pull request
Ready to deploy? See HFSPACESDEPLOYMENT.md for detailed instructions.
