Spaces:
Sleeping
Sleeping
Commit ·
3752981
0
Parent(s):
Initial commit
Browse filesFiles changed (33)
- KNOWLEDGE.mdAdded+258
- LABEL_AUDIT.mdAdded+56
- MARCH30_STATUS.mdAdded+117
- MENTAL_MODEL.mdAdded+155
- PLAN.mdAdded+147
- PreparationAdded
- ProblemDetailsAdded+472
- README.mdAdded+258
- ROADMAP.mdAdded+339
- __init__.cpython-313.pycAdded
- __init__.pyAdded
- app.cpython-313.pycAdded
- client.cpython-313.pycAdded
- client.pyAdded+28
- data/dataset.jsonAdded+543
- environment.cpython-313.pycAdded
- grader.cpython-313.pycAdded
- inference.pyAdded+276
- models.cpython-313.pycAdded
- models.pyAdded+114
- openenv.yamlAdded+59
- pyproject.tomlAdded+26
- requirements.txtAdded+6
- reward.cpython-313.pycAdded
- server/DockerfileAdded+12
- server/app.pyAdded+43
- server/environment.pyAdded+163
- server/grader.pyAdded+103
- server/reward.pyAdded+16
- server/tasks.pyAdded+60
- studymaterialLinksAdded+16
- tasks.cpython-313.pycAdded
- vocabulary.pyAdded+67
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258# IT Helpdesk Ticket Routing OpenEnv - Knowledge Guide
## Part 1: What The Hackathon Wants
The hackathon is asking for a real-world environment that an AI agent can learn from through the standard OpenEnv interface.
In plain terms, the judges want:
1. a real human job, not a toy problem2. typed models for actions, observations, and state3. `reset()`, `step()`, and `state()`4. at least 3 tasks with increasing difficulty5. deterministic graders that return scores from `0.0` to `1.0`6. a meaningful reward function7. a baseline `inference.py`8. Docker and deployment readiness
## Part 2: Why This Repo Uses IT Helpdesk Ticket Routing
IT helpdesk ticket routing is a strong OpenEnv domain because it is:
- a real operational workflow- naturally multi-step- easy to express with typed actions and observations- easy to score deterministically- useful for evaluating planning, classification, and routing ability in agents
## Part 3: The Core Mental Model
Think of this environment as a queue of helpdesk tickets.
For each ticket, the agent must answer:
- what kind of issue is this- how urgent is it- which resolver group should own it- what should happen next
The environment shows one ticket at a time. The agent responds with structured fields. The grader scores that response. Then the environment moves to the next ticket.
## Part 4: Main Files
### `models.py`
Defines the typed objects used everywhere:
- `HelpdeskTicketRecord`- `HelpdeskTicketAction`- `HelpdeskTicketObservation`- `HelpdeskTicketState`
### `server/environment.py`
This is the core engine.
It:
- loads the dataset- samples a queue of 3 to 5 tickets- tracks progress- grades each step- computes the final episode reward
### `server/grader.py`
Contains deterministic scoring logic.
It gives:
- exact or partial credit for `issue_type`- exact or proximity credit for `priority`- exact credit for `assignment_group`- exact credit for `resolution_action`
### `server/reward.py`
Contains reward helpers:
- per-step reward clamping- final trajectory reward calculation
### `server/tasks.py`
Defines the difficulty ladder:
- Task 1: issue type only- Task 2: issue type plus priority- Task 3: full routing
### `server/app.py`
Creates the OpenEnv app and exposes a custom `/tasks` route.
### `client.py`
Typed client used by the inference script.
### `inference.py`
The baseline agent runner.
It can:
- use a real LLM through an OpenAI-compatible API- or fall back to a keyword heuristic
## Part 5: Tasks
### Task 1: Issue Type Classification
The agent predicts:
- `issue_type`
### Task 2: Issue Type And Priority
The agent predicts:
- `issue_type`- `priority`
### Task 3: Full Ticket Routing
The agent predicts:
- `issue_type`- `priority`- `assignment_group`- `resolution_action`
## Part 6: Ticket Vocabulary
### Issue types
- `billing_license`- `identity_access`- `application_support`- `service_request`- `spam_phishing`- `general_inquiry`- `security_compliance`- `onboarding`- `feature_request`
### Assignment groups
- `license_ops`- `service_desk`- `application_team`- `procurement`- `security_team`- `onboarding_ops`
### Resolution actions
- `fulfill`- `escalate`- `assign`- `ignore`- `acknowledge`
## Part 7: Episode Flow
### `reset()`
Starts a new episode:
1. chooses a task2. samples a queue of tickets3. resets state4. returns the first observation
### `step(action)`
Processes one ticket:
1. grades the action2. stores the score3. advances the queue index4. returns the next ticket or the final reward
### `state`
Returns the internal state snapshot.
## Part 8: Reward Logic
Step reward:
- just the current ticket score clamped to `[0.0, 1.0]`
Final reward:
- average of all per-ticket scores- minus a small overshoot penalty if too many steps were taken
This keeps the signal dense and easy to interpret.
## Part 9: Dataset Shape
Each ticket record contains:
- `ticket_id`- `title`- `requester`- `description`- `issue_type`- `priority`- `assignment_group`- `resolution_action`- optional `ambiguity_note`- optional `related_ticket_id`
The current dataset contains 45 tickets.
It includes:
- straightforward tickets- ambiguous tickets- follow-up references to earlier tickets
## Part 10: Inference Script In Simple Terms
`inference.py` is the script that actually "plays" the environment.
For each task it:
1. connects to the server2. resets the environment3. reads the current ticket4. decides an action5. sends the action back6. collects scores7. prints a summary
If LLM credentials are available, it uses an LLM.If not, it uses keyword rules.
## Part 11: What Still Needs Verification
The important next checks are:
1. run the server locally2. verify the ticket-routing client path works end to end3. rerun `inference.py`4. record fresh baseline scores5. validate Docker and OpenEnv behavior
## Part 12: One-Minute Summary
If you only remember one thing, remember this:
- this repo is now an IT helpdesk ticket router- the mechanics are still the same multi-step OpenEnv pattern- one ticket is shown at a time- the agent predicts structured routing fields- the grader gives deterministic partial credit- `inference.py` is the baseline agent runner1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556# Label Audit Notes
This file records the March 31 and April 1 label-and-grader pass on the Roopal-owned files:
- `data/dataset.json`- `server/tasks.py`- `server/grader.py`
## Dataset Decisions
### Tightened ambiguity cases
- `ticket-022` Reworded to make the billing-versus-application ambiguity clearer while keeping the chosen label as `application_support`.
- `ticket-027` Reworded to make the vendor-offer ambiguity clearer between `general_inquiry` and `service_request`.
- `ticket-029` Reworded to make the seat-expansion versus prorating ambiguity clearer and changed `resolution_action` from `fulfill` to `assign`.
- `ticket-040` Reworded to make the feature-gap versus support-issue ambiguity clearer.
### Corrected label consistency
- `ticket-026` Changed from `feature_request` / `application_team` to `general_inquiry` / `service_desk` because it is a thank-you note, not a product change request.
## Task Wording Changes
The task instructions in `server/tasks.py` were tightened so they now:
- sound more like helpdesk triage- emphasize choosing the single best label- describe operational priority more clearly- describe full triage more concretely for Task 3
## Grader Changes
The grader was polished by:
- making task weights explicit in `TASK_WEIGHTS`- adding partial-credit pairs for: - `application_support` vs `feature_request` - `general_inquiry` vs `service_request`- keeping the scoring deterministic and task-specific
## Intent
These edits are meant to improve:
- dataset realism- label consistency- hard-task ambiguity quality- reviewability for judges and teammates123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117# March 30 Status Report
This file captures the code checkpoint completed for March 30, 2026 so both Codex sessions can compare against the same source of truth.
## Scope Completed
The March 30 code checkpoint is complete for the foundational files named in `ROADMAP.md`:
- `models.py`- `server/tasks.py`- `server/grader.py`- `server/environment.py`
Related supporting files were also aligned:
- `client.py`- `server/app.py`- `inference.py`- `vocabulary.py`
## What Is Locked
### Team and project identity
- Team: Hackstreet Boys- Members: Roopal Guha Neogi, Suyash Kumar- Domain: IT Helpdesk Ticket Routing
### Frozen class names
- `HelpdeskTicketRecord`- `HelpdeskTicketAction`- `HelpdeskTicketObservation`- `HelpdeskTicketState`- `HelpdeskTicketRoutingEnvironment`- `HelpdeskTicketEnvClient`
### Frozen field names
- `ticket_id`- `title`- `requester`- `description`- `issue_type`- `priority`- `assignment_group`- `resolution_action`- `related_ticket_id`
## Code That Exists Now
### `vocabulary.py`
Shared frozen constants now live in one place:
- team metadata- environment names- issue types- priorities- assignment groups- resolution actions- default issue-type mappings used by inference
### `models.py`
The typed models are defined and the vocabulary is enforced through validators, so unsupported labels should fail fast instead of silently drifting.
### `server/tasks.py`
All three tasks are defined with locked names, instructions, and allowed fields.
### `server/grader.py`
Deterministic scoring is in place with:
- partial credit for near-miss `issue_type`- proximity scoring for `priority`- exact match for `assignment_group`- exact match for `resolution_action`
### `server/environment.py`
The environment implements:
- queue sampling- reset flow- step flow- state tracking- final trajectory reward handoff
### `inference.py`
The baseline runner is aligned to the locked vocabulary and supports:
- LLM mode- heuristic mode- task loop over all 3 tasks
## Expected Agreement For The Other Codex Session
Your teammate's Codex should agree on all of the following:
1. the schema names above are frozen2. the vocabulary now has a single source of truth in `vocabulary.py`3. no one should rename labels after this checkpoint4. future work should build on these names, not replace them
## What Is Not Verified Yet
This checkpoint is a code-and-consistency checkpoint, not a runtime-complete checkpoint.
Still pending:
- local execution- heuristic baseline run- Docker validation- final benchmark numbers123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155# IT Helpdesk Ticket Routing Mental Model
This file is the practical mental model of the repo in its current form.
## What The Project Is
This repository is an OpenEnv environment for IT helpdesk ticket routing.
The environment presents a small queue of tickets. For each ticket, the agent must decide:
- issue type- priority- assignment group- resolution action
## Main Runtime Flow
```textinference.py | vclient.py <----> server/app.py | v server/environment.py | | | v v v grader.py reward.py tasks.py | v data/dataset.json```
## Main Files
- `models.py` Typed models for tickets, actions, observations, and state.
- `server/environment.py` Main environment engine.
- `server/grader.py` Deterministic partial-credit scorer.
- `server/reward.py` Step and trajectory reward helpers.
- `server/tasks.py` Task definitions and dataset loading.
- `client.py` Typed client used for multi-step interaction.
- `inference.py` Baseline runner with LLM mode and heuristic mode.
## Task Ladder
### Task 1
- predict `issue_type`
### Task 2
- predict `issue_type`- predict `priority`
### Task 3
- predict `issue_type`- predict `priority`- predict `assignment_group`- predict `resolution_action`
## Label Vocabulary
### Issue types
- `billing_license`- `identity_access`- `application_support`- `service_request`- `spam_phishing`- `general_inquiry`- `security_compliance`- `onboarding`- `feature_request`
### Assignment groups
- `license_ops`- `service_desk`- `application_team`- `procurement`- `security_team`- `onboarding_ops`
### Resolution actions
- `fulfill`- `escalate`- `assign`- `ignore`- `acknowledge`
## Observation And State
The observation exposes:
- task metadata- the current ticket- queue progress counters- history- reward and done status
The state tracks:
- current task- seed- queue ticket IDs- current ticket index- per-ticket scores- total reward
## Reward Logic
- each step returns the current ticket score- the final reward is the average of per-ticket scores- a small overshoot penalty exists as a safeguard
## Dataset Shape
Each record includes:
- `ticket_id`- `title`- `requester`- `description`- `issue_type`- `priority`- `assignment_group`- `resolution_action`- optional `ambiguity_note`- optional `related_ticket_id`
## Short Version
If coming back later, remember this:
- the repo is a helpdesk ticket router- the architecture is a small OpenEnv stack- one ticket is shown at a time- the agent predicts structured routing fields- the grader gives deterministic partial credit- `inference.py` is the baseline agent runner123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147# IT Helpdesk Ticket Routing OpenEnv - Project Plan
## Project Goal
Build a polished OpenEnv environment for IT helpdesk ticket routing that satisfies:
- real-world utility- strong task and grader quality- clean environment design- OpenEnv spec compliance- reproducible baseline inference- Docker and Hugging Face deployment readiness
## Current Product Definition
The environment simulates a helpdesk queue. An agent receives one ticket at a time and predicts:
- `issue_type`- `priority`- `assignment_group`- `resolution_action`
The project keeps three tasks:
1. Issue Type Classification2. Issue Type And Priority3. Full Ticket Routing
## What Must Be True At Submission
### Pass or fail requirements
- the environment responds correctly- OpenEnv metadata is valid- `reset()`, `step()`, and `state()` work- there are at least 3 tasks- graders return scores in `[0.0, 1.0]`- `inference.py` runs and prints reproducible results- Docker builds and starts cleanly
### Scored requirements
- the task should clearly feel like real helpdesk work- the hard task should require meaningful reasoning- partial credit should be useful and deterministic- docs should be clear enough for judges to understand quickly
## Core Files
### Runtime
- `models.py`- `server/environment.py`- `server/grader.py`- `server/reward.py`- `server/tasks.py`- `server/app.py`- `client.py`- `inference.py`
### Data and metadata
- `data/dataset.json`- `openenv.yaml`- `server/Dockerfile`- `pyproject.toml`- `requirements.txt`
### Docs
- `README.md`- `KNOWLEDGE.md`- `MENTAL_MODEL.md`
## Technical Priorities
### P0
1. keep the environment behavior correct2. verify the task definitions and graders3. make the baseline script reliable4. confirm dataset coverage and label consistency
### P1
1. validate Docker2. validate deployment assumptions3. record baseline scores4. polish docs
### P2
1. strengthen ticket wording for realism2. expand hard-case examples if needed3. remove low-signal artifacts from the repo
## Quality Checks To Perform
### Environment
- reset starts a clean episode- each step advances the queue correctly- the final step returns trajectory reward- state reflects the real internal status
### Grader
- exact matches score `1.0`- near misses get partial credit where intended- unsupported task IDs fail clearly- scores vary across examples
### Inference
- heuristic mode works without model credentials- LLM mode reads `API_BASE_URL`, `MODEL_NAME`, and `HF_TOKEN`- output is reproducible when the seed is fixed
### Docs
- no outdated domain references remain- team and project metadata are correct- setup and run instructions are accurate
## Risks
### Runtime risk
The repo still needs a proper local execution pass to confirm everything after the latest edits.
### Benchmark risk
Fresh scores must be generated and then reflected in docs.
### Deployment risk
Docker and Hugging Face behavior should be validated before the final submission window.
## Definition Of Done
The project is ready when:
1. the environment runs locally end to end2. the heuristic baseline runs successfully3. Docker build and run both succeed4. the docs are clean, current, and submission-ready5. the repo clearly presents Hackstreet Boys as the team123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472Round 1 — Problem Statement
The Task
Build a complete, real-world OpenEnv environment that an AI agent can learn from through the standard step() / reset() / state() API.
Key Requirements at a Glance
Must simulate a real-world task (not games or toys)
Implement full OpenEnv spec: typed models, step()/reset()/state(), openenv.yaml
Minimum 3 tasks with agent graders (easy → medium → hard, scores 0.0–1.0)
Meaningful reward function with partial progress signals
Baseline inference script with reproducible scores
Deploy to Hugging Face Spaces + working Dockerfile
README with environment description, action/observation spaces, setup instructions
Real-world task simulation
The environment must simulate a task humans actually do. Not games, not toys. Examples: email triage, code review, data cleaning, scheduling, customer support, content moderation.
OpenEnv spec compliance
Implement the full OpenEnv interface: typed Observation, Action, and Reward Pydantic models. step(action) → returns observation, reward, done, info. reset() → returns initial observation. state() → returns current state. openenv.yaml with metadata. Tested via openenv validate.
Minimum 3 tasks with agent graders
Each task defines a concrete objective an agent must accomplish, with a programmatic grader that scores performance (0.0–1.0). Tasks should range: easy → medium → hard. Graders must have clear, deterministic success/failure criteria.
Meaningful reward function
Provides signal over the full trajectory (not just binary end-of-episode). Rewards partial progress toward task completion. Penalizes clearly undesirable behavior (e.g. infinite loops, destructive actions).
Baseline inference script
Uses the OpenAI API client to run a model against the environment. Reads API credentials from environment variables (OPENAI_API_KEY). Produces a reproducible baseline score on all 3 tasks.___________________________________________Detailed Requirements
Non-Functional Requirements
Deploys to a Hugging Face Space
Environment must run as a containerized HF Space tagged with openenv.
Containerized execution
Must include a working Dockerfile. The environment should start cleanly with docker build + docker run.
Documentation
README must include: environment description and motivation, action and observation space definitions, task descriptions with expected difficulty, setup and usage instructions, baseline scores.___________________________________________
Parameter
Weight
Description
Real-world utility
30%
Does the environment model a genuine task? Would someone actually use this to train or evaluate agents?
Task & grader quality
25%
Are tasks well-defined with clear objectives? Do graders accurately and fairly measure success? Meaningful difficulty progression?
Environment design
20%
Clean state management, sensible action/observation spaces, good reward shaping, proper episode boundaries.
Code quality & spec compliance
15%
Follows OpenEnv spec, clean project structure, typed models, documented, tested, Dockerfile works.
Creativity & novelty
10%
Novel problem domain, interesting mechanics, clever reward design, original approach.
Scoring Breakdown
Real-world utility (30%)
• 0–5: Toy/artificial problem with no practical application
• 6–15: Valid domain but shallow modeling of the real task
• 16–25: Good domain modeling, would be useful for agent evaluation
• 26–30: Excellent — fills a real gap, immediate value for the RL/agent community
Task & grader quality (25%)
• 3+ tasks with difficulty range?
• Graders produce scores between 0.0–1.0?
• Graders deterministic and reproducible?
• Hard task genuinely challenges frontier models?
Environment design (20%)
• reset() produces clean state?
• Action/observation types well-designed and documented?
• Reward function provides useful varying signal (not just sparse)?
• Episode boundaries sensible?
Code quality & spec compliance (15%)
• openenv validate passes?
• docker build && docker run works?
• HF Space deploys and responds?
• Baseline script runs and reproduces scores?
Creativity & novelty (10%)
• Domain we haven’t seen in OpenEnv before?
• Reward design has interesting properties?
• Clever mechanics that make the environment engaging________________________________________
Phase 1: Automated Validation
Pass/fail gate — HF Space deploys, OpenEnv spec compliance, Dockerfile builds, baseline reproduces, 3+ tasks with graders.
Phase 2: Agentic Evaluation
Scored — baseline agent re-run, standard Open LLM agent (e.g. Nemotron 3 Super) run against all environments, score variance check.
Phase 3: Human Review
Top submissions reviewed by Meta and Hugging Face engineers for real-world utility, creativity, and exploit checks.
Disqualification Criteria
Environment does not deploy or respond
Plagiarized or trivially modified existing environments
Graders that always return the same score
No baseline inference script__________________________________________
HF Space deploys
Automated ping to the Space URL — must return 200 and respond to reset()
OpenEnv spec compliance
Validate openenv.yaml, typed models, step()/reset()/state() endpoints
Dockerfile builds
Automated docker build on the submitted repo
Baseline reproduces
Run the submitted inference script — must complete without error and produce scores
3+ tasks with graders
Enumerate tasks, run each grader, verify scores in 0.0–1.0 range
Additional Instructions
Before submitting, ensure the following variables are defined in your environment configuration:
API_BASE_URL The API endpoint for the LLM.
MODEL_NAME The model identifier to use for inference.
HF_TOKEN Your Hugging Face / API key.
The inference script must be named `inference.py` and placed in the root directory of the project
Participants must use OpenAI Client for all LLM calls using above variables
Infra Restrictions
Runtime of inference script should be less than 20min
Make sure your env and inference can run on a machine with vcpu=2, memory=8gb
Validator
Run the pre-submission validation script before submitting
__________________________________________SAMPLE INFERENCE SCRIPT:________________________Inference Script Example===================================MANDATORY- Before submitting, ensure the following variables are defined in your environment configuration: API_BASE_URL The API endpoint for the LLM. MODEL_NAME The model identifier to use for inference. HF_TOKEN Your Hugging Face / API key. - The inference script must be named `inference.py` and placed in the root directory of the project- Participants must use OpenAI Client for all LLM calls using above variables"""
import osimport reimport base64import textwrapfrom io import BytesIOfrom typing import List, Optional, Dict
from openai import OpenAIimport numpy as npfrom PIL import Image
from browsergym_env import BrowserGymAction, BrowserGymEnv
API_BASE_URL = os.getenv("API_BASE_URL") // "https://router.huggingface.co/v1"API_KEY = os.getenv("HF_TOKEN") or os.getenv("API_KEY")MODEL_NAME = os.getenv("MODEL_NAME")MAX_STEPS = 8MAX_DOM_CHARS = 3500TEMPERATURE = 0.2MAX_TOKENS = 200FALLBACK_ACTION = "noop()"
DEBUG = TrueACTION_PREFIX_RE = re.compile( r"^(action|next action)\s*[:\-]\s*", re.IGNORECASE,)ACTION_PATTERN = re.compile(r"[A-Za-z_]+\s*\(.*\)", re.DOTALL)
SYSTEM_PROMPT = textwrap.dedent( """ You control a web browser through BrowserGym. Reply with exactly one action string. The action must be a valid BrowserGym command such as: - noop() - click('<BID>') - type('selector', 'text to enter') - fill('selector', 'text to enter') - send_keys('Enter') - scroll('down') Use single quotes around string arguments. When clicking, use the BrowserGym element IDs (BIDs) listed in the user message. If you are unsure, respond with noop(). Do not include explanations or additional text. """).strip()
def build_history_lines(history: List[str]) -> str: if not history: return "None" return "\n".join(history[-4:])
def extract_screenshot_uri(observation) -> Optional[str]: if observation.screenshot is None: return None screen_array = np.array(observation.screenshot, dtype=np.uint8) image = Image.fromarray(screen_array) buffer = BytesIO() image.save(buffer, format="PNG") buffer.seek(0) data_uri = base64.b64encode(buffer.read()).decode("utf-8") return f"data:image/png;base64,{data_uri}"
def extract_clickable_elements(observation) -> List[Dict[str, str]]: """Collect BrowserGym element IDs that can be clicked."""
metadata = getattr(observation, "metadata", {}) or {} obs_dict = metadata.get("browsergym_obs", {}) or {} extra_props = obs_dict.get("extra_element_properties", {}) or {}
clickables: List[Dict[str, str]] = [] for bid, props in extra_props.items(): if not props.get("clickable"): continue
bbox = props.get("bbox") or [] bbox_str = ", ".join(bbox) if bbox else "?" clickables.append( { "bid": str(bid), "bbox": bbox_str, } )
# Keep a stable ordering for readability clickables.sort(key=lambda item: item["bid"]) return clickables
def build_user_prompt(step: int, observation, history: List[str]) -> str: goal = observation.goal or "(not provided)" url = observation.url or "(unknown)" error_note = "Yes" if observation.last_action_error else "No"
clickables = extract_clickable_elements(observation) if clickables: actions_hint = "\n".join( f" - {item['bid']} (bbox: {item['bbox']})" for item in clickables ) else: actions_hint = " (none detected)"
prompt = textwrap.dedent( f""" Step: {step} Goal: {goal} Current URL: {url} Previous steps: {build_history_lines(history)} Last action error: {error_note} Available clickable element IDs: {actions_hint} Reply with exactly one BrowserGym action string. """ ).strip() return prompt
def parse_model_action(response_text: str) -> str: if not response_text: return FALLBACK_ACTION
# Prefer the first line that looks like an action string lines = response_text.splitlines() for raw_line in lines: line = raw_line.strip() if not line: continue line = ACTION_PREFIX_RE.sub("", line) match = ACTION_PATTERN.search(line) if match: action = match.group(0).strip() # Collapse internal whitespace action = re.sub(r"\s+", " ", action) # If the model tried to click by natural-language description while we # only exposed numeric BrowserGym IDs, fallback to the single detected ID. return action
# Fall back to searching the whole response match = ACTION_PATTERN.search(response_text) if match: action = match.group(0).strip() action = re.sub(r"\s+", " ", action) return action
return FALLBACK_ACTION
def main() -> None: client = OpenAI(base_url=API_BASE_URL, api_key=API_KEY)
env = BrowserGymEnv.from_docker_image( image="browsergym-env:latest", env_vars={ "BROWSERGYM_BENCHMARK": "miniwob", "BROWSERGYM_TASK_NAME": "click-test", }, )
history: List[str] = []
try: result = env.reset() observation = result.observation print(f"Episode goal: {observation.goal}")
for step in range(1, MAX_STEPS + 1): if result.done: print("Environment signalled done. Stopping early.") break
user_prompt = build_user_prompt(step, observation, history) user_content = [{"type": "text", "text": user_prompt}] screenshot_uri = extract_screenshot_uri(observation) if screenshot_uri: user_content.append( { "type": "image_url", "image_url": {"url": screenshot_uri}, } )
messages = [ { "role": "system", "content": [{"type": "text", "text": SYSTEM_PROMPT}], }, { "role": "user", "content": user_content, }, ]
try: completion = client.chat.completions.create( model=MODEL_NAME, messages=messages, temperature=TEMPERATURE, max_tokens=MAX_TOKENS, stream=False, ) response_text = completion.choices[0].message.content or "" # pylint: disable=broad-except except Exception as exc: # noqa: BLE001 failure_msg = f"Model request failed ({exc}). Using fallback action." print(failure_msg) response_text = FALLBACK_ACTION
action_str = parse_model_action(response_text) print(f"Step {step}: model suggested -> {action_str}")
result = env.step(BrowserGymAction(action_str=action_str)) observation = result.observation
reward = result.reward or 0.0 error_flag = " ERROR" if observation.last_action_error else "" history_line = ( f"Step {step}: {action_str} -> reward {reward:+.2f}{error_flag}" ) history.append(history_line) print( " Reward: " f"{reward:+.2f} | Done: {result.done} | Last action error: " f"{observation.last_action_error}" )
if result.done: print("Episode complete.") break
else: print(f"Reached max steps ({MAX_STEPS}).")
finally: env.close()
if __name__ == "__main__": main() ____________________________________123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258# IT Helpdesk Ticket Routing OpenEnv
> Meta PyTorch OpenEnv Hackathon - Round 1 Submission> Team Hackstreet Boys - Roopal Guha Neogi, Suyash Kumar
A deterministic, multi-step IT helpdesk ticket routing environment built on the OpenEnv framework. An AI agent receives a small queue of helpdesk tickets and must classify the issue type, estimate priority, assign the correct resolver group, and choose the best next action.
## Why IT Helpdesk Ticket Routing?
IT service desks do this work every day:
- read a newly created ticket- decide what kind of issue it is- judge urgency- route it to the right team- decide whether to fulfill, escalate, assign, ignore, or acknowledge it
This makes the domain:
- genuinely real-world- easy to evaluate deterministically- naturally multi-step- well aligned with enterprise support and agent-routing workflows
## Architecture
```textinference.py | vclient.py <----> server/app.py | v server/environment.py | | | v v v grader.py reward.py tasks.py | v data/dataset.json```
Key architectural detail:
- the environment is designed as a multi-step ticket queue- the client path is used for persistent episode flow- the environment still follows the standard OpenEnv `reset()`, `step()`, and `state()` interface
## Tasks
| ID | Name | Difficulty | Fields Required | Description ||----|------|------------|-----------------|-------------|| 1 | Issue Type Classification | Easy | `issue_type` | Classify the ticket into the correct IT issue type || 2 | Issue Type And Priority | Medium | `issue_type`, `priority` | Classify the issue and estimate urgency || 3 | Full Ticket Routing | Hard | `issue_type`, `priority`, `assignment_group`, `resolution_action` | Perform full helpdesk routing |
## Action Space
The agent submits a `HelpdeskTicketAction`. Only the fields relevant to the current task are scored.
```json{ "issue_type": "billing_license | identity_access | application_support | service_request | spam_phishing | general_inquiry | security_compliance | onboarding | feature_request", "priority": "critical | high | medium | low", "assignment_group": "license_ops | service_desk | application_team | procurement | security_team | onboarding_ops", "resolution_action": "fulfill | escalate | assign | ignore | acknowledge"}```
## Observation Space
Each observation contains:
- `task_id`- `task_name`- `instructions`- `allowed_fields`- `current_ticket`- `queue_size`- `tickets_remaining`- `tickets_processed`- `history`- inherited OpenEnv fields such as `done` and `reward`
The visible ticket fields are:
- `ticket_id`- `title`- `requester`- `description`
Ground-truth labels are not exposed to the agent.
## State
The internal `HelpdeskTicketState` tracks:
- `episode_id`- `step_count`- `current_task_id`- `seed`- `queue_ticket_ids`- `current_ticket_index`- `per_ticket_scores`- `total_reward`
## Grading
Scoring is deterministic and ranges from `0.0` to `1.0`.
### Per-field logic
- `issue_type`: exact match or partial credit for near-miss pairs- `priority`: exact match or proximity score- `assignment_group`: exact match- `resolution_action`: exact match
### Task weights
| Task | Issue Type | Priority | Assignment Group | Resolution Action ||------|------------|----------|------------------|-------------------|| 1 | 100% | - | - | - || 2 | 60% | 40% | - | - || 3 | 35% | 20% | 25% | 20% |
### Trajectory reward
At episode end:
```texttrajectory_reward = average(per_ticket_scores) - 0.03 * max(0, steps_taken - queue_size)```
The result is clamped to `[0.0, 1.0]`.
## Dataset
`data/dataset.json` contains 45 labeled helpdesk tickets covering:
- issue classification- access requests- application incidents- procurement and service requests- phishing or spam reports- security and compliance work- onboarding tickets- feature requests
The dataset also includes:
- ambiguous cases- follow-up thread references- multiple priority levels
## Project Structure
```textserver/ app.py environment.py grader.py reward.py tasks.py Dockerfiledata/ dataset.jsonmodels.pyclient.pyinference.pyopenenv.yamlpyproject.tomlrequirements.txtREADME.mdKNOWLEDGE.mdPLAN.mdMENTAL_MODEL.md```
## Setup
Install dependencies:
```bashpip install -r requirements.txt```
Start the server:
```bashuvicorn server.app:app --host 0.0.0.0 --port 8000```
Basic checks:
```bashcurl http://localhost:8000/healthcurl http://localhost:8000/tasks```
## Running Inference
### LLM mode
Set:
- `API_BASE_URL`- `MODEL_NAME`- `HF_TOKEN`
Then run:
```bashpython inference.py```
### Heuristic mode
If those variables are not set, the script falls back to a keyword-based ticket router:
```bashpython inference.py```
Optional server target:
- `ENV_URL` default: `http://localhost:8000`
## Docker
Build and run:
```bashdocker build -f server/Dockerfile -t helpdesk-ticket-routing .docker run -p 7860:7860 helpdesk-ticket-routing```
## API Endpoints
OpenEnv auto-generates the main endpoints, and the repo adds `/tasks`.
| Method | Path | Description ||--------|------|-------------|| GET | `/health` | Health check || POST | `/reset` | Start a new episode || POST | `/step` | Submit an action || GET | `/state` | Inspect state || WebSocket | `/ws` | Persistent client channel || GET | `/tasks` | List available tasks || GET | `/docs` | API docs |
## Baseline Status
Fresh baseline scores should be recorded after the next validation pass. The recommended order is:
1. run the environment locally2. run the heuristic baseline in `inference.py`3. record per-task and overall scores4. update the docs only after those numbers are verified123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339# Hackstreet Boys Roadmap
## Team
- Team name: Hackstreet Boys- Members: - Roopal Guha Neogi - Suyash Kumar- Submission deadline: April 8, 2026, 11:59 PM IST
## Goal
Ship a clean, well-documented OpenEnv environment for IT helpdesk ticket routing that:
- passes all submission gates- scores well on real-world utility- has deterministic, defensible grading- is easy for judges to understand and rerun
## When You Start Coding
Start coding immediately on **March 30, 2026** after a short 30 to 60 minute alignment pass.
That first coding session should do only high-leverage foundation work:
- lock the exact ticket vocabulary- freeze field names in `models.py`- confirm task fields in `server/tasks.py`- agree on grader labels in `server/grader.py`- agree that no one changes schema names casually after this point
### First coding targets on March 30, 2026
Roopal should start with:
- `data/dataset.json`- `server/tasks.py`- `server/grader.py`
Suyash should start with:
- `models.py`- `server/environment.py`- `inference.py`
By the end of the first coding block, both of you should have:
- matching field names- matching task labels- matching issue-type vocabulary- no unresolved schema disagreements
## Working Model For Two People
The safest way for two people to work separately and merge cleanly is to divide ownership by file groups, not by abstract ideas.
### Roopal ownership
- `data/dataset.json`- `server/tasks.py`- `server/grader.py`- `README.md`- `KNOWLEDGE.md`- `MENTAL_MODEL.md`
Primary responsibilities:
- dataset quality- label consistency- task wording- grader realism- documentation clarity- judging-story polish
### Suyash ownership
- `models.py`- `server/environment.py`- `server/app.py`- `server/reward.py`- `client.py`- `inference.py`- `openenv.yaml`- `server/Dockerfile`- `pyproject.toml`- `requirements.txt`
Primary responsibilities:
- runtime correctness- OpenEnv interface- inference reliability- Docker and deployment readiness- integration behavior
## Merge Strategy
To keep parallel work easy to combine:
1. avoid editing the same file on the same day unless planned2. use one shared terminology list and do not invent alternate labels3. sync once daily with a 10 minute review of: - changed files - open blockers - any schema changes4. freeze the dataset schema early5. freeze the action and observation field names early
## Shared Source Of Truth
These files should be treated as authoritative:
- `README.md` for the public project story- `PLAN.md` for project requirements and definition of done- `MENTAL_MODEL.md` for the current system shape- `openenv.yaml` for environment metadata- `server/tasks.py` and `server/grader.py` for task rules
## AI Usage Policy
AI is permitted, so use it aggressively where it saves time, but do not outsource judgment.
Good uses of AI:
- draft clearer task descriptions- propose additional hard-case tickets- suggest edge cases and label audits- improve prompts in `inference.py`- generate test ideas and checklists- improve README structure and wording
Human review required for:
- final dataset labels- grader weights and partial-credit rules- any claims in README- final benchmark numbers- submission metadata and deployment settings
## Submission Criteria Checklist
### Must pass
- environment starts correctly- `reset()`, `step()`, and `state()` behave correctly- 3 tasks exist and are meaningfully different- grader scores are in `[0.0, 1.0]`- `inference.py` runs without error- Docker builds and starts- docs are complete and current
### Must score well
- the task feels like real IT helpdesk work- the hard task is genuinely harder- the grader gives partial credit in sensible ways- the environment is easy to understand and rerun
## Timeline
### March 30, 2026
- lock team name, domain, and vocabulary- finish repo cleanup- agree on ownership split- start coding the core schema and task logic immediately after the vocabulary lock- target a same-day checkpoint on: - `models.py` - `server/tasks.py` - `server/grader.py` - `server/environment.py`
### March 31, 2026
Roopal:
- audit `data/dataset.json` labels end to end- tighten ambiguous cases- review task wording in `server/tasks.py`- continue code work in `server/grader.py` if partial-credit tuning is still needed
Suyash:
- sanity-check `models.py`, `server/environment.py`, and `client.py`- check that the field names align everywhere- continue code work in `inference.py` and `server/app.py`
Shared checkpoint:
- confirm no schema changes are still pending
### April 1, 2026
Roopal:
- polish `server/grader.py`- confirm hard-task logic and partial-credit behavior- finish any remaining dataset label corrections
Suyash:
- polish `inference.py`- confirm heuristic mode uses the new ticket vocabulary consistently- finish runtime code adjustments in `client.py`, `server/app.py`, and `server/reward.py`
Shared checkpoint:
- agree on the exact labels and examples used in docs
### April 2, 2026
Roopal:
- improve `README.md`- improve `KNOWLEDGE.md`
Suyash:
- validate `openenv.yaml`- validate `server/Dockerfile`- validate dependency files
Shared checkpoint:
- ensure docs and code tell the same story
### April 3, 2026
Roopal:
- do a dataset realism pass- make sure examples clearly cover easy, medium, and hard cases
Suyash:
- perform the first full local runtime pass- run heuristic inference- note bugs or schema mismatches
Shared checkpoint:
- bug triage and fix list
### Practical coding rule
If you are wondering "should we still be planning or should we code now?", the answer is:
- **March 30 to April 4, 2026 = active coding and fixes**- **April 5 to April 6, 2026 = validation, docs, and score recording**- **April 7 to April 8, 2026 = freeze, smoke tests, and submission**
### April 4, 2026
Roopal:
- fix data, wording, and documentation issues from runtime feedback
Suyash:
- fix environment, inference, and Docker issues from runtime feedback
Shared checkpoint:
- second full local run
### April 5, 2026
Roopal:
- finalize README and knowledge docs- prepare a concise judge-facing explanation of the domain
Suyash:
- confirm Docker flow- confirm all required env vars are documented and handled
Shared checkpoint:
- record benchmark numbers if stable
### April 6, 2026
- full dry run from a clean copy if possible- verify every required file is present- check for stale claims and outdated wording
### April 7, 2026
- freeze feature changes- only bug fixes, validation, and submission packaging- verify final docs, metadata, and benchmark numbers
### April 8, 2026
- do one last deployment and smoke test early in the day- stop risky edits several hours before deadline- submit before 11:59 PM IST
## Integration Rules
To keep merges painless:
1. do not rename schemas after April 1, 20262. do not change task labels after April 2, 2026 without both agreeing3. do not edit ownership files casually4. if one person must touch the other person's file, call it out before doing it5. keep a short daily changelog in chat or a shared note
## Definition Of Done For Each Member
### Roopal done means
- dataset labels are internally consistent- docs are submission-ready- the hard task feels meaningfully harder than the easy and medium tasks
### Suyash done means
- the environment runs end to end- the inference script works in heuristic mode- Docker and metadata are in good shape
## Final Two-Day Priority Order
If time gets tight, prioritize in this exact order:
1. working environment2. working inference script3. valid grader and tasks4. Docker and metadata5. README clarity6. extra polish
## Simple Rule To Remember
Roopal owns the story and the labels.Suyash owns the runtime and the rails.Both review the final submission together.12345678910111213141516171819202122232425262728from __future__ import annotations
from typing import Any, Dict, Optional
from openenv.core.env_client import EnvClient, StepResult
from models import HelpdeskTicketAction, HelpdeskTicketObservation, HelpdeskTicketState
class HelpdeskTicketEnvClient( EnvClient[HelpdeskTicketAction, HelpdeskTicketObservation, HelpdeskTicketState]): def _step_payload(self, action: HelpdeskTicketAction) -> Dict[str, Any]: return action.model_dump(exclude_none=True)
def _parse_result( self, payload: Dict[str, Any] ) -> StepResult[HelpdeskTicketObservation]: obs_data = payload.get("observation", payload) obs = HelpdeskTicketObservation.model_validate(obs_data) return StepResult( observation=obs, reward=payload.get("reward", obs.reward), done=payload.get("done", obs.done), )
def _parse_state(self, payload: Dict[str, Any]) -> HelpdeskTicketState: return HelpdeskTicketState.model_validate(payload)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543[ { "ticket_id": "ticket-001", "title": "Urgent: customer charged twice for March invoice", "requester": "ap@northstar-retail.com", "description": "Our finance team found two charges on the same invoice and needs a refund processed today.", "issue_type": "billing_license", "priority": "high", "assignment_group": "license_ops", "resolution_action": "escalate", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-002", "title": "Can not sign in after 2FA reset", "requester": "ops@laneeight.io", "description": "I was forced to reset 2FA and now the account stays locked even with the backup code.", "issue_type": "identity_access", "priority": "high", "assignment_group": "service_desk", "resolution_action": "fulfill", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-003", "title": "Production checkout throwing null reference exception", "requester": "sre@paperkite.dev", "description": "Customers can not complete payment in production. This is blocking revenue right now.", "issue_type": "application_support", "priority": "critical", "assignment_group": "application_team", "resolution_action": "escalate", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-004", "title": "Requesting pricing for 300-seat rollout", "requester": "procurement@solsticehealth.org", "description": "We are evaluating vendors and want a quote for an enterprise rollout next quarter.", "issue_type": "service_request", "priority": "medium", "assignment_group": "procurement", "resolution_action": "assign", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-005", "title": "Guaranteed crypto income from home", "requester": "promo@fastwealth.example", "description": "Limited time offer. Click now to multiply your income and unsubscribe never.", "issue_type": "spam_phishing", "priority": "low", "assignment_group": "security_team", "resolution_action": "ignore", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-006", "title": "Refund still missing for canceled annual plan", "requester": "controller@redcedar.co", "description": "We canceled three weeks ago and the refund has not arrived. Please confirm status.", "issue_type": "billing_license", "priority": "medium", "assignment_group": "license_ops", "resolution_action": "fulfill", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-007", "title": "GDPR data deletion request — 30 day deadline", "requester": "legal@eurocorp.de", "description": "Per GDPR Article 17, we request deletion of all personal data associated with our account within 30 days. Failure to comply may result in regulatory action.", "issue_type": "security_compliance", "priority": "critical", "assignment_group": "security_team", "resolution_action": "escalate", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-008", "title": "Welcome aboard — getting started with your new account", "requester": "success@brightpath.io", "description": "Thanks for signing up! We\u0027d like to schedule an onboarding call this week. What time works for your team?", "issue_type": "onboarding", "priority": "medium", "assignment_group": "onboarding_ops", "resolution_action": "fulfill", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-009", "title": "Feature suggestion: dark mode for dashboard", "requester": "ux-team@designhub.co", "description": "Our users have been requesting dark mode for months. Would love to see this on the roadmap.", "issue_type": "feature_request", "priority": "low", "assignment_group": "application_team", "resolution_action": "acknowledge", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-010", "title": "Password reset link expired before I could use it", "requester": "jsmith@midtownlogistics.com", "description": "I requested a password reset but by the time I checked my email the link had expired. Can you send a new one?", "issue_type": "identity_access", "priority": "medium", "assignment_group": "service_desk", "resolution_action": "fulfill", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-011", "title": "API rate limiting causing data sync failures", "requester": "devops@streamline.app", "description": "Our integration is hitting 429 errors every hour during peak load. We need the rate limit raised or a bulk endpoint.", "issue_type": "application_support", "priority": "high", "assignment_group": "application_team", "resolution_action": "escalate", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-012", "title": "Interested in a live demo for our leadership team", "requester": "cto@nexwave.io", "description": "We have budget allocated for Q3 and would like a 30-minute demo with our CTO and VP Eng.", "issue_type": "service_request", "priority": "high", "assignment_group": "procurement", "resolution_action": "assign", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-013", "title": "Free vacation giveaway — claim your prize", "requester": "offers@tropicaldeals.example", "description": "Congratulations! You have been selected for an all-expenses-paid trip. Click here immediately.", "issue_type": "spam_phishing", "priority": "low", "assignment_group": "security_team", "resolution_action": "ignore", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-014", "title": "Audit report findings — action required by Friday", "requester": "audit@compliancepartners.com", "description": "The SOC2 audit uncovered three medium-severity findings. Remediation evidence is due by end of week.", "issue_type": "security_compliance", "priority": "high", "assignment_group": "security_team", "resolution_action": "escalate", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-015", "title": "Invoice discrepancy for order #4821", "requester": "accounts@meridianfoods.com", "description": "The invoice total doesn\u0027t match our purchase order. There\u0027s a $2,400 overcharge on the line items.", "issue_type": "billing_license", "priority": "high", "assignment_group": "license_ops", "resolution_action": "fulfill", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-016", "title": "New hire onboarding checklist incomplete", "requester": "hr@talentbridge.co", "description": "Three new engineers start Monday and their accounts haven\u0027t been provisioned yet. Please expedite.", "issue_type": "onboarding", "priority": "high", "assignment_group": "onboarding_ops", "resolution_action": "fulfill", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-017", "title": "Dashboard latency is unacceptable", "requester": "ops-lead@fastfreight.com", "description": "Pages are taking 12+ seconds to load. This is impacting our dispatchers during peak hours. We need this fixed ASAP.", "issue_type": "application_support", "priority": "critical", "assignment_group": "application_team", "resolution_action": "escalate", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-018", "title": "Question about enterprise tier pricing", "requester": "finance@urbanstack.io", "description": "We\u0027re comparing your enterprise plan against two competitors. Can you send over a detailed pricing breakdown?", "issue_type": "service_request", "priority": "medium", "assignment_group": "procurement", "resolution_action": "assign", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-019", "title": "Make $5000/week with this one simple trick", "requester": "noreply@quickcash.example", "description": "No experience needed. Start earning today. Limited spots available. Act now before it\u0027s too late.", "issue_type": "spam_phishing", "priority": "low", "assignment_group": "security_team", "resolution_action": "ignore", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-020", "title": "General inquiry about your platform capabilities", "requester": "info@greenleaf.org", "description": "Hi, I stumbled across your website and was curious about what your platform does. Can you send some information?", "issue_type": "general_inquiry", "priority": "low", "assignment_group": "service_desk", "resolution_action": "acknowledge", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-021", "title": "Re: Production checkout throwing null reference exception", "requester": "sre@paperkite.dev", "description": "Following up on ticket-003. The hotfix was deployed but we\u0027re seeing a regression in staging. Same null reference on the payment confirmation page. This is still blocking.", "issue_type": "application_support", "priority": "critical", "assignment_group": "application_team", "resolution_action": "escalate", "ambiguity_note": null, "related_ticket_id": "ticket-003" }, { "ticket_id": "ticket-022", "title": "Usage charge dispute tied to API failures", "requester": "admin@crossfitbayarea.com", "description": "Our usage charges increased while the integration returned 500 errors for two weeks. We need both charge review and API investigation before approving the invoice.", "issue_type": "application_support", "priority": "high", "assignment_group": "application_team", "resolution_action": "escalate", "ambiguity_note": "Mentions billing, but the root cause is an application issue. The issue type could reasonably be billing_license or application_support.", "related_ticket_id": null }, { "ticket_id": "ticket-023", "title": "Cancel subscription and process final refund", "requester": "ops@smallbatch.co", "description": "We\u0027ve decided to go with another vendor. Please cancel our subscription effective immediately and refund the remaining balance on our annual plan.", "issue_type": "billing_license", "priority": "medium", "assignment_group": "license_ops", "resolution_action": "fulfill", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-024", "title": "SSO configuration failing silently", "requester": "it@megacorp.com", "description": "We configured SAML SSO per your docs but users get redirected to a blank page. No error messages. This is affecting 2000+ employees.", "issue_type": "application_support", "priority": "critical", "assignment_group": "application_team", "resolution_action": "escalate", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-025", "title": "Data residency requirements for EU deployment", "requester": "dpo@nordicbank.fi", "description": "We need confirmation that all data for EU customers is stored within EU borders. Please provide your data processing addendum.", "issue_type": "security_compliance", "priority": "high", "assignment_group": "security_team", "resolution_action": "fulfill", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-026", "title": "Positive feedback on recent API support case", "requester": "pm@littlefox.dev", "description": "Sharing positive feedback after last week\u0027s API support case. No action is needed beyond acknowledging the note and logging the feedback.", "issue_type": "general_inquiry", "priority": "low", "assignment_group": "service_desk", "resolution_action": "acknowledge", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-027", "title": "Vendor upgrade offer for Premium tier", "requester": "marketing@legitsaas.com", "description": "A current vendor sent a 30% Premium-tier offer that expires in 48 hours. The team is unsure whether this should just be acknowledged or routed for procurement review.", "issue_type": "general_inquiry", "priority": "low", "assignment_group": "service_desk", "resolution_action": "acknowledge", "ambiguity_note": "Could be treated as general_inquiry or escalated into a service_request if procurement wants to review the offer.", "related_ticket_id": null }, { "ticket_id": "ticket-028", "title": "Webhook delivery failures since Tuesday", "requester": "backend@paystream.io", "description": "Our webhook endpoint hasn\u0027t received any events since Tuesday. We\u0027ve verified our server is up. Is there an outage on your side?", "issue_type": "application_support", "priority": "high", "assignment_group": "application_team", "resolution_action": "fulfill", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-029", "title": "Seat expansion request with prorating question", "requester": "admin@growthworks.co", "description": "Our team needs 50 additional seats immediately. We also need to know how prorating will be handled before the change is approved.", "issue_type": "service_request", "priority": "medium", "assignment_group": "procurement", "resolution_action": "assign", "ambiguity_note": "Could be billing_license (prorating) or service_request (seat expansion).", "related_ticket_id": null }, { "ticket_id": "ticket-030", "title": "Account suspended without warning", "requester": "ceo@startupxyz.io", "description": "Our entire company account was suspended this morning with no prior notice. We have 80 employees locked out. This is unacceptable and needs immediate resolution.", "issue_type": "identity_access", "priority": "critical", "assignment_group": "service_desk", "resolution_action": "escalate", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-031", "title": "Payment method update required", "requester": "billing@yourplatform.com", "description": "The credit card on file for account #7829 expired last month. We attempted to charge three times without success. Please update your payment method to avoid service interruption.", "issue_type": "billing_license", "priority": "medium", "assignment_group": "license_ops", "resolution_action": "fulfill", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-032", "title": "Penetration test results — critical vulnerabilities found", "requester": "security@redteam-auditors.com", "description": "Our pentest revealed two critical and five high-severity vulnerabilities in your API endpoints. Full report attached. Remediation should begin immediately.", "issue_type": "security_compliance", "priority": "critical", "assignment_group": "security_team", "resolution_action": "escalate", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-033", "title": "Getting started guide seems outdated", "requester": "newuser@freshstart.io", "description": "I just signed up yesterday and the getting started guide references features that don\u0027t seem to exist in the current UI. Can you point me to updated docs?", "issue_type": "onboarding", "priority": "medium", "assignment_group": "onboarding_ops", "resolution_action": "fulfill", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-034", "title": "Mobile app crashes on launch after latest update", "requester": "qa@betatesters.org", "description": "Version 4.2.1 crashes immediately on iOS 18. Reproducible on iPhone 15 and 16. Stack trace included below.", "issue_type": "application_support", "priority": "high", "assignment_group": "application_team", "resolution_action": "fulfill", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-035", "title": "Wire transfer for annual enterprise contract", "requester": "treasury@bigbank.com", "description": "We\u0027ve initiated a wire transfer of $240,000 for the annual enterprise contract. Please confirm receipt and send the signed agreement.", "issue_type": "billing_license", "priority": "high", "assignment_group": "license_ops", "resolution_action": "fulfill", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-036", "title": "Can we get API access for a proof of concept?", "requester": "architect@cloudnine.tech", "description": "We are evaluating your platform for a large migration project. Is there a sandbox or trial API we can use for a 2-week proof of concept?", "issue_type": "service_request", "priority": "medium", "assignment_group": "procurement", "resolution_action": "assign", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-037", "title": "Earn a degree in just 2 weeks!", "requester": "admissions@diplomamill.example", "description": "No exams, no classes. Get your accredited degree today. Reply for more information.", "issue_type": "spam_phishing", "priority": "low", "assignment_group": "security_team", "resolution_action": "ignore", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-038", "title": "Re: Invoice discrepancy for order #4821", "requester": "accounts@meridianfoods.com", "description": "Following up on ticket-015. We still haven\u0027t received the corrected invoice. Our payment is now 15 days overdue because of this. Please prioritize.", "issue_type": "billing_license", "priority": "critical", "assignment_group": "license_ops", "resolution_action": "escalate", "ambiguity_note": null, "related_ticket_id": "ticket-015" }, { "ticket_id": "ticket-039", "title": "MFA enrollment mandatory for all users by EOD Friday", "requester": "security@internal.corp", "description": "Per our updated security policy, all user accounts must have MFA enabled by end of day Friday. Non-compliant accounts will be suspended.", "issue_type": "security_compliance", "priority": "high", "assignment_group": "security_team", "resolution_action": "fulfill", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-040", "title": "Reporting module needs better export options", "requester": "analyst@datacrunchers.co", "description": "CSV export exists, but the team also needs Excel and PDF with date filters. This blocks monthly reporting and could be interpreted as either a feature gap or an application-support issue.", "issue_type": "feature_request", "priority": "medium", "assignment_group": "application_team", "resolution_action": "acknowledge", "ambiguity_note": "Could be feature_request or application_support depending on urgency interpretation.", "related_ticket_id": null }, { "ticket_id": "ticket-041", "title": "Account access request for new contractor", "requester": "pm@buildit.agency", "description": "We have a new contractor starting next week who needs read-only access to our project dashboard. Please set up their account.", "issue_type": "onboarding", "priority": "medium", "assignment_group": "onboarding_ops", "resolution_action": "fulfill", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-042", "title": "Database migration script failing on large tables", "requester": "dba@megastore.com", "description": "The v3 to v4 migration script times out on tables with more than 10M rows. We have three such tables. Need guidance or a fix.", "issue_type": "application_support", "priority": "high", "assignment_group": "application_team", "resolution_action": "fulfill", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-043", "title": "Negotiate volume discount for 1000+ licenses", "requester": "procurement@globalcorp.com", "description": "We\u0027re looking to standardize on your platform across all subsidiaries. Approximately 1200 seats. What volume discount can you offer?", "issue_type": "service_request", "priority": "high", "assignment_group": "procurement", "resolution_action": "assign", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-044", "title": "Your account has been compromised — act now", "requester": "security-alert@phishing.example", "description": "We detected unusual activity on your account. Click the link below to verify your identity and secure your account immediately.", "issue_type": "spam_phishing", "priority": "low", "assignment_group": "security_team", "resolution_action": "ignore", "ambiguity_note": null, "related_ticket_id": null }, { "ticket_id": "ticket-045", "title": "Re: Account suspended without warning", "requester": "ceo@startupxyz.io", "description": "This is my third update about this in 24 hours. 80 people are still locked out. If this isn\u0027t resolved in the next 2 hours we\u0027re escalating to legal. Reference ticket-030.", "issue_type": "identity_access", "priority": "critical", "assignment_group": "service_desk", "resolution_action": "escalate", "ambiguity_note": null, "related_ticket_id": "ticket-030" }]
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276#!/usr/bin/env python3"""Inference script for the IT Helpdesk Ticket Routing OpenEnv environment.
Uses the competition-mandated environment variables: API_BASE_URL - LLM provider base URL MODEL_NAME - model identifier HF_TOKEN - authentication token
Can run against a local server (default http://localhost:8000) or aremote HuggingFace Space URL passed via ENV_URL.
Uses the WebSocket-based EnvClient for multi-step episodes."""from __future__ import annotations
import jsonimport os
import httpxfrom openai import OpenAI
from client import HelpdeskTicketEnvClientfrom models import HelpdeskTicketActionfrom vocabulary import ( ASSIGNMENT_GROUPS, ISSUE_TYPES, ISSUE_TYPE_TO_ASSIGNMENT_GROUP, ISSUE_TYPE_TO_RESOLUTION_ACTION, PRIORITIES, RESOLUTION_ACTIONS, TASK_IDS,)
# ---------------------------------------------------------------------------# Configuration# ---------------------------------------------------------------------------API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")MODEL_NAME = os.getenv("MODEL_NAME", "")HF_TOKEN = os.getenv("HF_TOKEN", "")ENV_URL = os.getenv("ENV_URL", "http://localhost:8000")
SEED = 42TASKS = list(TASK_IDS)
# ---------------------------------------------------------------------------# LLM helper# ---------------------------------------------------------------------------
llm_client: OpenAI | None = None
if MODEL_NAME and HF_TOKEN: llm_client = OpenAI(base_url=API_BASE_URL, api_key=HF_TOKEN)
SYSTEM_PROMPT = """\You are an expert IT helpdesk ticket routing agent. Given a helpdesk ticket, you must produce a JSON object with the requested fields.
Valid values:- issue_type: {issue_types}- priority: {priorities}- assignment_group: {assignment_groups}- resolution_action: {resolution_actions}
Return ONLY valid JSON with the requested fields. No markdown, no explanation.""".format( issue_types=", ".join(ISSUE_TYPES), priorities=", ".join(PRIORITIES), assignment_groups=", ".join(ASSIGNMENT_GROUPS), resolution_actions=", ".join(RESOLUTION_ACTIONS),)
def call_llm(ticket: dict, allowed_fields: list[str], instructions: str) -> dict: assert llm_client is not None, "LLM client not configured"
user_msg = ( f"Instructions: {instructions}\n\n" f"Allowed fields: {', '.join(allowed_fields)}\n\n" f"Title: {ticket['title']}\n" f"Requester: {ticket['requester']}\n" f"Description: {ticket['description']}\n\n" f"Respond with JSON containing ONLY these fields: {', '.join(allowed_fields)}" )
response = llm_client.chat.completions.create( model=MODEL_NAME, messages=[ {"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": user_msg}, ], temperature=0.0, max_tokens=256, )
text = response.choices[0].message.content or "{}" text = text.strip() if text.startswith("```"): text = text.split("\n", 1)[-1].rsplit("```", 1)[0].strip()
try: return json.loads(text) except json.JSONDecodeError: return {}
# ---------------------------------------------------------------------------# Heuristic fallback (no LLM needed)# ---------------------------------------------------------------------------
KEYWORD_ISSUE_TYPES = { "invoice": "billing_license", "charge": "billing_license", "refund": "billing_license", "payment": "billing_license", "billing": "billing_license", "license": "billing_license", "sign in": "identity_access", "login": "identity_access", "password": "identity_access", "locked": "identity_access", "2fa": "identity_access", "sso": "identity_access", "bug": "application_support", "error": "application_support", "exception": "application_support", "crash": "application_support", "production": "application_support", "latency": "application_support", "timeout": "application_support", "webhook": "application_support", "migration": "application_support", "pricing": "service_request", "quote": "service_request", "demo": "service_request", "enterprise": "service_request", "rollout": "service_request", "sandbox": "service_request", "trial": "service_request", "seat": "service_request", "seats": "service_request", "spam": "spam_phishing", "click now": "spam_phishing", "guaranteed": "spam_phishing", "unsubscribe": "spam_phishing", "phishing": "spam_phishing", "compromised": "spam_phishing", "compliance": "security_compliance", "regulation": "security_compliance", "gdpr": "security_compliance", "audit": "security_compliance", "pentest": "security_compliance", "vulnerabilities": "security_compliance", "security policy": "security_compliance", "onboarding": "onboarding", "welcome": "onboarding", "getting started": "onboarding", "new hire": "onboarding", "contractor": "onboarding", "feedback": "feature_request", "suggestion": "feature_request", "improve": "feature_request", "roadmap": "feature_request", "export": "feature_request",}
def heuristic_action(ticket: dict, allowed_fields: list[str]) -> dict: text = (ticket.get("title", "") + " " + ticket.get("description", "")).lower()
issue_type = "general_inquiry" for kw, mapped_issue_type in KEYWORD_ISSUE_TYPES.items(): if kw in text: issue_type = mapped_issue_type break
priority = "medium" if any(w in text for w in ["urgent", "critical", "blocking", "asap", "immediately"]): priority = "critical" elif any(w in text for w in ["important", "high priority", "revenue"]): priority = "high" elif any(w in text for w in ["low", "whenever", "no rush"]): priority = "low"
result: dict = {} if "issue_type" in allowed_fields: result["issue_type"] = issue_type if "priority" in allowed_fields: result["priority"] = priority if "assignment_group" in allowed_fields: result["assignment_group"] = ISSUE_TYPE_TO_ASSIGNMENT_GROUP.get( issue_type, "service_desk" ) if "resolution_action" in allowed_fields: result["resolution_action"] = ISSUE_TYPE_TO_RESOLUTION_ACTION.get( issue_type, "acknowledge" ) return result
# ---------------------------------------------------------------------------# Main loop using WebSocket client for multi-step episodes# ---------------------------------------------------------------------------
def run(): # Quick HTTP health check http = httpx.Client(base_url=ENV_URL, timeout=30.0) health = http.get("/health") health.raise_for_status() print(f"Connected to {ENV_URL}: {health.json()}")
tasks_resp = http.get("/tasks") tasks_resp.raise_for_status() available_tasks = {t["id"]: t for t in tasks_resp.json()["tasks"]} print(f"Available tasks: {[t['name'] for t in available_tasks.values()]}") http.close()
all_scores: dict[int, list[float]] = {}
for task_id in TASKS: if task_id not in available_tasks: print(f"Task {task_id} not available, skipping") continue
task = available_tasks[task_id] print(f"\n--- Task {task_id}: {task['name']} ({task['difficulty']}) ---")
# Use sync WebSocket client for multi-step episode sync_client = HelpdeskTicketEnvClient(base_url=ENV_URL).sync() with sync_client: result = sync_client.reset(seed=SEED, task_id=task_id) obs = result.observation
task_scores: list[float] = [] step_num = 0
while not result.done: ticket = obs.current_ticket if ticket is None: break
allowed = obs.allowed_fields instructions = obs.instructions
if llm_client is not None: action_dict = call_llm(ticket, allowed, instructions) else: action_dict = heuristic_action(ticket, allowed)
action = HelpdeskTicketAction(**action_dict) result = sync_client.step(action) obs = result.observation
step_num += 1 print(f" Step {step_num}: reward={result.reward} done={result.done}")
if result.reward is not None: task_scores.append(result.reward)
all_scores[task_id] = task_scores final = task_scores[-1] if task_scores else 0.0 print(f" Task {task_id} final reward: {final:.4f}")
# Summary print("\n=== RESULTS ===") overall = [] for tid in TASKS: if tid in all_scores: scores = all_scores[tid] avg = sum(scores) / len(scores) if scores else 0.0 overall.append(avg) print(f"Task {tid}: avg_score={avg:.4f} ({len(scores)} steps)") if overall: print(f"Overall: {sum(overall) / len(overall):.4f}")
if __name__ == "__main__": run()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114from __future__ import annotations
from typing import Any, Optional
from pydantic import BaseModel, Field, field_validatorfrom openenv.core.env_server.types import Action, Observation, Statefrom vocabulary import ( ASSIGNMENT_GROUPS, ISSUE_TYPES, PRIORITIES, RESOLUTION_ACTIONS,)
ISSUE_TYPE_SET = set(ISSUE_TYPES)PRIORITY_SET = set(PRIORITIES)ASSIGNMENT_GROUP_SET = set(ASSIGNMENT_GROUPS)RESOLUTION_ACTION_SET = set(RESOLUTION_ACTIONS)
def _validate_choice(value: str, allowed: set[str], field_name: str) -> str: if value not in allowed: allowed_values = ", ".join(sorted(allowed)) raise ValueError(f"{field_name} must be one of: {allowed_values}") return value
def _validate_optional_choice( value: Optional[str], allowed: set[str], field_name: str) -> Optional[str]: if value is None: return None return _validate_choice(value, allowed, field_name)
class HelpdeskTicketRecord(BaseModel): ticket_id: str title: str requester: str description: str issue_type: str priority: str assignment_group: str resolution_action: str ambiguity_note: Optional[str] = None related_ticket_id: Optional[str] = None
@field_validator("issue_type") @classmethod def validate_issue_type(cls, value: str) -> str: return _validate_choice(value, ISSUE_TYPE_SET, "issue_type")
@field_validator("priority") @classmethod def validate_priority(cls, value: str) -> str: return _validate_choice(value, PRIORITY_SET, "priority")
@field_validator("assignment_group") @classmethod def validate_assignment_group(cls, value: str) -> str: return _validate_choice(value, ASSIGNMENT_GROUP_SET, "assignment_group")
@field_validator("resolution_action") @classmethod def validate_resolution_action(cls, value: str) -> str: return _validate_choice(value, RESOLUTION_ACTION_SET, "resolution_action")
class HelpdeskTicketAction(Action): issue_type: Optional[str] = None priority: Optional[str] = None assignment_group: Optional[str] = None resolution_action: Optional[str] = None
@field_validator("issue_type") @classmethod def validate_issue_type(cls, value: Optional[str]) -> Optional[str]: return _validate_optional_choice(value, ISSUE_TYPE_SET, "issue_type")
@field_validator("priority") @classmethod def validate_priority(cls, value: Optional[str]) -> Optional[str]: return _validate_optional_choice(value, PRIORITY_SET, "priority")
@field_validator("assignment_group") @classmethod def validate_assignment_group(cls, value: Optional[str]) -> Optional[str]: return _validate_optional_choice(value, ASSIGNMENT_GROUP_SET, "assignment_group")
@field_validator("resolution_action") @classmethod def validate_resolution_action(cls, value: Optional[str]) -> Optional[str]: return _validate_optional_choice(value, RESOLUTION_ACTION_SET, "resolution_action")
class HelpdeskTicketObservation(Observation): task_id: int = 0 task_name: str = "" instructions: str = "" allowed_fields: list[str] = Field(default_factory=list) current_ticket: Optional[dict[str, str]] = None queue_size: int = 0 tickets_remaining: int = 0 tickets_processed: int = 0 history: list[dict[str, Any]] = Field(default_factory=list)
class HelpdeskTicketState(State): current_task_id: Optional[int] = None seed: Optional[int] = None queue_ticket_ids: list[str] = Field(default_factory=list) current_ticket_index: int = 0 per_ticket_scores: list[float] = Field(default_factory=list) total_reward: float = 0.01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859name: it_helpdesk_ticket_routing_openenvversion: "0.1.0"description: > Deterministic IT helpdesk ticket routing environment for issue classification, prioritization, assignment, and resolution decisions. Built on the OpenEnv framework.author: Hackstreet Boys - Roopal Guha Neogi, Suyash Kumar
environment: type: openenv entry_point: server.environment:HelpdeskTicketRoutingEnvironment action_model: models:HelpdeskTicketAction observation_model: models:HelpdeskTicketObservation state_model: models:HelpdeskTicketState
tasks: - name: Issue Type Classification difficulty: easy objective: Predict the correct IT issue type for a helpdesk ticket. - name: Issue Type And Priority difficulty: medium objective: Predict the correct issue type and priority. - name: Full Ticket Routing difficulty: hard objective: Predict issue type, priority, assignment group, and resolution action.
api: endpoints: - /health - /reset - /step - /state - /tasks - /docs
evaluation: reward_range: min: 0.0 max: 1.0 deterministic: true
grading: normalizedreproducible: true
inference: script: inference.py env_vars: - API_BASE_URL - MODEL_NAME - HF_TOKEN
requirements: python: ">=3.11" dependencies: - openenv-core - fastapi>=0.115 - pydantic>=2.7 - uvicorn>=0.30 - httpx>=0.25 - openai>=1.681234567891011121314151617181920212223242526[build-system]requires = ["setuptools>=68.0", "wheel"]build-backend = "setuptools.build_meta"
[project]name = "it-helpdesk-ticket-routing-openenv"version = "0.1.0"description = "IT helpdesk ticket routing environment for the OpenEnv framework"requires-python = ">=3.11"dependencies = [ "openenv-core @ git+https://github.com/meta-pytorch/OpenEnv.git", "fastapi>=0.115", "pydantic>=2.7", "uvicorn>=0.30", "openai>=1.0", "httpx>=0.25",]
[project.optional-dependencies]dev = ["pytest", "httpx"]
[tool.setuptools]py-modules = ["models", "client", "vocabulary"]
[tool.setuptools.packages.find]include = ["server*"]123456openenv-core @ git+https://github.com/meta-pytorch/OpenEnv.gitfastapi>=0.115pydantic>=2.7uvicorn>=0.30openai>=1.0httpx>=0.25123456789101112FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 7860
CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"]12345678910111213141516171819202122232425262728293031323334353637383940414243import sysfrom pathlib import Path
# Ensure repo root is on sys.path so `models` and `server` are importable_repo_root = str(Path(__file__).resolve().parent.parent)if _repo_root not in sys.path: sys.path.insert(0, _repo_root)
from openenv.core.env_server import create_app
from models import HelpdeskTicketAction, HelpdeskTicketObservationfrom server.environment import HelpdeskTicketRoutingEnvironmentfrom server.tasks import TASKSfrom vocabulary import APP_ENV_NAME
app = create_app( HelpdeskTicketRoutingEnvironment, HelpdeskTicketAction, HelpdeskTicketObservation, env_name=APP_ENV_NAME,)
@app.get("/tasks")def list_tasks(): return { "tasks": [ { "id": t["id"], "name": t["name"], "difficulty": t["difficulty"], "instructions": t["instructions"], "allowed_fields": t["allowed_fields"], } for t in TASKS.values() ] }
if __name__ == "__main__": import uvicorn
uvicorn.run("server.app:app", host="0.0.0.0", port=8000, reload=True)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163from __future__ import annotations
import randomimport uuidfrom typing import Any, Optional
from openenv.core.env_server.interfaces import Environment
from models import ( HelpdeskTicketAction, HelpdeskTicketObservation, HelpdeskTicketRecord, HelpdeskTicketState,)from server.grader import grade_actionfrom server.reward import compute_step_reward, compute_trajectory_rewardfrom server.tasks import get_task_definition, load_dataset
QUEUE_SIZE_RANGE = (3, 5)
class HelpdeskTicketRoutingEnvironment( Environment[HelpdeskTicketAction, HelpdeskTicketObservation, HelpdeskTicketState]): def __init__(self) -> None: super().__init__() self._dataset = load_dataset() self._rng = random.Random() self._queue: list[HelpdeskTicketRecord] = [] self._state = HelpdeskTicketState()
# ------------------------------------------------------------------ # OpenEnv required interface # ------------------------------------------------------------------
def reset( self, seed: Optional[int] = None, episode_id: Optional[str] = None, **kwargs: Any, ) -> HelpdeskTicketObservation: task_id: int = kwargs.get("task_id", 1) task = get_task_definition(task_id)
if seed is not None: self._rng.seed(seed)
queue_size = self._rng.randint(*QUEUE_SIZE_RANGE) self._queue = self._rng.sample(self._dataset, min(queue_size, len(self._dataset)))
self._state = HelpdeskTicketState( episode_id=episode_id or str(uuid.uuid4()), step_count=0, current_task_id=task_id, seed=seed, queue_ticket_ids=[t.ticket_id for t in self._queue], current_ticket_index=0, per_ticket_scores=[], total_reward=0.0, )
return self._build_observation(task)
def step( self, action: HelpdeskTicketAction, timeout_s: Optional[float] = None, **kwargs: Any, ) -> HelpdeskTicketObservation: if not self._queue or self._state.current_task_id is None: raise RuntimeError("Environment has not been reset.")
idx = self._state.current_ticket_index if idx >= len(self._queue): raise RuntimeError("Episode already done — call reset().")
current_ticket = self._queue[idx] task_id = self._state.current_task_id task = get_task_definition(task_id)
score, breakdown = grade_action(action, current_ticket, task_id) step_reward = compute_step_reward(score)
self._state.per_ticket_scores.append(score) self._state.step_count += 1 self._state.current_ticket_index += 1
is_done = self._state.current_ticket_index >= len(self._queue)
if is_done: traj_reward = compute_trajectory_reward( self._state.per_ticket_scores, len(self._queue), self._state.step_count, ) self._state.total_reward = traj_reward final_reward = traj_reward else: final_reward = step_reward
history_entry = { "ticket_id": current_ticket.ticket_id, "score": score, "breakdown": breakdown, }
return self._build_observation( task, done=is_done, reward=final_reward, extra_history=history_entry, )
@property def state(self) -> HelpdeskTicketState: return self._state.model_copy(deep=True)
# ------------------------------------------------------------------ # Helpers # ------------------------------------------------------------------
def _build_observation( self, task: dict, done: bool = False, reward: float | None = None, extra_history: dict | None = None, ) -> HelpdeskTicketObservation: idx = self._state.current_ticket_index queue_size = len(self._queue)
if idx < queue_size: ticket = self._queue[idx] ticket_view = { "ticket_id": ticket.ticket_id, "title": ticket.title, "requester": ticket.requester, "description": ticket.description, } else: ticket_view = None
history: list[dict] = [] for i, s in enumerate(self._state.per_ticket_scores): history.append({"step": i + 1, "score": s}) if extra_history and history: history[-1] = {"step": len(history), **extra_history}
return HelpdeskTicketObservation( done=done, reward=reward, metadata={}, task_id=task["id"], task_name=task["name"], instructions=task["instructions"], allowed_fields=list(task["allowed_fields"]), current_ticket=ticket_view, queue_size=queue_size, tickets_remaining=max(0, queue_size - idx), tickets_processed=idx, history=history, )123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103from __future__ import annotations
from models import HelpdeskTicketAction, HelpdeskTicketRecord
ISSUE_TYPE_SIMILARITY = { ("billing_license", "service_request"): 0.4, ("service_request", "billing_license"): 0.4, ("application_support", "identity_access"): 0.5, ("identity_access", "application_support"): 0.5, ("application_support", "feature_request"): 0.35, ("feature_request", "application_support"): 0.35, ("onboarding", "identity_access"): 0.4, ("identity_access", "onboarding"): 0.4, ("general_inquiry", "feature_request"): 0.3, ("feature_request", "general_inquiry"): 0.3, ("general_inquiry", "service_request"): 0.25, ("service_request", "general_inquiry"): 0.25, ("spam_phishing", "security_compliance"): 0.4, ("security_compliance", "spam_phishing"): 0.4, ("security_compliance", "billing_license"): 0.2, ("billing_license", "security_compliance"): 0.2,}
PRIORITY_SCORES = { ("critical", "high"): 0.6, ("high", "critical"): 0.6, ("high", "medium"): 0.5, ("medium", "high"): 0.5, ("medium", "low"): 0.4, ("low", "medium"): 0.4, ("critical", "medium"): 0.3, ("medium", "critical"): 0.3, ("critical", "low"): 0.1, ("low", "critical"): 0.1, ("high", "low"): 0.2, ("low", "high"): 0.2,}
TASK_WEIGHTS = { 1: {"issue_type": 1.0}, 2: {"issue_type": 0.6, "priority": 0.4}, 3: { "issue_type": 0.35, "priority": 0.20, "assignment_group": 0.25, "resolution_action": 0.20, },}
def _normalized(value: str | None) -> str: return (value or "").strip().lower()
def _score_exact_or_similar(predicted: str | None, expected: str) -> float: pred = _normalized(predicted) exp = _normalized(expected) if not pred: return 0.0 if pred == exp: return 1.0 return ISSUE_TYPE_SIMILARITY.get((pred, exp), 0.0)
def _score_priority(predicted: str | None, expected: str) -> float: pred = _normalized(predicted) exp = _normalized(expected) if not pred: return 0.0 if pred == exp: return 1.0 return PRIORITY_SCORES.get((pred, exp), 0.0)
def _score_exact(predicted: str | None, expected: str) -> float: return 1.0 if _normalized(predicted) == _normalized(expected) and predicted else 0.0
def grade_action( action: HelpdeskTicketAction, ticket: HelpdeskTicketRecord, task_id: int,) -> tuple[float, dict[str, float]]: if task_id not in TASK_WEIGHTS: raise ValueError(f"Unsupported task_id: {task_id}")
field_scores = { "issue_type": _score_exact_or_similar(action.issue_type, ticket.issue_type), "priority": _score_priority(action.priority, ticket.priority), "assignment_group": _score_exact( action.assignment_group, ticket.assignment_group ), "resolution_action": _score_exact( action.resolution_action, ticket.resolution_action ), }
weights = TASK_WEIGHTS[task_id] score = sum(field_scores[field] * weight for field, weight in weights.items()) breakdown = {field: field_scores[field] for field in weights} return score, breakdown12345678910111213141516from __future__ import annotations
def compute_step_reward(score: float) -> float: return max(0.0, min(1.0, score))
def compute_trajectory_reward( per_ticket_scores: list[float], queue_size: int, steps_taken: int) -> float: if not per_ticket_scores: return 0.0 avg = sum(per_ticket_scores) / len(per_ticket_scores) overshoot = max(0, steps_taken - queue_size) penalty = overshoot * 0.03 return max(0.0, min(1.0, avg - penalty))123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960from __future__ import annotations
import jsonfrom pathlib import Path
from models import HelpdeskTicketRecordfrom vocabulary import TASK_IDS
TASKS = { 1: { "id": 1, "name": "Issue Type Classification", "difficulty": "easy", "instructions": ( "Read the ticket and select the single best IT issue type." ), "allowed_fields": ["issue_type"], }, 2: { "id": 2, "name": "Issue Type And Priority", "difficulty": "medium", "instructions": ( "Read the ticket, select the best IT issue type, and estimate the " "correct operational priority." ), "allowed_fields": ["issue_type", "priority"], }, 3: { "id": 3, "name": "Full Ticket Routing", "difficulty": "hard", "instructions": ( "Perform full helpdesk triage by selecting the best issue type, " "priority, assignment group, and resolution action for the ticket." ), "allowed_fields": [ "issue_type", "priority", "assignment_group", "resolution_action", ], },}
assert tuple(TASKS.keys()) == TASK_IDS
def load_dataset() -> list[HelpdeskTicketRecord]: dataset_path = Path(__file__).resolve().parent.parent / "data" / "dataset.json" with dataset_path.open("r", encoding="utf-8") as f: raw = json.load(f) return [HelpdeskTicketRecord.model_validate(r) for r in raw]
def get_task_definition(task_id: int) -> dict: if task_id not in TASKS: raise ValueError(f"Unsupported task_id: {task_id}") return TASKS[task_id]12345678910111213141516The following study material links were provided from the competeition-
Module 1: Why OpenEnv?https://github.com/meta-pytorch/OpenEnv/blob/main/tutorial/01-environments.md
Module 2: Using Existing Environmentshttps://github.com/meta-pytorch/OpenEnv/blob/main/tutorial/02-deployment.md
Module 3: Deploying Environmentshttps://github.com/meta-pytorch/OpenEnv/blob/main/tutorial/03-scaling.md
Module 4: Building Your Own Environment
MOST IMPORTANT FOR ROUND 1https://github.com/meta-pytorch/OpenEnv/blob/main/tutorial/04-training.md
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667from __future__ import annotations
TEAM_NAME = "Hackstreet Boys"TEAM_MEMBERS = ("Roopal Guha Neogi", "Suyash Kumar")
PROJECT_TITLE = "IT Helpdesk Ticket Routing OpenEnv"DOMAIN_NAME = "IT Helpdesk Ticket Routing"
OPENENV_NAME = "it_helpdesk_ticket_routing_openenv"APP_ENV_NAME = "it_helpdesk_ticket_routing"
ISSUE_TYPES = ( "billing_license", "identity_access", "application_support", "service_request", "spam_phishing", "general_inquiry", "security_compliance", "onboarding", "feature_request",)
PRIORITIES = ("critical", "high", "medium", "low")
ASSIGNMENT_GROUPS = ( "license_ops", "service_desk", "application_team", "procurement", "security_team", "onboarding_ops",)
RESOLUTION_ACTIONS = ( "fulfill", "escalate", "assign", "ignore", "acknowledge",)
TASK_IDS = (1, 2, 3)
ISSUE_TYPE_TO_ASSIGNMENT_GROUP = { "billing_license": "license_ops", "identity_access": "service_desk", "application_support": "application_team", "service_request": "procurement", "spam_phishing": "security_team", "general_inquiry": "service_desk", "security_compliance": "security_team", "onboarding": "onboarding_ops", "feature_request": "application_team",}
ISSUE_TYPE_TO_RESOLUTION_ACTION = { "billing_license": "fulfill", "identity_access": "fulfill", "application_support": "escalate", "service_request": "assign", "spam_phishing": "ignore", "general_inquiry": "acknowledge", "security_compliance": "escalate", "onboarding": "fulfill", "feature_request": "acknowledge",}KNOWLEDGE.mdAdded+258
LABEL_AUDIT.mdAdded+56
MARCH30_STATUS.mdAdded+117
MENTAL_MODEL.mdAdded+155
PLAN.mdAdded+147
PreparationAdded
ProblemDetailsAdded+472
README.mdAdded+258
ROADMAP.mdAdded+339
__init__.cpython-313.pycAdded
__init__.pyAdded
app.cpython-313.pycAdded
client.cpython-313.pycAdded
client.pyAdded+28
data/dataset.jsonAdded+543
environment.cpython-313.pycAdded
grader.cpython-313.pycAdded
inference.pyAdded+276
models.cpython-313.pycAdded
models.pyAdded+114
openenv.yamlAdded+59
pyproject.tomlAdded+26
requirements.txtAdded+6
reward.cpython-313.pycAdded
server/DockerfileAdded+12
server/app.pyAdded+43
server/environment.pyAdded+163
server/grader.pyAdded+103
server/reward.pyAdded+16
server/tasks.pyAdded+60
studymaterialLinksAdded+16
tasks.cpython-313.pycAdded
vocabulary.pyAdded+67