CoolFace
Apppublic

aadhesh2025/ticket-triage-env

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

<div align="center">

🎫 Ticket Triage OpenEnv

A Real-World AI Agent Training Environment

Train AI agents to triage customer support tickets β€” classify, prioritize, and respond.

![OpenEnv](https://huggingface.co/spaces/aadhesh2025/ticket-triage-env) ![HF Space](https://huggingface.co/spaces/aadhesh2025/ticket-triage-env) ![Docker](https://github.com/Crypto-Type/ticket-triage-env) ![Python](https://python.org) ![FastAPI](https://fastapi.tiangolo.com)

πŸš€ Live Demo Β· πŸ“– API Docs Β· πŸ“‹ Tasks

</div>


🌍 Why This Environment Exists

Every company receives hundreds of customer support tickets every day. Human agents must read each ticket, decide what type of problem it is, how urgent it is, and craft a helpful response. This process is:

  • —⏱️ Time-consuming β€” reading and triaging takes hours daily
  • β€”πŸ€” Judgment-heavy β€” requires experience and domain knowledge
  • β€”πŸ“ˆ Scalability bottleneck β€” hard to scale with growing user bases

This environment trains AI agents to automate that entire workflow.


πŸ—οΈ Environment Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  AI Agent (My Model)                β”‚
β”‚                        β”‚                            β”‚
β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                   β”‚
β”‚              β”‚   OpenEnv API      β”‚                 β”‚
β”‚              β”‚  POST /reset       β”‚  ← Get a ticket β”‚
β”‚              β”‚  POST /step        β”‚  ← Submit answerβ”‚
β”‚              β”‚  GET  /state       β”‚  ← Check status β”‚
β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                   β”‚
β”‚                        β”‚                            β”‚
β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                   β”‚
β”‚              β”‚  TicketTriage Env  β”‚                 β”‚
β”‚              β”‚  environment.py    β”‚                 β”‚
β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β”‚                        β”‚                            β”‚
β”‚         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
β”‚         β–Ό              β–Ό              β–Ό             β”‚
β”‚    Task 1 Grader  Task 2 Grader  Task 3 Grader      β”‚
β”‚    (Easy)         (Medium)       (Hard)             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ—‚οΈ Tasks Overview

🟒 Task 1 β€” Ticket Categorization (Easy)

FieldDetails
Task IDtask1_categorize
InputTicket subject + body text
OutputCategory label
Valid Valuesbilling Β· technical Β· general
Scoring1.0 if correct Β· 0.0 if wrong

Example:

json
Input:  "I was charged twice for my subscription"
Action: { "category": "billing" }
Reward: 1.0

🟑 Task 2 β€” Category + Priority Assignment (Medium)

FieldDetails
Task IDtask2_prioritize
InputTicket subject + body text
OutputCategory + priority label
Valid Prioritieslow Β· medium Β· high
Scoring0.5 per correct field Β· max 1.0

Example:

json
Action: { "category": "technical", "priority": "high" }
Reward: 1.0  (both correct) | 0.5  (one correct) | 0.0  (both wrong)

πŸ”΄ Task 3 β€” Full Ticket Triage (Hard)

FieldDetails
Task IDtask3_full_triage
InputTicket subject + body text
OutputCategory + priority + customer reply
Reply RequirementMinimum 10 words
Scoring~0.34 per correct field Β· max 1.0

Example:

json
Action: {
  "category": "billing",
  "priority": "high",
  "reply": "We sincerely apologize. Our billing team will process your refund within 24 hours."
}
Reward: 1.0

πŸ“ Observation & Action Spaces

Observation Space

json
{
  "observation": {
    "ticket_id": "T001",
    "subject":   "I was charged twice for my subscription",
    "body":      "Hello, I noticed two charges of $29.99 on my credit card..."
  },
  "task_id": "task1_categorize",
  "task_description": "Classify the support ticket into: billing, technical, or general",
  "action_schema": {
    "category": "string β€” one of: billing | technical | general"
  }
}

Action Space

Task 1: { "category": "billing" }

Task 2: { "category": "billing", "priority": "high" }

Task 3:

json
{
  "category": "billing",
  "priority": "high",
  "reply": "Thank you for contacting us. We will resolve your issue within 24 hours."
}

πŸ† Reward Function

Task 1:  R = 1.0 if category correct, else 0.0

Task 2:  R = (0.5 Γ— category_correct) + (0.5 Γ— priority_correct)

Task 3:  R = (0.34 Γ— category_correct)
           + (0.33 Γ— priority_correct)
           + (0.33 Γ— reply_length >= 10 words)

πŸ”Œ API Reference

MethodEndpointDescription
GET/Live dashboard UI
POST/resetStart new episode
POST/stepSubmit action, get reward
GET/stateCurrent environment state
GET/tasksList all tasks + schemas
GET/graderLast episode score
GET/baselineRun baseline agent

Python Example

python
import requests

BASE = "https://aadhesh2025-ticket-triage-env.hf.space"

# Start episode
obs = requests.post(f"{BASE}/reset", json={"task_id": "task1_categorize"}).json()
print(obs["observation"]["subject"])

# Submit action
result = requests.post(f"{BASE}/step", json={"action": {"category": "billing"}}).json()
print(f"Reward: {result['reward']}")

πŸ“Š Baseline Scores

TaskAvg RewardAgent Type
task1_categorize~0.33Random agent
task2_prioritize~0.28Random agent
task3_full_triage~0.56Random agent

πŸš€ Local Setup

bash
# Clone
git clone https://github.com/Crypto-Type/ticket-triage-env
cd ticket-triage-env

# Install
pip install -r requirements.txt

# Run
uvicorn main:app --host 0.0.0.0 --port 7860 --reload

# Open: http://localhost:7860

Run Inference Script

bash
export API_BASE_URL="https://api-inference.huggingface.co/v1"
export MODEL_NAME="Qwen/Qwen2.5-72B-Instruct"
export HF_TOKEN="your_hf_token_here"
export ENV_BASE_URL="http://localhost:7860"

python inference.py

🐳 Docker

bash
docker build -t ticket-triage-env .
docker run -p 7860:7860 ticket-triage-env

πŸ“ Project Structure

ticket-triage-env/
β”œβ”€β”€ main.py            # FastAPI server + UI dashboard
β”œβ”€β”€ environment.py     # Core env: reset(), step(), state()
β”œβ”€β”€ tasks.py           # Tasks, tickets, grader functions
β”œβ”€β”€ inference.py       # LLM inference script (OpenAI client)
β”œβ”€β”€ baseline.py        # Random baseline agent
β”œβ”€β”€ openenv.yaml       # OpenEnv specification
β”œβ”€β”€ pyproject.toml     # Python project config
β”œβ”€β”€ requirements.txt   # Python dependencies
β”œβ”€β”€ Dockerfile         # Container definition
└── README.md          # This file

πŸ§ͺ Environment Variables

VariableDescriptionDefault
API_BASE_URLLLM API endpointhttps://api-inference.huggingface.co/v1
MODEL_NAMEModel identifierQwen/Qwen2.5-72B-Instruct
HF_TOKENHugging Face API key""
ENV_BASE_URLEnvironment server URLhttp://localhost:7860

πŸ“‹ OpenEnv Compliance

  • β€”βœ… Typed Pydantic models for Observation, Action, Reward
  • β€”βœ… POST /reset β€” returns clean initial observation
  • β€”βœ… POST /step β€” returns observation, reward, done, info
  • β€”βœ… GET /state β€” returns current environment state
  • β€”βœ… openenv.yaml with full metadata
  • β€”βœ… Deployed on Hugging Face Spaces with Docker
  • β€”βœ… inference.py using OpenAI-compatible client
  • β€”βœ… Scores reproducible between runs

πŸ‘€ Author

Aravind S β€” Built for OpenEnv Round 1 Β· Hugging Face Γ— Meta AI Competition


<div align="center">

Built with ❀️ using FastAPI · Docker · Hugging Face Spaces

πŸš€ Try it Live Β· πŸ“– API Docs

</div>