Spaces:
Sleeping
Sleeping
File size: 25,266 Bytes
adb0674 6c7a6ef adb0674 6c7a6ef adb0674 6c7a6ef adb0674 6c7a6ef adb0674 6c7a6ef adb0674 6c7a6ef adb0674 6c7a6ef adb0674 6c7a6ef adb0674 6c7a6ef adb0674 6c7a6ef adb0674 6c7a6ef adb0674 6c7a6ef adb0674 6c7a6ef adb0674 6c7a6ef adb0674 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | from __future__ import annotations
from pydantic import BaseModel, ConfigDict, Field
from .models import PriorityLevel, TicketCategory
class TaskSpec(BaseModel):
model_config = ConfigDict(extra="forbid")
task_id: str
difficulty: str
title: str
description: str
subject: str
customer_message: str
extracted_entities: dict[str, str] = Field(default_factory=dict)
customer_metadata: dict[str, str] = Field(default_factory=dict)
attachment_refs: list[str] = Field(default_factory=list)
sla_deadline_minutes: int | None = None
ground_truth_category: TicketCategory
gold_queue: str
gold_priority: PriorityLevel
gold_resolution_path: list[str] = Field(default_factory=list)
required_diagnostic_fields: list[str] = Field(default_factory=list)
required_response_keywords: list[str] = Field(default_factory=list)
discouraged_keywords: list[str] = Field(default_factory=list)
must_escalate: bool = False
allow_close: bool = False
max_steps: int = 8
# ---------------------------------------------------------------------------
# Task variant templates β used by the stochastic variant system to randomize
# surface-level details while preserving the underlying task structure.
# ---------------------------------------------------------------------------
_CUSTOMER_TONES: dict[str, list[str]] = {
"frustrated": [
"I've been waiting for days and nobody has responded.",
"This is unacceptable β we're paying enterprise rates for this.",
"I need this resolved NOW.",
],
"calm": [
"I wanted to report an issue we noticed.",
"Hi team, just flagging something for your attention.",
"Could you please look into the following when you get a chance?",
],
"panicked": [
"URGENT β this is a critical issue impacting production!",
"We are losing revenue every minute this is down!",
"Please help, this is an emergency for our entire organization.",
],
}
_INVOICE_IDS = ["INV-88421", "INV-91034", "INV-77209", "INV-63582", "INV-50117"]
_PLAN_NAMES = ["Team", "Business", "Enterprise", "Starter", "Scale"]
_SERVICE_NAMES = ["checkout-api", "payment-gateway", "inventory-svc", "auth-service", "order-processor"]
_IP_ADDRESSES = ["185.42.103.7", "91.215.44.22", "203.0.113.55", "198.51.100.12", "45.33.17.89"]
_COUNTRIES = ["Russia", "China", "Brazil", "Nigeria", "Romania"]
_ERROR_CODES = ["503", "502", "500", "504", "520"]
def _vary_string(template: str, seed: int, replacements: dict[str, list[str]]) -> str:
"""Apply deterministic randomized replacements to a template string."""
result = template
for placeholder, options in replacements.items():
if placeholder in result:
idx = seed % len(options)
result = result.replace(placeholder, options[idx])
seed = (seed * 31 + 7) & 0xFFFFFFFF
return result
def generate_variant(task: TaskSpec, seed: int) -> TaskSpec:
"""
Create a surface-level variant of a task with randomized details.
The underlying task structure (gold answers, required fields) stays the same,
but customer messages, entity values, and tone vary per seed.
"""
import copy
variant = task.model_copy(deep=True)
# Vary tone prefix
tone_keys = list(_CUSTOMER_TONES.keys())
tone = tone_keys[seed % len(tone_keys)]
prefix = _CUSTOMER_TONES[tone][seed % len(_CUSTOMER_TONES[tone])]
# Apply entity-level variations based on category
s = seed
if task.ground_truth_category == TicketCategory.BILLING:
inv_id = _INVOICE_IDS[s % len(_INVOICE_IDS)]
plan = _PLAN_NAMES[(s >> 3) % len(_PLAN_NAMES)]
variant.extracted_entities = {
**variant.extracted_entities,
"invoice_id": inv_id,
"subscription_plan": plan,
}
variant.customer_message = (
f"{prefix} I was charged twice today for invoice {inv_id} on our {plan} plan. "
f"Can you fix this and refund one of the charges?"
)
variant.subject = f"Charged twice for same invoice {inv_id}"
elif task.ground_truth_category == TicketCategory.SECURITY:
country = _COUNTRIES[s % len(_COUNTRIES)]
ip = _IP_ADDRESSES[(s >> 2) % len(_IP_ADDRESSES)]
variant.extracted_entities = {
**variant.extracted_entities,
"reported_location": country,
"source_ip": ip,
}
variant.customer_message = (
f"{prefix} I just got a login alert from {country} (IP: {ip}) where none of our "
f"admins are located. I think someone accessed our account. Please help immediately."
)
variant.subject = f"Unrecognized login from {country}"
elif task.ground_truth_category == TicketCategory.INCIDENT:
svc = _SERVICE_NAMES[s % len(_SERVICE_NAMES)]
err = _ERROR_CODES[(s >> 2) % len(_ERROR_CODES)]
variant.extracted_entities = {
**variant.extracted_entities,
"affected_service": svc,
"error_code": err,
}
variant.customer_message = (
f"{prefix} Our production {svc} started returning {err} right after deployment. "
f"Deployments are blocked and customers cannot complete purchases. "
f"This is impacting revenue right now."
)
variant.subject = f"Production {svc} returning {err} after deployment"
else:
variant.customer_message = f"{prefix} {variant.customer_message}"
return variant
# ---------------------------------------------------------------------------
# Static task definitions
# ---------------------------------------------------------------------------
TASKS: dict[str, TaskSpec] = {
# ββ EASY ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
"easy_billing_duplicate_charge": TaskSpec(
task_id="easy_billing_duplicate_charge",
difficulty="easy",
title="Billing Inquiry - Duplicate Charge",
description=(
"Customer was charged twice for one subscription cycle and requests correction. "
"Agent should classify as billing, route to billing operations, acknowledge duplicate charge/refund path, "
"and close only after a proper acknowledgement."
),
subject="Charged twice for same invoice INV-88421",
customer_message=(
"Hi support, I was charged twice today for invoice INV-88421 for our Team plan. "
"Can you fix this and refund one of the charges?"
),
extracted_entities={
"invoice_id": "INV-88421",
"subscription_plan": "Team",
"reported_issue": "duplicate_charge",
},
customer_metadata={
"account_tier": "business",
"org_size": "50-200",
"timezone": "America/New_York",
"account_age_months": "18",
},
ground_truth_category=TicketCategory.BILLING,
gold_queue="billing-ops",
gold_priority=PriorityLevel.NORMAL,
gold_resolution_path=["classify", "assign_queue", "reply", "close"],
required_diagnostic_fields=[],
required_response_keywords=["duplicate charge", "refund", "next steps"],
discouraged_keywords=["security breach", "ignore"],
must_escalate=False,
allow_close=True,
max_steps=6,
),
"easy_password_reset_request": TaskSpec(
task_id="easy_password_reset_request",
difficulty="easy",
title="Account Access - Password Reset",
description=(
"User requests a password reset for their enterprise account. Agent should classify as account issue, "
"route to identity-ops queue, confirm identity verification steps, and guide through self-service reset."
),
subject="Cannot log in - need password reset for admin account",
customer_message=(
"Hi, I'm locked out of my admin account (email: j.martinez@acmecorp.com). "
"I've tried the 'forgot password' link but never received the reset email. "
"Can you help me regain access? This is blocking my team's work."
),
extracted_entities={
"user_email": "j.martinez@acmecorp.com",
"account_role": "admin",
"reported_issue": "password_reset",
},
customer_metadata={
"account_tier": "enterprise",
"org_size": "200-1000",
"timezone": "America/Chicago",
"account_age_months": "36",
},
ground_truth_category=TicketCategory.GENERAL,
gold_queue="identity-ops",
gold_priority=PriorityLevel.NORMAL,
gold_resolution_path=["classify", "assign_queue", "request_info", "reply", "close"],
required_diagnostic_fields=["account_email", "verification_method"],
required_response_keywords=["reset", "verify", "identity"],
discouraged_keywords=["share password", "ignore"],
must_escalate=False,
allow_close=True,
max_steps=6,
),
"easy_feature_request": TaskSpec(
task_id="easy_feature_request",
difficulty="easy",
title="Product Feedback - Feature Request",
description=(
"Customer submits a feature request for bulk user import. Agent should classify as feature request, "
"route to product-feedback queue, acknowledge the request with a timeline expectation, and close."
),
subject="Feature request: Bulk user import via CSV",
customer_message=(
"We have 500+ users to onboard and adding them one-by-one is extremely tedious. "
"Could you add a CSV bulk import feature for user management? "
"Other platforms we've evaluated have this. It's becoming a dealbreaker for us."
),
extracted_entities={
"requested_feature": "bulk_csv_import",
"module": "user_management",
"reported_issue": "feature_request",
},
customer_metadata={
"account_tier": "enterprise",
"org_size": "500+",
"timezone": "Europe/London",
"account_age_months": "6",
},
ground_truth_category=TicketCategory.GENERAL,
gold_queue="product-feedback",
gold_priority=PriorityLevel.LOW,
gold_resolution_path=["classify", "assign_queue", "reply", "close"],
required_diagnostic_fields=[],
required_response_keywords=["feature request", "roadmap", "acknowledged"],
discouraged_keywords=["bug", "outage", "security"],
must_escalate=False,
allow_close=True,
max_steps=5,
),
# ββ MEDIUM ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
"medium_security_suspicious_login": TaskSpec(
task_id="medium_security_suspicious_login",
difficulty="medium",
title="Account Security - Suspicious Login",
description=(
"User reports suspicious login activity. Agent should classify as security, assign to security queue, "
"set high priority, request verification details, and advise credential reset without closing prematurely."
),
subject="Unrecognized login from another country",
customer_message=(
"I just got a login alert from a country where none of our admins are located. "
"I think someone accessed our account. Please help immediately."
),
extracted_entities={
"alert_type": "suspicious_login",
"account_tier": "enterprise",
"reported_location": "unknown",
"source_ip": "185.42.103.7",
"login_timestamp": "2025-04-10T03:22:41Z",
},
customer_metadata={
"account_tier": "enterprise",
"org_size": "200-1000",
"timezone": "America/Los_Angeles",
"account_age_months": "24",
"sla_tier": "premium",
},
attachment_refs=["auth_audit_log_2025-04-10.json"],
sla_deadline_minutes=120,
ground_truth_category=TicketCategory.SECURITY,
gold_queue="security-response",
gold_priority=PriorityLevel.HIGH,
gold_resolution_path=["classify", "assign_queue", "update_priority", "request_info", "reply"],
required_diagnostic_fields=["last_known_login_time", "login_location", "mfa_status"],
required_response_keywords=["password reset", "verify", "security"],
discouraged_keywords=["close", "share password"],
must_escalate=False,
allow_close=False,
max_steps=8,
),
"medium_data_export_compliance": TaskSpec(
task_id="medium_data_export_compliance",
difficulty="medium",
title="Compliance - GDPR Data Export Request",
description=(
"Customer requests a full data export under GDPR Article 15. Agent must classify as compliance, "
"route to legal-compliance queue, set high priority, verify the requester's identity and authority, "
"and provide a timeline. Must NOT close β compliance team must fulfill."
),
subject="GDPR data export request - all user data for our organization",
customer_message=(
"Under GDPR Article 15, I'm requesting a complete export of all personal data your platform "
"holds for our organization (Org ID: ORG-4821). This includes user profiles, activity logs, "
"billing records, and any third-party data sharing records. "
"We need this within the 30-day regulatory window. Please confirm receipt and provide a timeline."
),
extracted_entities={
"request_type": "gdpr_data_export",
"regulation": "GDPR Article 15",
"org_id": "ORG-4821",
"reported_issue": "data_export_compliance",
},
customer_metadata={
"account_tier": "enterprise",
"org_size": "1000+",
"timezone": "Europe/Berlin",
"account_age_months": "42",
"jurisdiction": "EU",
},
sla_deadline_minutes=4320, # 3 days internal SLA
ground_truth_category=TicketCategory.GENERAL,
gold_queue="legal-compliance",
gold_priority=PriorityLevel.HIGH,
gold_resolution_path=["classify", "assign_queue", "update_priority", "request_info", "reply"],
required_diagnostic_fields=["requester_role", "data_scope", "legal_basis"],
required_response_keywords=["data export", "GDPR", "timeline", "verify"],
discouraged_keywords=["ignore", "deny", "not possible"],
must_escalate=False,
allow_close=False,
max_steps=8,
),
"medium_api_rate_limiting": TaskSpec(
task_id="medium_api_rate_limiting",
difficulty="medium",
title="Technical Support - API Rate Limiting",
description=(
"Customer reports unexpected API rate limiting causing intermittent 429 errors. "
"Agent should classify as technical/incident, route to platform-support, gather API usage "
"details and error patterns, and advise on rate limit configuration. Should NOT close."
),
subject="API returning 429 Too Many Requests intermittently",
customer_message=(
"Our integration started getting 429 errors from your API about 2 hours ago. "
"We haven't changed our request volume. Our API key is ak_prod_7x9m2. "
"The errors are intermittent β roughly 30% of requests fail. "
"This is breaking our automated order processing pipeline."
),
extracted_entities={
"error_code": "429",
"api_key_prefix": "ak_prod_7x9m2",
"error_rate": "30%",
"duration": "2 hours",
"reported_issue": "rate_limiting",
},
customer_metadata={
"account_tier": "business",
"org_size": "50-200",
"timezone": "Asia/Tokyo",
"account_age_months": "12",
},
attachment_refs=["api_error_log_sample.json"],
sla_deadline_minutes=240,
ground_truth_category=TicketCategory.INCIDENT,
gold_queue="platform-support",
gold_priority=PriorityLevel.HIGH,
gold_resolution_path=["classify", "assign_queue", "update_priority", "request_info", "reply"],
required_diagnostic_fields=["api_endpoint", "request_volume", "error_pattern"],
required_response_keywords=["rate limit", "429", "api"],
discouraged_keywords=["ignore", "wait a few days"],
must_escalate=False,
allow_close=False,
max_steps=8,
),
# ββ HARD ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
"hard_production_outage": TaskSpec(
task_id="hard_production_outage",
difficulty="hard",
title="Production Incident - Service Outage",
description=(
"A production outage blocks deployment and service availability. Agent must treat as a critical incident, "
"set urgent priority, request diagnostics, route to platform incident queue, and escalate properly."
),
subject="Production API returning 503 after deployment, checkout unavailable",
customer_message=(
"Our production checkout API started returning 503 right after deployment. "
"Deployments are blocked and customers cannot complete purchases. "
"This is impacting revenue right now."
),
extracted_entities={
"impact": "checkout_down",
"environment": "production",
"error_code": "503",
"business_impact": "revenue_blocked",
"deployment_id": "deploy-2025-04-10-1847",
"affected_region": "us-east-1",
},
customer_metadata={
"account_tier": "enterprise",
"org_size": "1000+",
"timezone": "America/New_York",
"account_age_months": "48",
"sla_tier": "premium",
},
attachment_refs=["deploy_log_2025-04-10.txt", "error_trace_503.json"],
sla_deadline_minutes=30,
ground_truth_category=TicketCategory.INCIDENT,
gold_queue="platform-incident",
gold_priority=PriorityLevel.URGENT,
gold_resolution_path=[
"classify",
"assign_queue",
"update_priority",
"request_info",
"escalate",
],
required_diagnostic_fields=[
"incident_start_time",
"affected_service",
"request_id",
"error_logs",
],
required_response_keywords=["incident", "request id", "logs", "escalate"],
discouraged_keywords=["close", "wait a few days"],
must_escalate=True,
allow_close=False,
max_steps=8,
),
"hard_data_breach_investigation": TaskSpec(
task_id="hard_data_breach_investigation",
difficulty="hard",
title="Security Incident - Potential Data Breach",
description=(
"Customer discovers unauthorized data access across multiple user accounts. "
"Agent must classify as critical security incident, set urgent priority, route to security-incident queue, "
"request forensic details, advise immediate containment, and escalate to CISO/incident response."
),
subject="Possible data breach - unauthorized access to customer PII",
customer_message=(
"We discovered that an unauthorized party accessed our customer database through what appears to be "
"a compromised API token. At least 3 user accounts show data exports we didn't authorize. "
"The exports include PII (names, emails, phone numbers). "
"We noticed this 45 minutes ago in our audit logs. We need immediate help containing this."
),
extracted_entities={
"incident_type": "data_breach",
"compromised_vector": "api_token",
"affected_accounts": "3+",
"data_types_exposed": "PII",
"time_since_discovery": "45 minutes",
"reported_issue": "data_breach",
},
customer_metadata={
"account_tier": "enterprise",
"org_size": "1000+",
"timezone": "America/New_York",
"account_age_months": "60",
"sla_tier": "premium",
"compliance_frameworks": "SOC2,HIPAA",
},
attachment_refs=["audit_log_export_suspicious.json", "compromised_token_details.txt"],
sla_deadline_minutes=15,
ground_truth_category=TicketCategory.SECURITY,
gold_queue="security-incident",
gold_priority=PriorityLevel.URGENT,
gold_resolution_path=[
"classify",
"assign_queue",
"update_priority",
"request_info",
"reply",
"escalate",
],
required_diagnostic_fields=[
"compromised_token_id",
"affected_user_list",
"export_timestamps",
"audit_log_range",
],
required_response_keywords=["breach", "contain", "revoke", "escalate"],
discouraged_keywords=["close", "ignore", "wait", "share password"],
must_escalate=True,
allow_close=False,
max_steps=10,
),
"hard_multi_service_cascade_failure": TaskSpec(
task_id="hard_multi_service_cascade_failure",
difficulty="hard",
title="Production Incident - Multi-Service Cascade Failure",
description=(
"A cascading failure across multiple microservices causes widespread outage. "
"Agent must classify as critical incident, set urgent priority, request detailed diagnostics "
"across multiple services, route to platform-incident, and escalate for incident bridge."
),
subject="Multiple services down - auth, payments, and notifications all failing",
customer_message=(
"Starting about 20 minutes ago, we're seeing failures across multiple services simultaneously. "
"Auth service returns 500, payment processing times out after 30s, and notification delivery "
"has completely stopped. We suspect a shared dependency (Redis cluster) may be the root cause. "
"Our entire platform is effectively down. Over 10,000 active users are affected. "
"We need your infrastructure team on this immediately."
),
extracted_entities={
"affected_services": "auth,payments,notifications",
"suspected_root_cause": "redis_cluster",
"error_types": "500,timeout,delivery_failure",
"users_affected": "10000+",
"duration": "20 minutes",
"environment": "production",
"reported_issue": "cascade_failure",
},
customer_metadata={
"account_tier": "enterprise",
"org_size": "1000+",
"timezone": "Europe/London",
"account_age_months": "36",
"sla_tier": "premium",
},
attachment_refs=[
"redis_cluster_health.json",
"service_dependency_graph.png",
"error_rate_dashboard.json",
],
sla_deadline_minutes=15,
ground_truth_category=TicketCategory.INCIDENT,
gold_queue="platform-incident",
gold_priority=PriorityLevel.URGENT,
gold_resolution_path=[
"classify",
"assign_queue",
"update_priority",
"request_info",
"escalate",
],
required_diagnostic_fields=[
"incident_start_time",
"affected_service",
"request_id",
"error_logs",
"dependency_health",
],
required_response_keywords=["incident", "cascade", "escalate", "infrastructure"],
discouraged_keywords=["close", "wait a few days", "not urgent"],
must_escalate=True,
allow_close=False,
max_steps=10,
),
}
TASK_ORDER: list[str] = [
"easy_billing_duplicate_charge",
"easy_password_reset_request",
"easy_feature_request",
"medium_security_suspicious_login",
"medium_data_export_compliance",
"medium_api_rate_limiting",
"hard_production_outage",
"hard_data_breach_investigation",
"hard_multi_service_cascade_failure",
]
def get_task(task_id: str) -> TaskSpec:
try:
return TASKS[task_id]
except KeyError as exc:
raise ValueError(f"unknown task_id: {task_id}") from exc
def list_tasks() -> list[TaskSpec]:
return [TASKS[task_id] for task_id in TASK_ORDER]
|