Tarun Claude Sonnet 4.6 commited on
Commit
adee2d5
Β·
1 Parent(s): 8b8db66

Polish UI to match SRE incident env design language

Browse files

- Hero section: large title + description + 6 stat cards in a grid row
(TICKETS 15, TIERS 3, PHASES 3, TEAMS 6, MAX STEPS 5, REWARD range)
matching the exact card style from the reference screenshot
- Overview tab: 6 unique-card grid with Lucide-style SVG icon boxes
(dark green #0a2a1a bg, white stroke icon), bold title, gray description
matching 4-column auto-fill grid layout
- Scenarios tab: professional HTML tables per tier with header row,
alternating rows, hover highlight, color-coded sentiment/priority/action
badges, truncated message cell with full-text title attr, kw-tags
- Playground tab: all outputs as structured HTML panels with dark headers;
observation rendered as key-value table (not raw JSON); phase steps as
a proper table (Step|Phase|Action|Team|Score); episode score as a 4-cell
metrics bar; team assignment as icon cards; agent response in a green
left-border box
- Try It tab: reward breakdown as a proper HTML table
- CSS: Inter + JetBrains Mono, full Gradio chrome strip, emerald accent

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (2) hide show
  1. app.py +848 -529
  2. server/app.py +848 -529
app.py CHANGED
@@ -212,16 +212,16 @@ async def _call_llm(obs, history: List[str], phase: int = 1) -> dict:
212
  return json.loads(match.group(1))
213
 
214
  # ---------------------------------------------------------------------------
215
- # UI helpers & HTML renderers
216
  # ---------------------------------------------------------------------------
217
 
218
- TASK_MAP = {
219
- "Easy (Classification)": "easy",
220
- "Medium (Assignment)": "medium",
221
- "Hard (Full Resolution)": "hard",
222
- }
223
-
224
- TEAM_DESCRIPTIONS = {
225
  "logistics_team": "Logistics Team",
226
  "tech_support_team": "Tech Support Team",
227
  "safety_team": "Safety Team",
@@ -229,256 +229,57 @@ TEAM_DESCRIPTIONS = {
229
  "orders_team": "Orders Team",
230
  "management_team": "Management Team",
231
  }
232
-
233
- TEAM_SUBTITLES = {
234
  "logistics_team": "Shipping, delivery, lost packages",
235
  "tech_support_team": "Login, bugs, API errors, data loss",
236
  "safety_team": "Defects, overheating, recalls, hazards",
237
- "finance_team": "Invoices, billing, tax, payment issues",
238
  "orders_team": "Bulk orders, returns, subscriptions",
239
  "management_team": "Escalated complaints, manager requests",
240
  }
241
 
242
- _PHASE_COLORS = {1: "#60a5fa", 2: "#ffa94d", 3: "#00d084"}
243
- _PHASE_NAMES = {1: "Triage", 2: "Route", 3: "Resolve"}
244
- _TIER_COLORS = {"easy": "#00d084", "medium": "#ffa94d", "hard": "#ff6b6b"}
245
- _SENT_COLORS = {"positive": "#00d084", "neutral": "#9ca3af", "negative": "#ffa94d", "angry": "#ff6b6b"}
246
- _PRIO_COLORS = {"low": "#9ca3af", "medium": "#60a5fa", "high": "#ffa94d", "critical": "#ff6b6b"}
247
- _ACTION_COLORS = {"classify": "#60a5fa", "assign": "#ffa94d", "respond": "#00d084", "refund": "#c084fc", "escalate": "#ff6b6b"}
248
-
249
  _agent_history: List[str] = []
250
 
 
 
 
251
 
252
- def _esc(s: str) -> str:
253
  return str(s).replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
254
 
255
  def _score_color(s: float) -> str:
256
- if s >= 0.8: return "#00d084"
257
- if s >= 0.5: return "#ffa94d"
258
  return "#ff6b6b"
259
 
260
- def _badge(label: str, color: str) -> str:
261
  return (
262
- f"<span style='display:inline-block;padding:2px 9px;border-radius:4px;"
263
- f"background:{color}22;color:{color};border:1px solid {color}66;"
264
- f"font-size:11px;font-weight:600;font-family:JetBrains Mono,monospace;"
265
- f"letter-spacing:.4px;text-transform:uppercase'>{_esc(label)}</span>"
 
266
  )
267
 
268
-
269
- def _obs_html(obs_json: str) -> str:
270
- if not obs_json:
271
- return "<div class='pg-placeholder'>Reset to load a ticket.</div>"
272
- return f"<pre class='pg-code'>{_esc(obs_json)}</pre>"
273
-
274
-
275
- def _steps_html(steps: List[str]) -> str:
276
- if not steps:
277
- return "<div class='pg-placeholder'>No steps taken yet.</div>"
278
- rows = ""
279
- for s in steps:
280
- color = "#9ca3af"
281
- for p, c in _PHASE_COLORS.items():
282
- if f"Phase {p}:" in s:
283
- color = c
284
- break
285
- rows += f"<div class='trace-step' style='border-left:3px solid {color};background:{color}0d'><code>{_esc(s)}</code></div>"
286
- return f"<div class='trace-wrap'>{rows}</div>"
287
-
288
-
289
- def _score_html(rewards: List[float], avg: float, done: bool) -> str:
290
- if not rewards:
291
- return "<div class='pg-placeholder'>No scores yet.</div>"
292
- badges = " ".join(
293
- f"<span class='score-badge' style='background:{_score_color(r)}22;color:{_score_color(r)};border:1px solid {_score_color(r)}66'>{r:.3f}</span>"
294
- for r in rewards
295
  )
296
- ac = _score_color(avg)
297
- dc = "#00d084" if done else "#ffa94d"
298
- return f"""
299
- <div class='pg-status'>
300
- <div class='stat-item'><span class='stat-label'>Steps</span><span class='stat-val'>{len(rewards)}</span></div>
301
- <div class='stat-item'><span class='stat-label'>Per-Phase Rewards</span><span>{badges}</span></div>
302
- <div class='stat-item'><span class='stat-label'>Avg Score</span><span class='stat-val' style='color:{ac};font-size:18px'>{avg:.3f}</span></div>
303
- <div class='stat-item'><span class='stat-label'>Done</span><span class='stat-val' style='color:{dc}'>{str(done).lower()}</span></div>
304
- </div>"""
305
-
306
-
307
- def _team_html(team_lines: List[str]) -> str:
308
- if not team_lines:
309
- return "<div class='pg-placeholder'>(no team assigned β€” triage or respond action)</div>"
310
- rows = ""
311
- for line in team_lines:
312
- # parse "[TKT-XXX] Team Name β€” subtitle"
313
- rows += f"<div class='team-row'><code>{_esc(line)}</code></div>"
314
- return f"<div class='team-wrap'>{rows}</div>"
315
-
316
-
317
- def _history_html() -> str:
318
- if not env.history:
319
- return "<div class='pg-placeholder'>(empty)</div>"
320
- rows = ""
321
- for entry in env.history:
322
- if entry.startswith("System:") or entry.startswith("Customer:"):
323
- cls = "hist-system"
324
- else:
325
- cls = "hist-agent"
326
- rows += f"<div class='hist-row {cls}'>{_esc(entry)}</div>"
327
- return f"<div class='hist-wrap'>{rows}</div>"
328
-
329
-
330
- def _msg_html(msg: str) -> str:
331
- if not msg:
332
- return "<div class='pg-placeholder'>(no customer-facing message β€” triage or route phase)</div>"
333
- return f"<div class='agent-msg'>{_esc(msg)}</div>"
334
-
335
-
336
- def _manual_score_html(reward: float, done: bool, feedback: str) -> str:
337
- c = _score_color(reward)
338
- dc = "#00d084" if done else "#ffa94d"
339
- fb = feedback[:300] + "..." if len(feedback) > 300 else feedback
340
- return f"""
341
- <div class='pg-status'>
342
- <div class='stat-item'><span class='stat-label'>Score</span><span class='stat-val' style='color:{c};font-size:18px'>{reward:.3f}</span></div>
343
- <div class='stat-item'><span class='stat-label'>Done</span><span class='stat-val' style='color:{dc}'>{str(done).lower()}</span></div>
344
- <div class='stat-item' style='flex:2'><span class='stat-label'>Grader Feedback</span><code style='font-size:11px;color:#9ca3af'>{_esc(fb)}</code></div>
345
- </div>"""
346
-
347
- # ---------------------------------------------------------------------------
348
- # Static HTML content sections
349
- # ---------------------------------------------------------------------------
350
-
351
- def _overview_html() -> str:
352
- cards = [
353
- ("⚑", "3-Phase MDP", "Not a bandit. Every ticket runs through Triage β†’ Route β†’ Resolve with state evolving between steps β€” a proper sequential decision problem."),
354
- ("🎯", "Dense Rewards", "Every phase returns an intermediate reward. No sparse end-of-episode signal. Phase 1 binary, Phase 2 graded, Phase 3 quality-scored."),
355
- ("πŸ”€", "State Transitions", "After Phase 1 the observation's issue_type updates from 'unknown' to the true category. After Phase 2 the assigned team appears in history. The agent sees richer context at each step."),
356
- ("βš–οΈ", "Asymmetric Penalties", "Refund (-0.50) > Escalation (-0.30) > Wrong Team (-0.15). Mirrors real business cost: an unwarranted refund is immediate financial loss."),
357
- ("πŸ“Š", "Proportional Scoring", "Phase 3 normalizes raw_score / max_possible so a simple ticket can still score 0.998 without being penalized for omitting components it never needed."),
358
- ("πŸ”’", "Deterministic Grader", "Same action + same ticket = same reward. No stochasticity in the grader. Reproducible RL training and evaluation."),
359
- ]
360
- grid = ""
361
- for icon, title, body in cards:
362
- grid += f"""
363
- <div class='unique-card'>
364
- <div class='card-icon'>{icon}</div>
365
- <div class='card-title'>{title}</div>
366
- <div class='card-body'>{body}</div>
367
- </div>"""
368
- arch = """
369
- <div class='arch-box'>
370
- <pre class='pg-code' style='margin:0'>Episode Flow (3 steps per ticket):
371
-
372
- reset()
373
- └─▢ Observation {issue_type: "unknown", sentiment, priority, message}
374
-
375
- step({"action_type": "classify"}) ← Phase 1: Triage
376
- └─▢ issue_type revealed in observation
377
- └─▢ reward: 0.998 (correct) or 0.002
378
-
379
- step({"action_type": "assign", "team": …}) ← Phase 2: Route
380
- └─▢ team context appended to history
381
- └─▢ reward: 0.998 / 0.400 / 0.002
382
-
383
- step({"action_type": "respond/refund/escalate", …}) ← Phase 3: Resolve
384
- └─▢ done = True
385
- └─▢ reward: proportional quality score in [0.002, 0.998]
386
-
387
- episode_score = mean(phase1_reward, phase2_reward, phase3_reward)</pre>
388
- </div>"""
389
- return f"""
390
- <h2 class='section-h'>What makes this a real RL environment</h2>
391
- <p class='section-sub'>Six design decisions that distinguish this from single-step LLM evaluation benchmarks.</p>
392
- <div class='unique-grid'>{grid}</div>
393
- <h2 class='section-h' style='margin-top:40px'>Episode Architecture</h2>
394
- <p class='section-sub'>Each episode is a deterministic 3-step MDP. Observation state updates between steps.</p>
395
- {arch}"""
396
-
397
-
398
- def _scenarios_html() -> str:
399
- out = ""
400
- for tier in ["easy", "medium", "hard"]:
401
- scenarios = TASK_REGISTRY[tier]
402
- tc = _TIER_COLORS[tier]
403
- out += f"<h3 class='tier-header' style='color:{tc}'>{tier.upper()} TIER β€” {len(scenarios)} scenarios</h3>"
404
- for sc in scenarios:
405
- t = sc.ticket
406
- gt = sc.ground_truth
407
- sc_color = _ACTION_COLORS.get(gt.action_type, "#9ca3af")
408
- sent_c = _SENT_COLORS.get(t.sentiment, "#9ca3af")
409
- prio_c = _PRIO_COLORS.get(t.priority, "#9ca3af")
410
- kw_html = " ".join(
411
- f"<code class='kw-tag'>{_esc(k)}</code>"
412
- for k in gt.response_keywords
413
- ) if gt.response_keywords else "<span class='muted'>none</span>"
414
- team_html = (
415
- f"<code style='color:#ffa94d'>{_esc(gt.team)}</code>"
416
- if gt.team else "<span class='muted'>β€”</span>"
417
- )
418
- out += f"""
419
- <div class='scen-card'>
420
- <div class='scen-header'>
421
- {_badge(tier, tc)}
422
- {_badge(t.sentiment, sent_c)}
423
- {_badge(t.priority, prio_c)}
424
- <code class='ticket-id'>{_esc(t.ticket_id)}</code>
425
- </div>
426
- <div class='scen-message'>&ldquo;{_esc(t.message)}&rdquo;</div>
427
- <div class='scen-meta'>
428
- <div class='meta-item'>
429
- <span class='meta-label'>Phase 3 Action</span>
430
- <span>{_badge(gt.action_type, sc_color)}</span>
431
- </div>
432
- <div class='meta-item'>
433
- <span class='meta-label'>Target Team</span>
434
- <span>{team_html}</span>
435
- </div>
436
- <div class='meta-item'>
437
- <span class='meta-label'>Response Keywords</span>
438
- <span>{kw_html}</span>
439
- </div>
440
- </div>
441
- </div>"""
442
- return out
443
 
444
-
445
- def _try_it_html() -> str:
446
- model = _esc(MODEL_NAME)
447
- return f"""
448
- <h2 class='section-h'>Run the baseline yourself</h2>
449
- <p class='section-sub'>The validator runs <code>inference.py</code> and parses structured stdout logs. Reproduce it locally with:</p>
450
- <div class='code-block'>
451
- <pre># Set environment variables
452
- export API_BASE_URL=https://your-llm-proxy/v1
453
- export HF_TOKEN=your_token_here
454
- export MODEL_NAME={model}
455
-
456
- # Run all 3 tasks (easy / medium / hard)
457
- python inference.py</pre>
458
- </div>
459
- <h3 class='section-h' style='margin-top:32px'>Expected output format</h3>
460
- <div class='code-block'>
461
- <pre>[INFO] Using API_BASE_URL=https://... MODEL_NAME={model}
462
-
463
- [START] task=easy env=support_env model={model}
464
- [STEP] step=1 action={{"action_type":"classify"}} reward=1.00 done=false error=null
465
- [STEP] step=2 action={{"action_type":"assign","team":"orders_team"}} reward=1.00 done=false error=null
466
- [STEP] step=3 action={{"action_type":"respond","response":"..."}} reward=0.87 done=true error=null
467
- [END] success=true steps=3 score=0.957 rewards=1.00,1.00,0.87
468
-
469
- [START] task=medium env=support_env model={model}
470
- ...
471
- [START] task=hard env=support_env model={model}
472
- ...</pre>
473
- </div>
474
- <h3 class='section-h' style='margin-top:32px'>Reward scoring summary</h3>
475
- <div class='scoring-grid'>
476
- <div class='scoring-row header'><span>Phase</span><span>Correct</span><span>Wrong</span></div>
477
- <div class='scoring-row'><span style='color:#60a5fa'>Phase 1 β€” Triage</span><span style='color:#00d084'>0.998</span><span style='color:#ff6b6b'>0.002</span></div>
478
- <div class='scoring-row'><span style='color:#ffa94d'>Phase 2 β€” Route</span><span style='color:#00d084'>0.998</span><span style='color:#ffa94d'>0.400 (wrong team)</span></div>
479
- <div class='scoring-row'><span style='color:#00d084'>Phase 3 β€” Resolve</span><span style='color:#00d084'>0.002 – 0.998</span><span style='color:#ff6b6b'>penalties apply</span></div>
480
- </div>
481
- <p class='muted' style='margin-top:16px;font-size:12px'>All scores clamped to [0.002, 0.998]. Episode score = mean of all step rewards.</p>"""
482
 
483
  # ---------------------------------------------------------------------------
484
  # CSS
@@ -487,321 +288,832 @@ python inference.py</pre>
487
  CSS = """
488
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');
489
 
490
- *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
 
491
 
492
  .gradio-container {
493
- background: #0a0a0a !important;
494
- color: #ededed !important;
495
- font-family: Inter, system-ui, sans-serif !important;
496
  max-width: 100% !important;
497
- padding: 0 28px 32px !important;
 
498
  }
 
499
 
500
- /* ── Tabs ─────────────────────────────────────────────────────────── */
501
- .tab-nav button {
 
 
502
  background: transparent !important;
503
- color: #9ca3af !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
504
  border: none !important;
505
  border-bottom: 2px solid transparent !important;
506
  font-family: Inter, sans-serif !important;
507
  font-size: 13px !important;
508
  font-weight: 500 !important;
509
- padding: 10px 18px !important;
 
 
510
  transition: color .15s, border-color .15s !important;
 
511
  }
512
- .tab-nav button:hover { color: #ededed !important; }
513
- .tab-nav button.selected {
514
  color: #00d084 !important;
515
  border-bottom-color: #00d084 !important;
516
  }
517
- .tabitem { background: transparent !important; border: none !important; padding: 24px 0 0 !important; }
 
 
 
 
518
 
519
- /* ── Hero bar ─────────────────────────────────────────────────────── */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
520
  .hero {
521
- display: flex;
522
- gap: 32px;
523
- align-items: center;
524
- padding: 28px 32px;
525
  background: #141414;
526
- border: 1px solid #262626;
527
- border-radius: 10px;
528
- margin-bottom: 28px;
529
- flex-wrap: wrap;
530
- }
531
- .hero-title { flex: 1; }
532
- .hero-title h1 { font-size: 22px; font-weight: 700; color: #ededed; line-height: 1.3; }
533
- .hero-title p { font-size: 13px; color: #9ca3af; margin-top: 4px; }
534
- .hero-stats { display: flex; gap: 28px; flex-wrap: wrap; }
535
- .stat-pill {
536
- display: flex; flex-direction: column; align-items: center;
537
- padding: 8px 18px;
538
- background: #0a0a0a;
539
- border: 1px solid #262626;
 
 
 
 
 
 
 
 
 
 
 
 
540
  border-radius: 8px;
541
- min-width: 80px;
542
  }
543
- .stat-pill .num { font-size: 22px; font-weight: 700; color: #00d084; font-family: JetBrains Mono, monospace; }
544
- .stat-pill .lbl { font-size: 11px; color: #9ca3af; margin-top: 2px; text-transform: uppercase; letter-spacing: .5px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
545
 
546
  /* ── Section typography ───────────────────────────────────────────── */
547
- .section-h { font-size: 17px; font-weight: 600; color: #ededed; margin: 28px 0 8px; }
548
- .section-sub { font-size: 13px; color: #9ca3af; margin-bottom: 20px; line-height: 1.6; }
549
- .muted { color: #9ca3af; }
550
- .tier-header { font-size: 13px; font-weight: 600; letter-spacing: 1px; margin: 28px 0 12px; font-family: JetBrains Mono, monospace; }
551
 
552
- /* ── Unique cards grid ────────────────────────────────────────────── */
553
  .unique-grid {
554
  display: grid;
555
- grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
556
- gap: 16px;
 
557
  }
558
  .unique-card {
559
  background: #141414;
560
- border: 1px solid #262626;
561
  border-radius: 10px;
562
- padding: 20px;
563
  transition: border-color .2s, transform .2s;
564
  }
565
- .unique-card:hover { border-color: #00d084; transform: translateY(-2px); }
566
- .card-icon { font-size: 24px; margin-bottom: 10px; }
567
- .card-title { font-size: 14px; font-weight: 600; color: #ededed; margin-bottom: 6px; }
568
- .card-body { font-size: 13px; color: #9ca3af; line-height: 1.6; }
569
-
570
- /* ── Architecture box ─────────────────────────────────────────────── */
571
- .arch-box { background: #141414; border: 1px solid #262626; border-radius: 10px; overflow: hidden; }
572
-
573
- /* ── Scenario cards ───────────────────────────────────────────────── */
574
- .scen-card {
575
- background: #141414;
576
- border: 1px solid #262626;
577
- border-radius: 10px;
578
- padding: 18px 20px;
579
- margin-bottom: 12px;
580
- transition: border-color .2s;
581
- }
582
- .scen-card:hover { border-color: #404040; }
583
- .scen-header { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
584
- .ticket-id { font-family: JetBrains Mono, monospace; font-size: 12px; color: #9ca3af; margin-left: auto; }
585
- .scen-message {
586
- font-size: 13px; color: #ededed; line-height: 1.6;
587
- border-left: 3px solid #00d08444;
588
- padding: 8px 14px;
589
- background: #0a0a0a;
590
- border-radius: 0 6px 6px 0;
591
- margin-bottom: 14px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
592
  font-style: italic;
593
  }
594
- .scen-meta { display: flex; gap: 20px; flex-wrap: wrap; }
595
- .meta-item { display: flex; flex-direction: column; gap: 4px; }
596
- .meta-label { font-size: 11px; color: #9ca3af; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
597
- .kw-tag {
598
- display: inline-block; padding: 1px 7px; border-radius: 4px;
599
- background: #1a1a1a; color: #9ca3af; border: 1px solid #333;
600
- font-size: 11px; font-family: JetBrains Mono, monospace; margin: 2px;
 
 
 
601
  }
602
 
603
- /* ── Playground ───────────────────────────────────────────────────── */
604
- .pg-placeholder { color: #5a5a5a; font-size: 13px; padding: 16px; font-style: italic; }
605
- .pg-code {
606
- background: #0a0a0a;
607
- border: 1px solid #262626;
608
- border-radius: 8px;
609
- padding: 16px;
610
- font-family: JetBrains Mono, monospace;
611
- font-size: 12px;
612
- color: #9ca3af;
613
- overflow-x: auto;
614
- white-space: pre;
615
- line-height: 1.6;
616
- }
617
- .pg-status {
618
  display: flex;
619
- gap: 0;
 
 
 
 
 
 
 
 
 
620
  background: #141414;
621
- border: 1px solid #262626;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
622
  border-radius: 8px;
623
  overflow: hidden;
624
  }
625
- .stat-item {
626
- display: flex; flex-direction: column; gap: 4px;
627
- padding: 14px 20px;
628
- border-right: 1px solid #262626;
629
- flex: 1;
630
- }
631
- .stat-item:last-child { border-right: none; }
632
- .stat-label { font-size: 11px; color: #9ca3af; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
633
- .stat-val { font-size: 15px; font-weight: 700; color: #ededed; font-family: JetBrains Mono, monospace; }
634
- .score-badge {
635
- display: inline-block; padding: 2px 9px; border-radius: 4px;
636
- font-size: 12px; font-weight: 600; font-family: JetBrains Mono, monospace;
637
- margin: 2px;
 
 
 
 
638
  }
639
 
640
- /* ── Trace steps ─────────────────────────────────────────────────── */
641
- .trace-wrap { display: flex; flex-direction: column; gap: 6px; }
642
- .trace-step {
643
- padding: 10px 14px;
644
- border-radius: 6px;
645
- font-size: 12px;
646
- line-height: 1.5;
 
 
 
647
  }
648
- .trace-step code { font-family: JetBrains Mono, monospace; color: #ededed; background: none; }
 
 
649
 
650
- /* ── Team assignment ─────────────────────────────────────────────── */
651
- .team-wrap { display: flex; flex-direction: column; gap: 6px; }
652
- .team-row {
653
- padding: 10px 14px;
 
 
 
654
  background: #141414;
655
- border: 1px solid #ffa94d33;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
656
  border-left: 3px solid #ffa94d;
 
 
 
 
 
 
 
657
  border-radius: 6px;
658
- font-size: 12px;
 
 
659
  }
660
- .team-row code { font-family: JetBrains Mono, monospace; color: #ffa94d; background: none; }
661
-
662
- /* ── History ─────────────────────────────────────────────────────── */
663
- .hist-wrap { display: flex; flex-direction: column; gap: 4px; }
664
- .hist-row { padding: 7px 12px; border-radius: 5px; font-size: 12px; line-height: 1.5; }
665
- .hist-agent { background: #60a5fa0d; border-left: 3px solid #60a5fa; color: #ededed; }
666
- .hist-system { background: #0a0a0a; border-left: 3px solid #333; color: #9ca3af; font-style: italic; }
667
 
668
- /* ── Agent message ───────────────────────────────────────────────── */
669
- .agent-msg {
 
670
  background: #141414;
671
- border: 1px solid #00d08433;
672
  border-left: 3px solid #00d084;
673
  border-radius: 8px;
674
- padding: 14px 18px;
675
  font-size: 13px;
676
- line-height: 1.7;
677
- color: #ededed;
 
678
  }
679
 
680
- /* ── Try It code blocks ──────────────────────────────────────────── */
681
  .code-block {
682
- background: #161b22;
683
- border: 1px solid #30363d;
684
  border-radius: 8px;
685
  overflow: hidden;
 
686
  }
687
  .code-block pre {
688
- padding: 18px 20px;
689
- font-family: JetBrains Mono, monospace;
690
  font-size: 12px;
691
- color: #9ca3af;
692
- line-height: 1.7;
693
  white-space: pre;
694
  overflow-x: auto;
 
695
  }
696
- .scoring-grid {
697
- background: #141414;
698
- border: 1px solid #262626;
699
- border-radius: 8px;
700
- overflow: hidden;
701
- }
702
- .scoring-row {
703
- display: grid;
704
- grid-template-columns: 1fr 1fr 1fr;
705
- padding: 10px 16px;
706
- border-bottom: 1px solid #1f1f1f;
707
- font-size: 13px;
708
- font-family: JetBrains Mono, monospace;
709
- }
710
- .scoring-row.header {
711
- background: #0a0a0a;
712
- font-size: 11px;
713
- text-transform: uppercase;
714
- letter-spacing: .5px;
715
- color: #5a5a5a;
716
- font-weight: 600;
717
- }
718
- .scoring-row:last-child { border-bottom: none; }
719
 
720
- /* ── Gradio component overrides ──────────────────────────────────── */
721
- .gradio-container label { color: #9ca3af !important; font-size: 12px !important; }
722
- .gradio-container input, .gradio-container select, .gradio-container textarea {
723
- background: #141414 !important;
724
- border-color: #262626 !important;
725
- color: #ededed !important;
726
- font-family: JetBrains Mono, monospace !important;
727
- font-size: 12px !important;
728
- }
729
- .gradio-container .gr-button-primary, button.primary {
730
- background: #00d084 !important;
731
- color: #0a0a0a !important;
732
- border: 1px solid #00a866 !important;
733
- font-weight: 600 !important;
734
- font-family: Inter, sans-serif !important;
735
- }
736
- .gradio-container .gr-button-primary:hover { background: #00b870 !important; }
737
- .gradio-container .gr-button-secondary, button.secondary {
738
- background: #141414 !important;
739
- color: #ededed !important;
740
- border: 1px solid #262626 !important;
741
- }
742
- .gradio-container .gr-button-secondary:hover { border-color: #404040 !important; }
743
- .gradio-container .gr-accordion {
744
- background: #141414 !important;
745
- border-color: #262626 !important;
746
- }
747
- .gradio-container .block.svelte-1gfkfd6 {
748
- background: transparent !important;
749
- border: none !important;
750
- }
751
-
752
- /* ── Footer ──────────────────────────────────────────────────────── */
753
  .footer {
754
  margin-top: 48px;
755
- padding-top: 20px;
756
- border-top: 1px solid #1f1f1f;
757
- text-align: center;
758
  font-size: 12px;
759
- color: #5a5a5a;
760
- line-height: 1.8;
761
  }
762
- .footer a { color: #9ca3af; text-decoration: none; }
763
  .footer a:hover { color: #00d084; }
764
  """
765
 
766
- HERO_HTML = """
 
 
 
 
 
 
 
 
 
 
 
 
767
  <div class='hero'>
768
- <div class='hero-title'>
769
- <h1>Customer Support Agent</h1>
770
- <p>OpenEnv-compliant autonomous BPO agent Β· Meta PyTorch Hackathon x Scaler</p>
 
 
 
 
 
 
771
  </div>
772
- <div class='hero-stats'>
773
- <div class='stat-pill'><span class='num'>15</span><span class='lbl'>Tickets</span></div>
774
- <div class='stat-pill'><span class='num'>3</span><span class='lbl'>Tiers</span></div>
775
- <div class='stat-pill'><span class='num'>3</span><span class='lbl'>Phases</span></div>
776
- <div class='stat-pill'><span class='num'>6</span><span class='lbl'>Teams</span></div>
777
- <div class='stat-pill'><span class='num'>5</span><span class='lbl'>Max Steps</span></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
778
  </div>
779
- </div>
780
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
781
 
782
- FOOTER_HTML = """
783
- <div class='footer'>
784
- customer-support-agent · 3-phase MDP · 15 tickets · 6 specialist teams · deterministic grader · reward ∈ [0.002, 0.998]<br/>
785
- <a href='https://github.com/AdityaK-labs/Support-Agent/tree/Tarun'>github</a> Β·
786
- <a href='https://huggingface.co/spaces/Tarun21W/MetaAI'>huggingface</a>
787
- </div>
788
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
789
 
790
  # ---------------------------------------------------------------------------
791
- # Gradio UI functions
792
  # ---------------------------------------------------------------------------
793
 
794
  def ui_reset(task_choice: str):
795
  global _agent_history
796
  _agent_history = []
797
- task_name = TASK_MAP.get(task_choice, "easy")
798
  res = env.reset(task_name)
799
  obs_json = res.observation.model_dump_json(indent=2)
 
800
  return (
801
  _obs_html(obs_json),
802
  _msg_html(""),
803
  _steps_html([]),
804
- "<div class='pg-placeholder'>No scores yet.</div>",
805
  _history_html(),
806
  _team_html([]),
807
  )
@@ -814,16 +1126,16 @@ async def ui_auto_step():
814
  return (
815
  _obs_html(env.get_current_observation().model_dump_json(indent=2)),
816
  _msg_html(""),
817
- "<div class='pg-placeholder'>Episode finished β€” please reset.</div>",
818
- "<div class='pg-placeholder'>Episode finished.</div>",
819
  _history_html(),
820
  _team_html([]),
821
  )
822
 
823
- all_steps = []
824
- all_rewards = []
825
  last_message = ""
826
- team_lines = []
827
 
828
  for step_num in range(1, 6):
829
  if env.done:
@@ -843,7 +1155,7 @@ async def ui_auto_step():
843
  elif current_phase == 2:
844
  action = Action(action_type="assign", team="management_team")
845
  else:
846
- action = Action(action_type="respond", response="Thank you for contacting us.")
847
 
848
  result = env.step(action)
849
  reward = result.reward
@@ -852,18 +1164,21 @@ async def ui_auto_step():
852
  _agent_history = env.history.copy()
853
  all_rewards.append(reward)
854
 
855
- phase_label = _PHASE_NAMES.get(current_phase, str(current_phase))
856
- step_line = f"[Phase {current_phase}: {phase_label}] step={step_num} {action.action_type}"
857
- if action.team: step_line += f" β†’ {action.team}"
858
- step_line += f" | score: {reward:.3f}"
859
- if error_msg: step_line += f" ⚠ {error_msg[:60]}"
860
- all_steps.append(step_line)
 
 
 
861
 
862
  if action.team:
863
- desc = TEAM_DESCRIPTIONS.get(action.team, action.team)
864
- sub = TEAM_SUBTITLES.get(action.team, "")
865
  tid = obs.ticket_id if hasattr(obs, "ticket_id") else "?"
866
- team_lines.append(f"[{tid}] {desc} β€” {sub}")
867
 
868
  if action.response:
869
  last_message = action.response
@@ -889,13 +1204,14 @@ def ui_manual_step(a_type: str, t_name: str, resp_text: str):
889
  return (
890
  _obs_html(env.get_current_observation().model_dump_json(indent=2)),
891
  _msg_html(""),
892
- "<div class='pg-placeholder'>Episode finished β€” please reset.</div>",
893
- "<div class='pg-placeholder'>Episode finished.</div>",
894
  _history_html(),
895
  _team_html([]),
896
  )
897
 
898
  try:
 
899
  action = Action(
900
  action_type=a_type,
901
  team=t_name or None,
@@ -906,33 +1222,42 @@ def ui_manual_step(a_type: str, t_name: str, resp_text: str):
906
  done = result.done
907
  _agent_history = env.history.copy()
908
 
909
- phase_num = result.info.get("phase", env.phase)
910
- phase_lbl = _PHASE_NAMES.get(phase_num - 1, str(phase_num - 1))
911
- step_line = f"[Phase {phase_num - 1}: {phase_lbl}] {a_type}"
912
- if t_name: step_line += f" β†’ {t_name}"
913
- step_line += f" | score: {reward:.3f}"
 
 
 
 
914
 
915
  team_lines = []
916
  if t_name:
917
- desc = TEAM_DESCRIPTIONS.get(t_name, t_name)
918
- sub = TEAM_SUBTITLES.get(t_name, "")
919
- team_lines.append(f"[{env.current_scenario.ticket.ticket_id}] {desc} β€” {sub}")
 
 
 
 
920
 
921
  return (
922
  _obs_html(result.observation.model_dump_json(indent=2)),
923
  _msg_html(resp_text or ""),
924
- _steps_html([step_line]),
925
- _manual_score_html(reward, done, result.info.get("feedback", "")),
926
  _history_html(),
927
  _team_html(team_lines),
928
  )
929
 
930
  except Exception as exc:
 
931
  return (
932
  _obs_html(env.get_current_observation().model_dump_json(indent=2)),
933
  _msg_html(""),
934
- f"<div class='pg-placeholder' style='color:#ff6b6b'>Error: {_esc(str(exc))}</div>",
935
- "<div class='pg-placeholder'>β€”</div>",
936
  _history_html(),
937
  _team_html([]),
938
  )
@@ -941,73 +1266,67 @@ def ui_manual_step(a_type: str, t_name: str, resp_text: str):
941
  # Gradio layout
942
  # ---------------------------------------------------------------------------
943
 
 
 
944
  with gr.Blocks(css=CSS, title="Customer Support Agent β€” OpenEnv") as demo:
945
 
946
- gr.HTML(HERO_HTML)
947
 
948
  with gr.Tabs():
949
 
950
- # ── Tab 1: Overview ───────────────────────────────────────────
951
  with gr.Tab("Overview"):
952
  gr.HTML(_overview_html())
953
 
954
- # ── Tab 2: Scenarios ──────────────────────────────────────────
955
  with gr.Tab("Scenarios"):
956
- gr.HTML(f"<h2 class='section-h'>15 support tickets Β· 3 difficulty tiers</h2>")
957
- gr.HTML(f"<p class='section-sub'>Each scenario runs the full 3-phase MDP. Phase 3 action and keywords shown are the ground truth the grader checks against.</p>")
958
  gr.HTML(_scenarios_html())
959
 
960
- # ── Tab 3: Playground ─────────────────────────────────────────
961
  with gr.Tab("Playground"):
962
- gr.HTML("<h2 class='section-h'>Live interactive episode</h2>")
963
- gr.HTML("<p class='section-sub'>Select a task tier, reset the environment, then run the full 3-phase episode automatically β€” or step through each phase manually.</p>")
964
 
965
  with gr.Row():
966
- task_dd = gr.Dropdown(choices=list(TASK_MAP.keys()), value="Easy (Classification)", label="Task Tier", scale=4)
967
- reset_btn = gr.Button("Reset Episode", variant="secondary", scale=1, min_width=140)
968
- auto_btn = gr.Button("Run Agent (Full Episode)", variant="primary", scale=2, min_width=200)
969
 
970
  with gr.Row():
971
  with gr.Column(scale=1):
972
- gr.HTML("<div class='section-h' style='margin:16px 0 8px'>Current Observation</div>")
973
- obs_out = gr.HTML(_obs_html(""), label="")
974
-
975
- gr.HTML("<div class='section-h' style='margin:16px 0 8px'>Action History</div>")
976
- hist_out = gr.HTML(_history_html(), label="")
977
 
978
  with gr.Column(scale=1):
979
- gr.HTML("<div class='section-h' style='margin:16px 0 8px'>Phase Steps</div>")
980
- steps_out = gr.HTML(_steps_html([]), label="")
981
-
982
- gr.HTML("<div class='section-h' style='margin:16px 0 8px'>Team Assignment</div>")
983
- team_out = gr.HTML(_team_html([]), label="")
984
-
985
- gr.HTML("<div class='section-h' style='margin:16px 0 8px'>Agent Response</div>")
986
- msg_out = gr.HTML(_msg_html(""), label="")
987
 
988
- gr.HTML("<div class='section-h' style='margin:16px 0 8px'>Score</div>")
989
- score_out = gr.HTML("<div class='pg-placeholder'>No scores yet.</div>", label="")
990
 
991
- with gr.Accordion("Manual Step (override agent)", open=False):
 
992
  with gr.Row():
993
- act_type = gr.Dropdown(choices=["classify","assign","respond","refund","escalate"], value="classify", label="Action Type", scale=1)
994
- act_team = gr.Textbox(label="Team (optional)", scale=1)
 
 
 
995
  with gr.Row():
996
- act_resp = gr.Textbox(label="Response text (optional)", lines=2, scale=3)
997
- manual_btn = gr.Button("Submit Manual Action", variant="primary", scale=1, min_width=160)
 
998
 
999
- # ── Tab 4: Try It ─────────────────────────────────────────────
1000
  with gr.Tab("Try It"):
1001
  gr.HTML(_try_it_html())
1002
 
1003
- gr.HTML(FOOTER_HTML)
1004
 
1005
- # ── Event wiring ─────────────────────────────────────────────────
1006
  _outputs = [obs_out, msg_out, steps_out, score_out, hist_out, team_out]
1007
 
1008
- reset_btn.click(ui_reset, inputs=[task_dd], outputs=_outputs)
1009
- auto_btn.click( ui_auto_step, inputs=[], outputs=_outputs)
1010
- manual_btn.click(ui_manual_step, inputs=[act_type, act_team, act_resp], outputs=_outputs)
1011
 
1012
  demo.queue()
1013
  app = gr.mount_gradio_app(app, demo, path="/")
 
212
  return json.loads(match.group(1))
213
 
214
  # ---------------------------------------------------------------------------
215
+ # Design tokens
216
  # ---------------------------------------------------------------------------
217
 
218
+ _PHASE_COLORS = {1: "#60a5fa", 2: "#ffa94d", 3: "#00d084"}
219
+ _PHASE_NAMES = {1: "Triage", 2: "Route", 3: "Resolve"}
220
+ _TIER_COLORS = {"easy": "#00d084", "medium": "#ffa94d", "hard": "#ff6b6b"}
221
+ _SENT_COLORS = {"positive": "#00d084", "neutral": "#9ca3af", "negative": "#ffa94d", "angry": "#ff6b6b"}
222
+ _PRIO_COLORS = {"low": "#9ca3af", "medium": "#60a5fa", "high": "#ffa94d", "critical": "#ff6b6b"}
223
+ _ACTION_COLORS = {"classify": "#60a5fa", "assign": "#ffa94d", "respond": "#00d084", "refund": "#c084fc", "escalate": "#ff6b6b"}
224
+ _TEAM_NAMES = {
225
  "logistics_team": "Logistics Team",
226
  "tech_support_team": "Tech Support Team",
227
  "safety_team": "Safety Team",
 
229
  "orders_team": "Orders Team",
230
  "management_team": "Management Team",
231
  }
232
+ _TEAM_SUBTITLES = {
 
233
  "logistics_team": "Shipping, delivery, lost packages",
234
  "tech_support_team": "Login, bugs, API errors, data loss",
235
  "safety_team": "Defects, overheating, recalls, hazards",
236
+ "finance_team": "Invoices, billing, tax, payments",
237
  "orders_team": "Bulk orders, returns, subscriptions",
238
  "management_team": "Escalated complaints, manager requests",
239
  }
240
 
 
 
 
 
 
 
 
241
  _agent_history: List[str] = []
242
 
243
+ # ---------------------------------------------------------------------------
244
+ # HTML utility helpers
245
+ # ---------------------------------------------------------------------------
246
 
247
+ def _esc(s) -> str:
248
  return str(s).replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
249
 
250
  def _score_color(s: float) -> str:
251
+ if s >= 0.80: return "#00d084"
252
+ if s >= 0.50: return "#ffa94d"
253
  return "#ff6b6b"
254
 
255
+ def _badge(label: str, color: str, size: str = "12") -> str:
256
  return (
257
+ f"<span style='display:inline-flex;align-items:center;padding:2px 9px;"
258
+ f"border-radius:4px;background:{color}1a;color:{color};"
259
+ f"border:1px solid {color}44;font-size:{size}px;font-weight:600;"
260
+ f"font-family:\"JetBrains Mono\",monospace;letter-spacing:.3px;"
261
+ f"text-transform:uppercase;line-height:1.6'>{_esc(label)}</span>"
262
  )
263
 
264
+ def _icon_box(svg_path: str) -> str:
265
+ return (
266
+ f"<div style='width:40px;height:40px;background:#0a2a1a;"
267
+ f"border:1px solid #1a4a2a;border-radius:8px;"
268
+ f"display:flex;align-items:center;justify-content:center;margin-bottom:14px;flex-shrink:0'>"
269
+ f"<svg width='18' height='18' viewBox='0 0 24 24' fill='none' "
270
+ f"stroke='#00d084' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'>"
271
+ f"{svg_path}</svg></div>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
 
274
+ # SVG icon paths (Lucide-style)
275
+ _ICONS = {
276
+ "zap": "<polygon points='13 2 3 14 12 14 11 22 21 10 12 10 13 2'/>",
277
+ "layers": "<polygon points='12 2 2 7 12 12 22 7 12 2'/><polyline points='2 17 12 22 22 17'/><polyline points='2 12 12 17 22 12'/>",
278
+ "git": "<line x1='6' y1='3' x2='6' y2='15'/><circle cx='18' cy='6' r='3'/><circle cx='6' cy='18' r='3'/><path d='M18 9a9 9 0 0 1-9 9'/>",
279
+ "scale": "<line x1='12' y1='3' x2='12' y2='21'/><path d='M3 9l4.5 9'/><path d='M21 9l-4.5 9'/><path d='M3 18a4.5 4.5 0 0 0 9 0'/><path d='M12 18a4.5 4.5 0 0 0 9 0'/>",
280
+ "bar": "<line x1='18' y1='20' x2='18' y2='10'/><line x1='12' y1='20' x2='12' y2='4'/><line x1='6' y1='20' x2='6' y2='14'/><line x1='2' y1='20' x2='22' y2='20'/>",
281
+ "lock": "<rect x='3' y='11' width='18' height='11' rx='2' ry='2'/><path d='M7 11V7a5 5 0 0 1 10 0v4'/>",
282
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
 
284
  # ---------------------------------------------------------------------------
285
  # CSS
 
288
  CSS = """
289
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');
290
 
291
+ /* ── Global reset ─────────────────────────────────────────────────── */
292
+ *, *::before, *::after { box-sizing: border-box; }
293
 
294
  .gradio-container {
295
+ background: #0d0d0d !important;
296
+ color: #e8e8e8 !important;
297
+ font-family: Inter, system-ui, -apple-system, sans-serif !important;
298
  max-width: 100% !important;
299
+ padding: 0 !important;
300
+ min-height: 100vh !important;
301
  }
302
+ .gradio-container > .main { padding: 0 32px 40px !important; }
303
 
304
+ /* ── Strip default Gradio chrome from HTML containers ────────────── */
305
+ .gradio-container .block,
306
+ .gradio-container .form,
307
+ .gradio-container .gap {
308
  background: transparent !important;
309
+ border: none !important;
310
+ box-shadow: none !important;
311
+ padding: 0 !important;
312
+ gap: 0 !important;
313
+ }
314
+ .gradio-container .wrap { border: none !important; }
315
+ .gradio-container .output-html { padding: 0 !important; }
316
+
317
+ /* ── Tab bar ──────────────────────────────────────────────────────── */
318
+ .gradio-container .tab-nav {
319
+ background: #0d0d0d !important;
320
+ border-bottom: 1px solid #1f1f1f !important;
321
+ padding: 0 32px !important;
322
+ gap: 0 !important;
323
+ }
324
+ .gradio-container .tab-nav button {
325
+ background: transparent !important;
326
+ color: #666 !important;
327
  border: none !important;
328
  border-bottom: 2px solid transparent !important;
329
  font-family: Inter, sans-serif !important;
330
  font-size: 13px !important;
331
  font-weight: 500 !important;
332
+ padding: 14px 20px !important;
333
+ margin: 0 !important;
334
+ border-radius: 0 !important;
335
  transition: color .15s, border-color .15s !important;
336
+ letter-spacing: .2px !important;
337
  }
338
+ .gradio-container .tab-nav button:hover { color: #ccc !important; }
339
+ .gradio-container .tab-nav button.selected {
340
  color: #00d084 !important;
341
  border-bottom-color: #00d084 !important;
342
  }
343
+ .gradio-container .tabitem {
344
+ background: transparent !important;
345
+ border: none !important;
346
+ padding: 32px 0 0 !important;
347
+ }
348
 
349
+ /* ── Gradio input component overrides ────────────────────────────── */
350
+ .gradio-container select,
351
+ .gradio-container input[type=text],
352
+ .gradio-container textarea {
353
+ background: #1a1a1a !important;
354
+ border: 1px solid #2a2a2a !important;
355
+ color: #e8e8e8 !important;
356
+ font-family: "JetBrains Mono", monospace !important;
357
+ font-size: 12px !important;
358
+ border-radius: 6px !important;
359
+ }
360
+ .gradio-container select:focus,
361
+ .gradio-container input:focus,
362
+ .gradio-container textarea:focus {
363
+ border-color: #00d084 !important;
364
+ outline: none !important;
365
+ box-shadow: 0 0 0 2px #00d08422 !important;
366
+ }
367
+ .gradio-container label span {
368
+ color: #666 !important;
369
+ font-size: 11px !important;
370
+ font-weight: 600 !important;
371
+ text-transform: uppercase !important;
372
+ letter-spacing: .6px !important;
373
+ font-family: Inter, sans-serif !important;
374
+ }
375
+ button.primary, .gradio-container button.primary {
376
+ background: #00d084 !important;
377
+ color: #0a0a0a !important;
378
+ border: 1px solid #00a866 !important;
379
+ border-radius: 6px !important;
380
+ font-family: Inter, sans-serif !important;
381
+ font-weight: 600 !important;
382
+ font-size: 13px !important;
383
+ transition: background .15s !important;
384
+ }
385
+ button.primary:hover { background: #00b870 !important; }
386
+ button.secondary, .gradio-container button.secondary {
387
+ background: #1a1a1a !important;
388
+ color: #ccc !important;
389
+ border: 1px solid #2a2a2a !important;
390
+ border-radius: 6px !important;
391
+ font-family: Inter, sans-serif !important;
392
+ font-weight: 500 !important;
393
+ font-size: 13px !important;
394
+ transition: border-color .15s !important;
395
+ }
396
+ button.secondary:hover { border-color: #444 !important; color: #e8e8e8 !important; }
397
+ .gradio-container .gr-accordion {
398
+ background: #141414 !important;
399
+ border: 1px solid #222 !important;
400
+ border-radius: 8px !important;
401
+ margin-top: 16px !important;
402
+ }
403
+ .gradio-container .gr-accordion > .label-wrap {
404
+ padding: 12px 16px !important;
405
+ color: #888 !important;
406
+ font-size: 12px !important;
407
+ font-weight: 600 !important;
408
+ text-transform: uppercase !important;
409
+ letter-spacing: .5px !important;
410
+ }
411
+
412
+ /* ── Hero ─────────────────────────────────────────────────────────── */
413
  .hero {
 
 
 
 
414
  background: #141414;
415
+ border-bottom: 1px solid #1f1f1f;
416
+ padding: 32px 32px 28px;
417
+ }
418
+ .hero-title {
419
+ font-size: 26px;
420
+ font-weight: 700;
421
+ color: #f0f0f0;
422
+ line-height: 1.2;
423
+ margin-bottom: 10px;
424
+ letter-spacing: -.3px;
425
+ }
426
+ .hero-desc {
427
+ font-size: 13px;
428
+ color: #666;
429
+ line-height: 1.75;
430
+ max-width: 860px;
431
+ }
432
+ .stat-grid {
433
+ display: grid;
434
+ grid-template-columns: repeat(6, 1fr);
435
+ gap: 10px;
436
+ margin-top: 24px;
437
+ }
438
+ .stat-card {
439
+ background: #0d0d0d;
440
+ border: 1px solid #1f1f1f;
441
  border-radius: 8px;
442
+ padding: 18px 16px 14px;
443
  }
444
+ .sc-label {
445
+ font-size: 10px;
446
+ font-weight: 600;
447
+ color: #444;
448
+ text-transform: uppercase;
449
+ letter-spacing: 1.2px;
450
+ margin-bottom: 10px;
451
+ }
452
+ .sc-num {
453
+ font-size: 38px;
454
+ font-weight: 700;
455
+ color: #e8e8e8;
456
+ font-family: "JetBrains Mono", monospace;
457
+ line-height: 1;
458
+ }
459
+ .sc-num.sm { font-size: 22px; padding-top: 8px; }
460
 
461
  /* ── Section typography ───────────────────────────────────────────── */
462
+ .section-h { font-size: 18px; font-weight: 600; color: #f0f0f0; margin: 0 0 8px; }
463
+ .section-sub { font-size: 13px; color: #666; margin-bottom: 28px; line-height: 1.6; }
 
 
464
 
465
+ /* ── Overview unique cards ────────────────────────────────────────── */
466
  .unique-grid {
467
  display: grid;
468
+ grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
469
+ gap: 14px;
470
+ margin-top: 4px;
471
  }
472
  .unique-card {
473
  background: #141414;
474
+ border: 1px solid #222;
475
  border-radius: 10px;
476
+ padding: 22px 22px 20px;
477
  transition: border-color .2s, transform .2s;
478
  }
479
+ .unique-card:hover { border-color: #00d08466; transform: translateY(-2px); }
480
+ .uc-title { font-size: 14px; font-weight: 600; color: #f0f0f0; margin-bottom: 8px; }
481
+ .uc-body { font-size: 13px; color: #777; line-height: 1.7; }
482
+
483
+ /* ── Data tables (shared) ─────────────────────────────────────────── */
484
+ .data-table {
485
+ width: 100%;
486
+ border-collapse: collapse;
487
+ font-size: 12px;
488
+ font-family: "JetBrains Mono", monospace;
489
+ }
490
+ .data-table thead tr {
491
+ background: #0d0d0d;
492
+ border-bottom: 2px solid #1f1f1f;
493
+ }
494
+ .data-table th {
495
+ padding: 10px 14px;
496
+ text-align: left;
497
+ font-size: 10px;
498
+ font-weight: 600;
499
+ color: #444;
500
+ text-transform: uppercase;
501
+ letter-spacing: 1px;
502
+ white-space: nowrap;
503
+ }
504
+ .data-table th.tc { text-align: center; }
505
+ .data-table th.tr { text-align: right; }
506
+ .data-table td {
507
+ padding: 11px 14px;
508
+ border-bottom: 1px solid #1a1a1a;
509
+ vertical-align: middle;
510
+ color: #ccc;
511
+ line-height: 1.5;
512
+ }
513
+ .data-table td.tc { text-align: center; }
514
+ .data-table td.tr { text-align: right; }
515
+ .data-table tbody tr:hover { background: #161616; }
516
+ .data-table tbody tr:last-child td { border-bottom: none; }
517
+ .msg-cell {
518
+ max-width: 320px;
519
+ overflow: hidden;
520
+ text-overflow: ellipsis;
521
+ white-space: nowrap;
522
+ color: #888;
523
  font-style: italic;
524
  }
525
+ .kw-cell { max-width: 240px; }
526
+ .kw-tag {
527
+ display: inline-block;
528
+ padding: 1px 6px;
529
+ border-radius: 3px;
530
+ background: #1f1f1f;
531
+ border: 1px solid #2a2a2a;
532
+ color: #777;
533
+ font-size: 10px;
534
+ margin: 1px;
535
  }
536
 
537
+ /* ── Tier section ─────────────────────────────────────────────────── */
538
+ .tier-section { margin-bottom: 32px; }
539
+ .tier-header-row {
 
 
 
 
 
 
 
 
 
 
 
 
540
  display: flex;
541
+ align-items: center;
542
+ gap: 12px;
543
+ padding: 14px 16px;
544
+ background: #111;
545
+ border: 1px solid #1f1f1f;
546
+ border-radius: 8px 8px 0 0;
547
+ border-bottom: none;
548
+ }
549
+ .tier-info { font-size: 12px; color: #555; font-family: "JetBrains Mono", monospace; }
550
+ .table-wrap {
551
  background: #141414;
552
+ border: 1px solid #1f1f1f;
553
+ border-radius: 0 0 8px 8px;
554
+ overflow: hidden;
555
+ }
556
+
557
+ /* ── Playground panels ────────────────────────────────────────────── */
558
+ .panel-title {
559
+ font-size: 11px;
560
+ font-weight: 600;
561
+ color: #444;
562
+ text-transform: uppercase;
563
+ letter-spacing: 1px;
564
+ padding: 0 0 8px;
565
+ margin-bottom: 0;
566
+ }
567
+ .pg-panel {
568
+ background: #141414;
569
+ border: 1px solid #1f1f1f;
570
  border-radius: 8px;
571
  overflow: hidden;
572
  }
573
+ .pg-panel-head {
574
+ background: #111;
575
+ border-bottom: 1px solid #1f1f1f;
576
+ padding: 10px 16px;
577
+ font-size: 11px;
578
+ font-weight: 600;
579
+ color: #555;
580
+ text-transform: uppercase;
581
+ letter-spacing: 1px;
582
+ }
583
+ .pg-panel-body { padding: 0; }
584
+ .empty-state {
585
+ padding: 24px 16px;
586
+ color: #3a3a3a;
587
+ font-size: 13px;
588
+ font-style: italic;
589
+ text-align: center;
590
  }
591
 
592
+ /* Observation table inside panel */
593
+ .obs-table { width: 100%; border-collapse: collapse; }
594
+ .obs-table td { padding: 9px 16px; border-bottom: 1px solid #1a1a1a; font-size: 12px; vertical-align: top; }
595
+ .obs-table tr:last-child td { border-bottom: none; }
596
+ .obs-key {
597
+ width: 100px;
598
+ color: #444;
599
+ font-family: "JetBrains Mono", monospace;
600
+ font-size: 11px;
601
+ white-space: nowrap;
602
  }
603
+ .obs-val { color: #ccc; font-family: "JetBrains Mono", monospace; font-size: 12px; word-break: break-word; }
604
+ .obs-message { font-family: Inter, sans-serif; font-size: 12px; color: #999; font-style: italic; line-height: 1.6; }
605
+ .hist-mini { font-size: 11px; color: #555; line-height: 1.6; }
606
 
607
+ /* Episode score metrics bar */
608
+ .metrics-bar {
609
+ display: grid;
610
+ grid-template-columns: repeat(4, 1fr);
611
+ border: 1px solid #1f1f1f;
612
+ border-radius: 8px;
613
+ overflow: hidden;
614
  background: #141414;
615
+ }
616
+ .metric-cell {
617
+ padding: 16px;
618
+ border-right: 1px solid #1f1f1f;
619
+ }
620
+ .metric-cell:last-child { border-right: none; }
621
+ .metric-label { font-size: 10px; font-weight: 600; color: #444; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
622
+ .metric-val { font-size: 28px; font-weight: 700; color: #e8e8e8; font-family: "JetBrains Mono", monospace; line-height: 1; }
623
+ .metric-val.sm { font-size: 14px; padding-top: 7px; }
624
+ .score-pill {
625
+ display: inline-flex; align-items: center;
626
+ padding: 3px 10px; border-radius: 4px;
627
+ font-size: 12px; font-weight: 700;
628
+ font-family: "JetBrains Mono", monospace;
629
+ margin: 2px;
630
+ }
631
+
632
+ /* Team assignment card */
633
+ .team-card {
634
+ display: flex;
635
+ align-items: flex-start;
636
+ gap: 14px;
637
+ padding: 16px;
638
+ background: #141414;
639
+ border: 1px solid #1f1f1f;
640
  border-left: 3px solid #ffa94d;
641
+ border-radius: 8px;
642
+ margin-bottom: 8px;
643
+ }
644
+ .team-icon {
645
+ width: 36px; height: 36px;
646
+ background: #1f1500;
647
+ border: 1px solid #3a2800;
648
  border-radius: 6px;
649
+ display: flex; align-items: center; justify-content: center;
650
+ flex-shrink: 0;
651
+ font-size: 16px;
652
  }
653
+ .team-name { font-size: 13px; font-weight: 600; color: #e8e8e8; margin-bottom: 3px; }
654
+ .team-sub { font-size: 11px; color: #666; }
 
 
 
 
 
655
 
656
+ /* Agent response */
657
+ .agent-response {
658
+ padding: 16px;
659
  background: #141414;
660
+ border: 1px solid #00d08422;
661
  border-left: 3px solid #00d084;
662
  border-radius: 8px;
 
663
  font-size: 13px;
664
+ color: #ccc;
665
+ line-height: 1.75;
666
+ font-family: Inter, sans-serif;
667
  }
668
 
669
+ /* Try It code blocks */
670
  .code-block {
671
+ background: #0d1117;
672
+ border: 1px solid #21262d;
673
  border-radius: 8px;
674
  overflow: hidden;
675
+ margin: 16px 0;
676
  }
677
  .code-block pre {
678
+ padding: 20px 24px;
679
+ font-family: "JetBrains Mono", monospace;
680
  font-size: 12px;
681
+ color: #8b949e;
682
+ line-height: 1.75;
683
  white-space: pre;
684
  overflow-x: auto;
685
+ margin: 0;
686
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
687
 
688
+ /* Footer */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
689
  .footer {
690
  margin-top: 48px;
691
+ padding: 20px 32px;
692
+ border-top: 1px solid #1a1a1a;
 
693
  font-size: 12px;
694
+ color: #3a3a3a;
695
+ line-height: 1.9;
696
  }
697
+ .footer a { color: #555; text-decoration: none; }
698
  .footer a:hover { color: #00d084; }
699
  """
700
 
701
+ # ---------------------------------------------------------------------------
702
+ # Static HTML sections
703
+ # ---------------------------------------------------------------------------
704
+
705
+ def _hero_html() -> str:
706
+ desc = (
707
+ "A 3-phase Markov Decision Process where LLM agents triage, route, and resolve "
708
+ "customer support tickets across a structured action space β€” classify, assign, respond, "
709
+ "refund, escalate. Covers e-commerce and SaaS BPO workflows across 3 difficulty tiers. "
710
+ "Deterministic per-phase reward shaping. Parameter-randomized ticket selection prevents "
711
+ "memorization β€” agents must learn the decision pattern, not specific tickets."
712
+ )
713
+ return f"""
714
  <div class='hero'>
715
+ <div class='hero-title'>Customer Support Agent</div>
716
+ <div class='hero-desc'>{desc}</div>
717
+ <div class='stat-grid'>
718
+ <div class='stat-card'><div class='sc-label'>Tickets</div><div class='sc-num'>15</div></div>
719
+ <div class='stat-card'><div class='sc-label'>Tiers</div><div class='sc-num'>3</div></div>
720
+ <div class='stat-card'><div class='sc-label'>Phases</div><div class='sc-num'>3</div></div>
721
+ <div class='stat-card'><div class='sc-label'>Teams</div><div class='sc-num'>6</div></div>
722
+ <div class='stat-card'><div class='sc-label'>Max Steps</div><div class='sc-num'>5</div></div>
723
+ <div class='stat-card'><div class='sc-label'>Reward</div><div class='sc-num sm'>[0.002, 0.998]</div></div>
724
  </div>
725
+ </div>"""
726
+
727
+
728
+ def _overview_html() -> str:
729
+ cards = [
730
+ ("zap", "3-Phase MDP, Not a Bandit",
731
+ "Every ticket runs Triage β†’ Route β†’ Resolve with state evolving between steps. "
732
+ "The agent makes 3 sequential decisions per episode β€” a proper Markov Decision "
733
+ "Process, not a single-shot classification task."),
734
+ ("layers", "Dense Per-Phase Rewards",
735
+ "Intermediate reward at every phase. No sparse end-of-episode signal. "
736
+ "Phase 1 binary (classify or not), Phase 2 graded by team accuracy, "
737
+ "Phase 3 proportional quality scoring across action + team + keyword coverage."),
738
+ ("git", "Evolving Observation State",
739
+ "After Phase 1, issue_type updates from 'unknown' to the true category. "
740
+ "After Phase 2, the assigned team appears in history. The agent sees richer "
741
+ "context at each step β€” state transitions are real, not simulated."),
742
+ ("scale", "Asymmetric Business Penalties",
743
+ "Refund (βˆ’0.50) > Escalation (βˆ’0.30) > Wrong Team (βˆ’0.15). "
744
+ "Mirrors actual BPO cost: an unwarranted refund is immediate financial loss, "
745
+ "a false escalation wastes senior time, wrong routing is recoverable."),
746
+ ("bar", "Proportional Normalization",
747
+ "Phase 3 scores normalize raw_score / max_possible. A simple ticket needing "
748
+ "only classify can still achieve 0.998 without being penalized for omitting "
749
+ "team or response components it never required."),
750
+ ("lock", "Deterministic Grader",
751
+ "Same action + same ticket = same reward. No stochasticity in the grader. "
752
+ "Reproducible RL training and evaluation without environment noise "
753
+ "contaminating the reward signal across runs."),
754
+ ]
755
+ grid = "".join(
756
+ f"<div class='unique-card'>{_icon_box(_ICONS[icon])}"
757
+ f"<div class='uc-title'>{title}</div><div class='uc-body'>{body}</div></div>"
758
+ for icon, title, body in cards
759
+ )
760
+ arch = """<div class='code-block'><pre>Episode Flow β€” 3 sequential steps per ticket:
761
+
762
+ reset() β†’ Observation { issue_type: "unknown", sentiment, priority, message }
763
+
764
+ step({"action_type": "classify"}) ← Phase 1: Triage
765
+ reward: 0.998 (correct) | 0.002 (wrong)
766
+ effect: issue_type revealed in next observation
767
+
768
+ step({"action_type": "assign", "team": "…"}) ← Phase 2: Route
769
+ reward: 0.998 (correct team) | 0.400 (wrong team) | 0.002 (wrong action)
770
+ effect: team context appended to history
771
+
772
+ step({"action_type": "respond|refund|escalate"}) ← Phase 3: Resolve
773
+ reward: proportional quality score in [0.002, 0.998]
774
+ effect: done = True
775
+
776
+ episode_score = mean(r1, r2, r3)</pre></div>"""
777
+ return f"""
778
+ <h2 class='section-h'>What makes this unique</h2>
779
+ <p class='section-sub'>Six design decisions that differentiate this environment from single-step LLM evaluation benchmarks.</p>
780
+ <div class='unique-grid'>{grid}</div>
781
+ <h2 class='section-h' style='margin-top:40px'>Episode Architecture</h2>
782
+ <p class='section-sub'>Each episode is a deterministic 3-step MDP. Observation state updates between phases.</p>
783
+ {arch}"""
784
+
785
+
786
+ def _scenarios_html() -> str:
787
+ out = ""
788
+ tier_meta = {
789
+ "easy": ("5 tickets", "respond, refund"),
790
+ "medium": ("5 tickets", "respond, escalate"),
791
+ "hard": ("5 tickets", "escalate, refund, respond"),
792
+ }
793
+ for tier in ["easy", "medium", "hard"]:
794
+ tc = _TIER_COLORS[tier]
795
+ tickets, actions = tier_meta[tier]
796
+ badge = _badge(tier, tc)
797
+ rows = ""
798
+ for sc in TASK_REGISTRY[tier]:
799
+ t = sc.ticket
800
+ gt = sc.ground_truth
801
+ sc_color = _ACTION_COLORS.get(gt.action_type, "#9ca3af")
802
+ sent_c = _SENT_COLORS.get(t.sentiment, "#9ca3af")
803
+ prio_c = _PRIO_COLORS.get(t.priority, "#9ca3af")
804
+ kws = " ".join(
805
+ f"<span class='kw-tag'>{_esc(k)}</span>"
806
+ for k in gt.response_keywords
807
+ ) if gt.response_keywords else "<span style='color:#333'>β€”</span>"
808
+ team_html = (
809
+ f"<code style='color:#ffa94d;font-size:11px'>{_esc(gt.team)}</code>"
810
+ if gt.team else "<span style='color:#333'>β€”</span>"
811
+ )
812
+ msg_short = t.message[:72] + "…" if len(t.message) > 72 else t.message
813
+ rows += f"""
814
+ <tr>
815
+ <td><code style='color:#666;font-size:11px'>{_esc(t.ticket_id)}</code></td>
816
+ <td><span style='color:{sent_c};font-weight:500'>{_esc(t.sentiment)}</span></td>
817
+ <td><span style='color:{prio_c};font-weight:500'>{_esc(t.priority)}</span></td>
818
+ <td class='msg-cell' title='{_esc(t.message)}'>&ldquo;{_esc(msg_short)}&rdquo;</td>
819
+ <td>{_badge(gt.action_type, sc_color, "11")}</td>
820
+ <td>{team_html}</td>
821
+ <td class='kw-cell'>{kws}</td>
822
+ </tr>"""
823
+ out += f"""
824
+ <div class='tier-section'>
825
+ <div class='tier-header-row'>
826
+ {badge}
827
+ <span class='tier-info'>{tickets} Β· Phase 3 actions: {actions}</span>
828
  </div>
829
+ <div class='table-wrap'>
830
+ <table class='data-table'>
831
+ <thead>
832
+ <tr>
833
+ <th>Ticket ID</th>
834
+ <th>Sentiment</th>
835
+ <th>Priority</th>
836
+ <th>Customer Message</th>
837
+ <th>Phase 3 Action</th>
838
+ <th>Target Team</th>
839
+ <th>Response Keywords</th>
840
+ </tr>
841
+ </thead>
842
+ <tbody>{rows}</tbody>
843
+ </table>
844
+ </div>
845
+ </div>"""
846
+ return f"""
847
+ <h2 class='section-h'>15 support tickets Β· 3 difficulty tiers</h2>
848
+ <p class='section-sub'>
849
+ Each scenario runs the full 3-phase MDP. Hover over a message cell to read the full text.
850
+ Phase 3 action and keywords are ground truth β€” the deterministic grader checks against these.
851
+ </p>
852
+ {out}"""
853
 
854
+
855
+ def _try_it_html() -> str:
856
+ m = _esc(MODEL_NAME)
857
+ return f"""
858
+ <h2 class='section-h'>Run the baseline yourself</h2>
859
+ <p class='section-sub'>
860
+ The validator runs <code style='color:#9ca3af;font-size:12px'>inference.py</code> and parses structured stdout logs.
861
+ Set the two required env vars and run:
862
+ </p>
863
+ <div class='code-block'><pre>export API_BASE_URL=https://your-llm-proxy/v1
864
+ export HF_TOKEN=your_token_here
865
+ export MODEL_NAME={m} # optional
866
+
867
+ python inference.py</pre></div>
868
+
869
+ <h2 class='section-h' style='margin-top:36px'>Expected output</h2>
870
+ <div class='code-block'><pre>[INFO] Using API_BASE_URL=https://... MODEL_NAME={m}
871
+
872
+ [START] task=easy env=support_env model={m}
873
+ [STEP] step=1 action={{"action_type":"classify"}} reward=1.00 done=false error=null
874
+ [STEP] step=2 action={{"action_type":"assign","team":"orders_team"}} reward=1.00 done=false error=null
875
+ [STEP] step=3 action={{"action_type":"respond","response":"..."}} reward=0.87 done=true error=null
876
+ [END] success=true steps=3 score=0.957 rewards=1.00,1.00,0.87
877
+
878
+ [START] task=medium ...
879
+ [START] task=hard ...</pre></div>
880
+
881
+ <h2 class='section-h' style='margin-top:36px'>Reward breakdown</h2>
882
+ <div class='table-wrap' style='border-radius:8px'>
883
+ <table class='data-table'>
884
+ <thead>
885
+ <tr>
886
+ <th>Phase</th>
887
+ <th>Correct</th>
888
+ <th>Wrong action type</th>
889
+ <th>Wrong team</th>
890
+ <th>Penalty</th>
891
+ </tr>
892
+ </thead>
893
+ <tbody>
894
+ <tr>
895
+ <td><span style='color:#60a5fa;font-weight:600'>Phase 1 β€” Triage</span></td>
896
+ <td><span style='color:#00d084;font-weight:700'>0.998</span></td>
897
+ <td><span style='color:#ff6b6b'>0.002</span></td>
898
+ <td><span style='color:#555'>n/a</span></td>
899
+ <td><span style='color:#555'>β€”</span></td>
900
+ </tr>
901
+ <tr>
902
+ <td><span style='color:#ffa94d;font-weight:600'>Phase 2 β€” Route</span></td>
903
+ <td><span style='color:#00d084;font-weight:700'>0.998</span></td>
904
+ <td><span style='color:#ff6b6b'>0.002</span></td>
905
+ <td><span style='color:#ffa94d'>0.400</span></td>
906
+ <td><span style='color:#555'>β€”</span></td>
907
+ </tr>
908
+ <tr>
909
+ <td><span style='color:#00d084;font-weight:600'>Phase 3 β€” Resolve</span></td>
910
+ <td><span style='color:#00d084;font-weight:700'>0.002 – 0.998</span></td>
911
+ <td><span style='color:#ff6b6b'>0.002</span></td>
912
+ <td><span style='color:#ff6b6b'>βˆ’0.15</span></td>
913
+ <td><span style='color:#ff6b6b'>refund βˆ’0.50 Β· escalate βˆ’0.30</span></td>
914
+ </tr>
915
+ <tr style='background:#0d0d0d;font-weight:600'>
916
+ <td style='color:#888'>Episode Score</td>
917
+ <td colspan='4' style='color:#888'>mean(phase1, phase2, phase3) Β· clamped to [0.002, 0.998]</td>
918
+ </tr>
919
+ </tbody>
920
+ </table>
921
+ </div>"""
922
+
923
+ # ---------------------------------------------------------------------------
924
+ # Playground HTML renderers
925
+ # ---------------------------------------------------------------------------
926
+
927
+ def _obs_html(obs_json: str) -> str:
928
+ if not obs_json:
929
+ return "<div class='empty-state'>Reset the environment to load a ticket.</div>"
930
+ try:
931
+ obs = json.loads(obs_json)
932
+ except Exception:
933
+ return f"<div class='empty-state'>β€”</div>"
934
+
935
+ def _val(key, val):
936
+ if key == "ticket_id":
937
+ return f"<code style='color:#888'>{_esc(val)}</code>"
938
+ if key == "issue_type":
939
+ if val == "unknown":
940
+ return f"<span style='color:#333;font-style:italic'>unknown</span>"
941
+ return f"<span style='color:#00d084;font-weight:600'>{_esc(val)}</span>"
942
+ if key == "sentiment":
943
+ c = _SENT_COLORS.get(val, "#9ca3af")
944
+ return f"<span style='color:{c};font-weight:500'>{_esc(val)}</span>"
945
+ if key == "priority":
946
+ c = _PRIO_COLORS.get(val, "#9ca3af")
947
+ return f"<span style='color:{c};font-weight:500'>{_esc(val)}</span>"
948
+ if key == "message":
949
+ return f"<span class='obs-message'>&ldquo;{_esc(val)}&rdquo;</span>"
950
+ return f"<span style='color:#aaa'>{_esc(str(val))}</span>"
951
+
952
+ rows = "".join(
953
+ f"<tr><td class='obs-key'>{key}</td><td class='obs-val'>{_val(key, obs.get(key,'β€”'))}</td></tr>"
954
+ for key in ["ticket_id", "issue_type", "sentiment", "priority", "message"]
955
+ )
956
+ history = obs.get("history", [])
957
+ if history:
958
+ hist_html = "".join(f"<div class='hist-mini'>{_esc(h)}</div>" for h in history[-5:])
959
+ rows += f"<tr><td class='obs-key'>history</td><td class='obs-val'>{hist_html}</td></tr>"
960
+
961
+ return f"""
962
+ <div class='pg-panel'>
963
+ <div class='pg-panel-head'>Current Ticket</div>
964
+ <div class='pg-panel-body'><table class='obs-table'><tbody>{rows}</tbody></table></div>
965
+ </div>"""
966
+
967
+
968
+ def _steps_html(steps: List[dict]) -> str:
969
+ if not steps:
970
+ return f"""
971
+ <div class='pg-panel'>
972
+ <div class='pg-panel-head'>Phase Steps</div>
973
+ <div class='pg-panel-body'><div class='empty-state'>No steps taken yet. Click Run Agent to start.</div></div>
974
+ </div>"""
975
+ rows = ""
976
+ for s in steps:
977
+ pc = _PHASE_COLORS.get(s["phase"], "#9ca3af")
978
+ sc = _score_color(s["score"])
979
+ ac = _ACTION_COLORS.get(s["action"], "#9ca3af")
980
+ err = f"<span style='color:#ff6b6b;font-size:10px'> ⚠</span>" if s.get("error") else ""
981
+ rows += f"""
982
+ <tr>
983
+ <td class='tc'><code style='color:#555'>{s["step"]}</code></td>
984
+ <td><span style='color:{pc};font-weight:600;font-size:11px'>{_esc(s["phase_name"])}</span></td>
985
+ <td>{_badge(s["action"], ac, "11")}</td>
986
+ <td><code style='color:#ffa94d;font-size:11px'>{_esc(s["team"])}</code></td>
987
+ <td class='tr'><span style='color:{sc};font-weight:700'>{s["score"]:.3f}</span>{err}</td>
988
+ </tr>"""
989
+ return f"""
990
+ <div class='pg-panel'>
991
+ <div class='pg-panel-head'>Phase Steps</div>
992
+ <div class='pg-panel-body'>
993
+ <table class='data-table'>
994
+ <thead><tr><th class='tc'>Step</th><th>Phase</th><th>Action</th><th>Team Routed</th><th class='tr'>Score</th></tr></thead>
995
+ <tbody>{rows}</tbody>
996
+ </table>
997
+ </div>
998
+ </div>"""
999
+
1000
+
1001
+ def _score_html(rewards: List[float], avg: float, done: bool) -> str:
1002
+ if not rewards:
1003
+ return f"""
1004
+ <div class='pg-panel'>
1005
+ <div class='pg-panel-head'>Episode Score</div>
1006
+ <div class='pg-panel-body'><div class='empty-state'>No scores yet.</div></div>
1007
+ </div>"""
1008
+ ac = _score_color(avg)
1009
+ dc = "#00d084" if done else "#ffa94d"
1010
+ pills = "".join(
1011
+ f"<span class='score-pill' style='background:{_score_color(r)}1a;color:{_score_color(r)};border:1px solid {_score_color(r)}44'>{r:.3f}</span>"
1012
+ for r in rewards
1013
+ )
1014
+ return f"""
1015
+ <div class='metrics-bar'>
1016
+ <div class='metric-cell'><div class='metric-label'>Avg Score</div>
1017
+ <div class='metric-val' style='color:{ac}'>{avg:.3f}</div></div>
1018
+ <div class='metric-cell'><div class='metric-label'>Steps</div>
1019
+ <div class='metric-val'>{len(rewards)}</div></div>
1020
+ <div class='metric-cell'><div class='metric-label'>Done</div>
1021
+ <div class='metric-val sm' style='color:{dc}'>{str(done).lower()}</div></div>
1022
+ <div class='metric-cell'><div class='metric-label'>Per-Phase</div>
1023
+ <div style='padding-top:6px'>{pills}</div></div>
1024
+ </div>"""
1025
+
1026
+
1027
+ def _team_html(team_lines: List[str]) -> str:
1028
+ if not team_lines:
1029
+ return f"""
1030
+ <div class='pg-panel'>
1031
+ <div class='pg-panel-head'>Team Assignment</div>
1032
+ <div class='pg-panel-body'><div class='empty-state'>No team assigned yet.</div></div>
1033
+ </div>"""
1034
+ ICONS_MAP = {
1035
+ "logistics_team": "🚚", "tech_support_team": "πŸ› ",
1036
+ "safety_team": "⚠️", "finance_team": "πŸ’³",
1037
+ "orders_team": "πŸ“¦", "management_team": "πŸ‘”",
1038
+ }
1039
+ cards = ""
1040
+ for line in team_lines:
1041
+ # line format: "[TKT-XXX] Team Name β€” subtitle"
1042
+ parts = line.split(" ", 1)
1043
+ tid_str = parts[0] if parts else line
1044
+ rest = parts[1] if len(parts) > 1 else ""
1045
+ # find which team key matches
1046
+ matched_key = next((k for k in _TEAM_NAMES if _TEAM_NAMES[k] in rest), None)
1047
+ icon = ICONS_MAP.get(matched_key, "πŸ“‹")
1048
+ name = _TEAM_NAMES.get(matched_key, rest.split(" β€” ")[0]) if matched_key else rest.split(" β€” ")[0]
1049
+ sub = _TEAM_SUBTITLES.get(matched_key, rest.split(" β€” ", 1)[1] if " β€” " in rest else "")
1050
+ cards += f"""
1051
+ <div class='team-card'>
1052
+ <div class='team-icon'>{icon}</div>
1053
+ <div>
1054
+ <div class='team-name'>{_esc(name)}</div>
1055
+ <div class='team-sub'><code style='font-size:11px;color:#444'>{_esc(tid_str)}</code> Β· {_esc(sub)}</div>
1056
+ </div>
1057
+ </div>"""
1058
+ return f"""
1059
+ <div class='pg-panel'>
1060
+ <div class='pg-panel-head'>Team Assignment</div>
1061
+ <div class='pg-panel-body' style='padding:12px'>{cards}</div>
1062
+ </div>"""
1063
+
1064
+
1065
+ def _msg_html(msg: str) -> str:
1066
+ if not msg:
1067
+ return f"""
1068
+ <div class='pg-panel'>
1069
+ <div class='pg-panel-head'>Agent Response</div>
1070
+ <div class='pg-panel-body'><div class='empty-state'>No customer-facing message (triage or route phase).</div></div>
1071
+ </div>"""
1072
+ return f"""
1073
+ <div class='pg-panel'>
1074
+ <div class='pg-panel-head'>Agent Response</div>
1075
+ <div class='pg-panel-body' style='padding:16px'>
1076
+ <div class='agent-response'>{_esc(msg)}</div>
1077
+ </div>
1078
+ </div>"""
1079
+
1080
+
1081
+ def _history_html() -> str:
1082
+ if not env.history:
1083
+ return f"""
1084
+ <div class='pg-panel'>
1085
+ <div class='pg-panel-head'>Action History</div>
1086
+ <div class='pg-panel-body'><div class='empty-state'>History will appear here after reset.</div></div>
1087
+ </div>"""
1088
+ rows = ""
1089
+ for entry in env.history:
1090
+ is_sys = entry.startswith("System:") or entry.startswith("Customer:")
1091
+ cl = "#1f1f1f" if is_sys else "#60a5fa0d"
1092
+ bl = "#2a2a2a" if is_sys else "#60a5fa"
1093
+ fc = "#555" if is_sys else "#ccc"
1094
+ rows += f"<div style='padding:8px 16px;border-bottom:1px solid #1a1a1a;border-left:3px solid {bl};background:{cl};font-size:12px;color:{fc};line-height:1.5'>{_esc(entry)}</div>"
1095
+ return f"""
1096
+ <div class='pg-panel'>
1097
+ <div class='pg-panel-head'>Action History</div>
1098
+ <div class='pg-panel-body'>{rows}</div>
1099
+ </div>"""
1100
 
1101
  # ---------------------------------------------------------------------------
1102
+ # Gradio event handlers
1103
  # ---------------------------------------------------------------------------
1104
 
1105
  def ui_reset(task_choice: str):
1106
  global _agent_history
1107
  _agent_history = []
1108
+ task_name = {"Easy (Classification)": "easy", "Medium (Assignment)": "medium", "Hard (Full Resolution)": "hard"}.get(task_choice, "easy")
1109
  res = env.reset(task_name)
1110
  obs_json = res.observation.model_dump_json(indent=2)
1111
+ empty_score = "<div class='pg-panel'><div class='pg-panel-head'>Episode Score</div><div class='pg-panel-body'><div class='empty-state'>No scores yet.</div></div></div>"
1112
  return (
1113
  _obs_html(obs_json),
1114
  _msg_html(""),
1115
  _steps_html([]),
1116
+ empty_score,
1117
  _history_html(),
1118
  _team_html([]),
1119
  )
 
1126
  return (
1127
  _obs_html(env.get_current_observation().model_dump_json(indent=2)),
1128
  _msg_html(""),
1129
+ _steps_html([]),
1130
+ _score_html([], 0.0, True),
1131
  _history_html(),
1132
  _team_html([]),
1133
  )
1134
 
1135
+ all_steps: List[dict] = []
1136
+ all_rewards: List[float] = []
1137
  last_message = ""
1138
+ team_lines: List[str] = []
1139
 
1140
  for step_num in range(1, 6):
1141
  if env.done:
 
1155
  elif current_phase == 2:
1156
  action = Action(action_type="assign", team="management_team")
1157
  else:
1158
+ action = Action(action_type="respond", response="Thank you for contacting us. Our team will look into this shortly.")
1159
 
1160
  result = env.step(action)
1161
  reward = result.reward
 
1164
  _agent_history = env.history.copy()
1165
  all_rewards.append(reward)
1166
 
1167
+ all_steps.append({
1168
+ "step": step_num,
1169
+ "phase": current_phase,
1170
+ "phase_name": _PHASE_NAMES.get(current_phase, str(current_phase)),
1171
+ "action": action.action_type,
1172
+ "team": action.team or "β€”",
1173
+ "score": reward,
1174
+ "error": error_msg,
1175
+ })
1176
 
1177
  if action.team:
1178
+ name = _TEAM_NAMES.get(action.team, action.team)
1179
+ sub = _TEAM_SUBTITLES.get(action.team, "")
1180
  tid = obs.ticket_id if hasattr(obs, "ticket_id") else "?"
1181
+ team_lines.append(f"[{tid}] {name} β€” {sub}")
1182
 
1183
  if action.response:
1184
  last_message = action.response
 
1204
  return (
1205
  _obs_html(env.get_current_observation().model_dump_json(indent=2)),
1206
  _msg_html(""),
1207
+ _steps_html([]),
1208
+ _score_html([], 0.0, True),
1209
  _history_html(),
1210
  _team_html([]),
1211
  )
1212
 
1213
  try:
1214
+ current_phase = env.phase
1215
  action = Action(
1216
  action_type=a_type,
1217
  team=t_name or None,
 
1222
  done = result.done
1223
  _agent_history = env.history.copy()
1224
 
1225
+ steps = [{
1226
+ "step": env.step_count,
1227
+ "phase": current_phase,
1228
+ "phase_name": _PHASE_NAMES.get(current_phase, str(current_phase)),
1229
+ "action": a_type,
1230
+ "team": t_name or "β€”",
1231
+ "score": reward,
1232
+ "error": None,
1233
+ }]
1234
 
1235
  team_lines = []
1236
  if t_name:
1237
+ name = _TEAM_NAMES.get(t_name, t_name)
1238
+ sub = _TEAM_SUBTITLES.get(t_name, "")
1239
+ if env.current_scenario:
1240
+ tid = env.current_scenario.ticket.ticket_id
1241
+ else:
1242
+ tid = "?"
1243
+ team_lines.append(f"[{tid}] {name} β€” {sub}")
1244
 
1245
  return (
1246
  _obs_html(result.observation.model_dump_json(indent=2)),
1247
  _msg_html(resp_text or ""),
1248
+ _steps_html(steps),
1249
+ _score_html([reward], reward, done),
1250
  _history_html(),
1251
  _team_html(team_lines),
1252
  )
1253
 
1254
  except Exception as exc:
1255
+ err_html = f"<div style='padding:16px;color:#ff6b6b;font-size:13px'>Error: {_esc(str(exc))}</div>"
1256
  return (
1257
  _obs_html(env.get_current_observation().model_dump_json(indent=2)),
1258
  _msg_html(""),
1259
+ f"<div class='pg-panel'><div class='pg-panel-head'>Error</div><div class='pg-panel-body'>{err_html}</div></div>",
1260
+ "<div class='pg-panel'><div class='pg-panel-head'>Episode Score</div><div class='pg-panel-body'><div class='empty-state'>β€”</div></div></div>",
1261
  _history_html(),
1262
  _team_html([]),
1263
  )
 
1266
  # Gradio layout
1267
  # ---------------------------------------------------------------------------
1268
 
1269
+ TASK_CHOICES = ["Easy (Classification)", "Medium (Assignment)", "Hard (Full Resolution)"]
1270
+
1271
  with gr.Blocks(css=CSS, title="Customer Support Agent β€” OpenEnv") as demo:
1272
 
1273
+ gr.HTML(_hero_html())
1274
 
1275
  with gr.Tabs():
1276
 
1277
+ # ── Tab: Overview ─────────────────────────────────────────────
1278
  with gr.Tab("Overview"):
1279
  gr.HTML(_overview_html())
1280
 
1281
+ # ── Tab: Scenarios ────────────────────────────────────────────
1282
  with gr.Tab("Scenarios"):
 
 
1283
  gr.HTML(_scenarios_html())
1284
 
1285
+ # ── Tab: Playground ───────────────────────────────────────────
1286
  with gr.Tab("Playground"):
1287
+ gr.HTML("<h2 class='section-h'>Live interactive episode</h2><p class='section-sub'>Select a tier, reset the environment, then run the full 3-phase episode automatically or step through manually.</p>")
 
1288
 
1289
  with gr.Row():
1290
+ task_dd = gr.Dropdown(choices=TASK_CHOICES, value=TASK_CHOICES[0], label="Task Tier", scale=4)
1291
+ reset_btn = gr.Button("Reset Episode", variant="secondary", scale=1, min_width=140)
1292
+ auto_btn = gr.Button("Run Agent (Full Episode)", variant="primary", scale=2, min_width=200)
1293
 
1294
  with gr.Row():
1295
  with gr.Column(scale=1):
1296
+ obs_out = gr.HTML(_obs_html(""))
1297
+ hist_out = gr.HTML(_history_html())
 
 
 
1298
 
1299
  with gr.Column(scale=1):
1300
+ steps_out = gr.HTML(_steps_html([]))
1301
+ team_out = gr.HTML(_team_html([]))
1302
+ msg_out = gr.HTML(_msg_html(""))
 
 
 
 
 
1303
 
1304
+ score_out = gr.HTML("<div class='pg-panel'><div class='pg-panel-head'>Episode Score</div><div class='pg-panel-body'><div class='empty-state'>No scores yet.</div></div></div>")
 
1305
 
1306
+ with gr.Accordion("Manual Step Override", open=False):
1307
+ gr.HTML("<p style='font-size:12px;color:#555;padding:4px 0 12px'>Step through individual phases manually. Phase 1 requires classify, Phase 2 requires assign + team, Phase 3 requires respond/refund/escalate.</p>")
1308
  with gr.Row():
1309
+ act_type = gr.Dropdown(
1310
+ choices=["classify", "assign", "respond", "refund", "escalate"],
1311
+ value="classify", label="Action Type", scale=1,
1312
+ )
1313
+ act_team = gr.Textbox(label="Team (Phase 2 only)", scale=1, placeholder="e.g. tech_support_team")
1314
  with gr.Row():
1315
+ act_resp = gr.Textbox(label="Response Text (Phase 3 only)", lines=2, scale=3,
1316
+ placeholder="Write the customer-facing response here...")
1317
+ manual_btn = gr.Button("Submit Action", variant="primary", scale=1, min_width=140)
1318
 
1319
+ # ── Tab: Try It ────────────────────────────────────────────────
1320
  with gr.Tab("Try It"):
1321
  gr.HTML(_try_it_html())
1322
 
1323
+ gr.HTML("<div class='footer'>customer-support-agent · 3-phase MDP · 15 tickets · 6 specialist teams · deterministic grader · reward ∈ [0.002, 0.998]<br/><a href='https://github.com/AdityaK-labs/Support-Agent/tree/Tarun'>github</a> · <a href='https://huggingface.co/spaces/Tarun21W/MetaAI'>huggingface</a></div>")
1324
 
 
1325
  _outputs = [obs_out, msg_out, steps_out, score_out, hist_out, team_out]
1326
 
1327
+ reset_btn.click( ui_reset, inputs=[task_dd], outputs=_outputs)
1328
+ auto_btn.click( ui_auto_step, inputs=[], outputs=_outputs)
1329
+ manual_btn.click(ui_manual_step, inputs=[act_type, act_team, act_resp], outputs=_outputs)
1330
 
1331
  demo.queue()
1332
  app = gr.mount_gradio_app(app, demo, path="/")
server/app.py CHANGED
@@ -212,16 +212,16 @@ async def _call_llm(obs, history: List[str], phase: int = 1) -> dict:
212
  return json.loads(match.group(1))
213
 
214
  # ---------------------------------------------------------------------------
215
- # UI helpers & HTML renderers
216
  # ---------------------------------------------------------------------------
217
 
218
- TASK_MAP = {
219
- "Easy (Classification)": "easy",
220
- "Medium (Assignment)": "medium",
221
- "Hard (Full Resolution)": "hard",
222
- }
223
-
224
- TEAM_DESCRIPTIONS = {
225
  "logistics_team": "Logistics Team",
226
  "tech_support_team": "Tech Support Team",
227
  "safety_team": "Safety Team",
@@ -229,256 +229,57 @@ TEAM_DESCRIPTIONS = {
229
  "orders_team": "Orders Team",
230
  "management_team": "Management Team",
231
  }
232
-
233
- TEAM_SUBTITLES = {
234
  "logistics_team": "Shipping, delivery, lost packages",
235
  "tech_support_team": "Login, bugs, API errors, data loss",
236
  "safety_team": "Defects, overheating, recalls, hazards",
237
- "finance_team": "Invoices, billing, tax, payment issues",
238
  "orders_team": "Bulk orders, returns, subscriptions",
239
  "management_team": "Escalated complaints, manager requests",
240
  }
241
 
242
- _PHASE_COLORS = {1: "#60a5fa", 2: "#ffa94d", 3: "#00d084"}
243
- _PHASE_NAMES = {1: "Triage", 2: "Route", 3: "Resolve"}
244
- _TIER_COLORS = {"easy": "#00d084", "medium": "#ffa94d", "hard": "#ff6b6b"}
245
- _SENT_COLORS = {"positive": "#00d084", "neutral": "#9ca3af", "negative": "#ffa94d", "angry": "#ff6b6b"}
246
- _PRIO_COLORS = {"low": "#9ca3af", "medium": "#60a5fa", "high": "#ffa94d", "critical": "#ff6b6b"}
247
- _ACTION_COLORS = {"classify": "#60a5fa", "assign": "#ffa94d", "respond": "#00d084", "refund": "#c084fc", "escalate": "#ff6b6b"}
248
-
249
  _agent_history: List[str] = []
250
 
 
 
 
251
 
252
- def _esc(s: str) -> str:
253
  return str(s).replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
254
 
255
  def _score_color(s: float) -> str:
256
- if s >= 0.8: return "#00d084"
257
- if s >= 0.5: return "#ffa94d"
258
  return "#ff6b6b"
259
 
260
- def _badge(label: str, color: str) -> str:
261
  return (
262
- f"<span style='display:inline-block;padding:2px 9px;border-radius:4px;"
263
- f"background:{color}22;color:{color};border:1px solid {color}66;"
264
- f"font-size:11px;font-weight:600;font-family:JetBrains Mono,monospace;"
265
- f"letter-spacing:.4px;text-transform:uppercase'>{_esc(label)}</span>"
 
266
  )
267
 
268
-
269
- def _obs_html(obs_json: str) -> str:
270
- if not obs_json:
271
- return "<div class='pg-placeholder'>Reset to load a ticket.</div>"
272
- return f"<pre class='pg-code'>{_esc(obs_json)}</pre>"
273
-
274
-
275
- def _steps_html(steps: List[str]) -> str:
276
- if not steps:
277
- return "<div class='pg-placeholder'>No steps taken yet.</div>"
278
- rows = ""
279
- for s in steps:
280
- color = "#9ca3af"
281
- for p, c in _PHASE_COLORS.items():
282
- if f"Phase {p}:" in s:
283
- color = c
284
- break
285
- rows += f"<div class='trace-step' style='border-left:3px solid {color};background:{color}0d'><code>{_esc(s)}</code></div>"
286
- return f"<div class='trace-wrap'>{rows}</div>"
287
-
288
-
289
- def _score_html(rewards: List[float], avg: float, done: bool) -> str:
290
- if not rewards:
291
- return "<div class='pg-placeholder'>No scores yet.</div>"
292
- badges = " ".join(
293
- f"<span class='score-badge' style='background:{_score_color(r)}22;color:{_score_color(r)};border:1px solid {_score_color(r)}66'>{r:.3f}</span>"
294
- for r in rewards
295
  )
296
- ac = _score_color(avg)
297
- dc = "#00d084" if done else "#ffa94d"
298
- return f"""
299
- <div class='pg-status'>
300
- <div class='stat-item'><span class='stat-label'>Steps</span><span class='stat-val'>{len(rewards)}</span></div>
301
- <div class='stat-item'><span class='stat-label'>Per-Phase Rewards</span><span>{badges}</span></div>
302
- <div class='stat-item'><span class='stat-label'>Avg Score</span><span class='stat-val' style='color:{ac};font-size:18px'>{avg:.3f}</span></div>
303
- <div class='stat-item'><span class='stat-label'>Done</span><span class='stat-val' style='color:{dc}'>{str(done).lower()}</span></div>
304
- </div>"""
305
-
306
-
307
- def _team_html(team_lines: List[str]) -> str:
308
- if not team_lines:
309
- return "<div class='pg-placeholder'>(no team assigned β€” triage or respond action)</div>"
310
- rows = ""
311
- for line in team_lines:
312
- # parse "[TKT-XXX] Team Name β€” subtitle"
313
- rows += f"<div class='team-row'><code>{_esc(line)}</code></div>"
314
- return f"<div class='team-wrap'>{rows}</div>"
315
-
316
-
317
- def _history_html() -> str:
318
- if not env.history:
319
- return "<div class='pg-placeholder'>(empty)</div>"
320
- rows = ""
321
- for entry in env.history:
322
- if entry.startswith("System:") or entry.startswith("Customer:"):
323
- cls = "hist-system"
324
- else:
325
- cls = "hist-agent"
326
- rows += f"<div class='hist-row {cls}'>{_esc(entry)}</div>"
327
- return f"<div class='hist-wrap'>{rows}</div>"
328
-
329
-
330
- def _msg_html(msg: str) -> str:
331
- if not msg:
332
- return "<div class='pg-placeholder'>(no customer-facing message β€” triage or route phase)</div>"
333
- return f"<div class='agent-msg'>{_esc(msg)}</div>"
334
-
335
-
336
- def _manual_score_html(reward: float, done: bool, feedback: str) -> str:
337
- c = _score_color(reward)
338
- dc = "#00d084" if done else "#ffa94d"
339
- fb = feedback[:300] + "..." if len(feedback) > 300 else feedback
340
- return f"""
341
- <div class='pg-status'>
342
- <div class='stat-item'><span class='stat-label'>Score</span><span class='stat-val' style='color:{c};font-size:18px'>{reward:.3f}</span></div>
343
- <div class='stat-item'><span class='stat-label'>Done</span><span class='stat-val' style='color:{dc}'>{str(done).lower()}</span></div>
344
- <div class='stat-item' style='flex:2'><span class='stat-label'>Grader Feedback</span><code style='font-size:11px;color:#9ca3af'>{_esc(fb)}</code></div>
345
- </div>"""
346
-
347
- # ---------------------------------------------------------------------------
348
- # Static HTML content sections
349
- # ---------------------------------------------------------------------------
350
-
351
- def _overview_html() -> str:
352
- cards = [
353
- ("⚑", "3-Phase MDP", "Not a bandit. Every ticket runs through Triage β†’ Route β†’ Resolve with state evolving between steps β€” a proper sequential decision problem."),
354
- ("🎯", "Dense Rewards", "Every phase returns an intermediate reward. No sparse end-of-episode signal. Phase 1 binary, Phase 2 graded, Phase 3 quality-scored."),
355
- ("πŸ”€", "State Transitions", "After Phase 1 the observation's issue_type updates from 'unknown' to the true category. After Phase 2 the assigned team appears in history. The agent sees richer context at each step."),
356
- ("βš–οΈ", "Asymmetric Penalties", "Refund (-0.50) > Escalation (-0.30) > Wrong Team (-0.15). Mirrors real business cost: an unwarranted refund is immediate financial loss."),
357
- ("πŸ“Š", "Proportional Scoring", "Phase 3 normalizes raw_score / max_possible so a simple ticket can still score 0.998 without being penalized for omitting components it never needed."),
358
- ("πŸ”’", "Deterministic Grader", "Same action + same ticket = same reward. No stochasticity in the grader. Reproducible RL training and evaluation."),
359
- ]
360
- grid = ""
361
- for icon, title, body in cards:
362
- grid += f"""
363
- <div class='unique-card'>
364
- <div class='card-icon'>{icon}</div>
365
- <div class='card-title'>{title}</div>
366
- <div class='card-body'>{body}</div>
367
- </div>"""
368
- arch = """
369
- <div class='arch-box'>
370
- <pre class='pg-code' style='margin:0'>Episode Flow (3 steps per ticket):
371
-
372
- reset()
373
- └─▢ Observation {issue_type: "unknown", sentiment, priority, message}
374
-
375
- step({"action_type": "classify"}) ← Phase 1: Triage
376
- └─▢ issue_type revealed in observation
377
- └─▢ reward: 0.998 (correct) or 0.002
378
-
379
- step({"action_type": "assign", "team": …}) ← Phase 2: Route
380
- └─▢ team context appended to history
381
- └─▢ reward: 0.998 / 0.400 / 0.002
382
-
383
- step({"action_type": "respond/refund/escalate", …}) ← Phase 3: Resolve
384
- └─▢ done = True
385
- └─▢ reward: proportional quality score in [0.002, 0.998]
386
-
387
- episode_score = mean(phase1_reward, phase2_reward, phase3_reward)</pre>
388
- </div>"""
389
- return f"""
390
- <h2 class='section-h'>What makes this a real RL environment</h2>
391
- <p class='section-sub'>Six design decisions that distinguish this from single-step LLM evaluation benchmarks.</p>
392
- <div class='unique-grid'>{grid}</div>
393
- <h2 class='section-h' style='margin-top:40px'>Episode Architecture</h2>
394
- <p class='section-sub'>Each episode is a deterministic 3-step MDP. Observation state updates between steps.</p>
395
- {arch}"""
396
-
397
-
398
- def _scenarios_html() -> str:
399
- out = ""
400
- for tier in ["easy", "medium", "hard"]:
401
- scenarios = TASK_REGISTRY[tier]
402
- tc = _TIER_COLORS[tier]
403
- out += f"<h3 class='tier-header' style='color:{tc}'>{tier.upper()} TIER β€” {len(scenarios)} scenarios</h3>"
404
- for sc in scenarios:
405
- t = sc.ticket
406
- gt = sc.ground_truth
407
- sc_color = _ACTION_COLORS.get(gt.action_type, "#9ca3af")
408
- sent_c = _SENT_COLORS.get(t.sentiment, "#9ca3af")
409
- prio_c = _PRIO_COLORS.get(t.priority, "#9ca3af")
410
- kw_html = " ".join(
411
- f"<code class='kw-tag'>{_esc(k)}</code>"
412
- for k in gt.response_keywords
413
- ) if gt.response_keywords else "<span class='muted'>none</span>"
414
- team_html = (
415
- f"<code style='color:#ffa94d'>{_esc(gt.team)}</code>"
416
- if gt.team else "<span class='muted'>β€”</span>"
417
- )
418
- out += f"""
419
- <div class='scen-card'>
420
- <div class='scen-header'>
421
- {_badge(tier, tc)}
422
- {_badge(t.sentiment, sent_c)}
423
- {_badge(t.priority, prio_c)}
424
- <code class='ticket-id'>{_esc(t.ticket_id)}</code>
425
- </div>
426
- <div class='scen-message'>&ldquo;{_esc(t.message)}&rdquo;</div>
427
- <div class='scen-meta'>
428
- <div class='meta-item'>
429
- <span class='meta-label'>Phase 3 Action</span>
430
- <span>{_badge(gt.action_type, sc_color)}</span>
431
- </div>
432
- <div class='meta-item'>
433
- <span class='meta-label'>Target Team</span>
434
- <span>{team_html}</span>
435
- </div>
436
- <div class='meta-item'>
437
- <span class='meta-label'>Response Keywords</span>
438
- <span>{kw_html}</span>
439
- </div>
440
- </div>
441
- </div>"""
442
- return out
443
 
444
-
445
- def _try_it_html() -> str:
446
- model = _esc(MODEL_NAME)
447
- return f"""
448
- <h2 class='section-h'>Run the baseline yourself</h2>
449
- <p class='section-sub'>The validator runs <code>inference.py</code> and parses structured stdout logs. Reproduce it locally with:</p>
450
- <div class='code-block'>
451
- <pre># Set environment variables
452
- export API_BASE_URL=https://your-llm-proxy/v1
453
- export HF_TOKEN=your_token_here
454
- export MODEL_NAME={model}
455
-
456
- # Run all 3 tasks (easy / medium / hard)
457
- python inference.py</pre>
458
- </div>
459
- <h3 class='section-h' style='margin-top:32px'>Expected output format</h3>
460
- <div class='code-block'>
461
- <pre>[INFO] Using API_BASE_URL=https://... MODEL_NAME={model}
462
-
463
- [START] task=easy env=support_env model={model}
464
- [STEP] step=1 action={{"action_type":"classify"}} reward=1.00 done=false error=null
465
- [STEP] step=2 action={{"action_type":"assign","team":"orders_team"}} reward=1.00 done=false error=null
466
- [STEP] step=3 action={{"action_type":"respond","response":"..."}} reward=0.87 done=true error=null
467
- [END] success=true steps=3 score=0.957 rewards=1.00,1.00,0.87
468
-
469
- [START] task=medium env=support_env model={model}
470
- ...
471
- [START] task=hard env=support_env model={model}
472
- ...</pre>
473
- </div>
474
- <h3 class='section-h' style='margin-top:32px'>Reward scoring summary</h3>
475
- <div class='scoring-grid'>
476
- <div class='scoring-row header'><span>Phase</span><span>Correct</span><span>Wrong</span></div>
477
- <div class='scoring-row'><span style='color:#60a5fa'>Phase 1 β€” Triage</span><span style='color:#00d084'>0.998</span><span style='color:#ff6b6b'>0.002</span></div>
478
- <div class='scoring-row'><span style='color:#ffa94d'>Phase 2 β€” Route</span><span style='color:#00d084'>0.998</span><span style='color:#ffa94d'>0.400 (wrong team)</span></div>
479
- <div class='scoring-row'><span style='color:#00d084'>Phase 3 β€” Resolve</span><span style='color:#00d084'>0.002 – 0.998</span><span style='color:#ff6b6b'>penalties apply</span></div>
480
- </div>
481
- <p class='muted' style='margin-top:16px;font-size:12px'>All scores clamped to [0.002, 0.998]. Episode score = mean of all step rewards.</p>"""
482
 
483
  # ---------------------------------------------------------------------------
484
  # CSS
@@ -487,321 +288,832 @@ python inference.py</pre>
487
  CSS = """
488
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');
489
 
490
- *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
 
491
 
492
  .gradio-container {
493
- background: #0a0a0a !important;
494
- color: #ededed !important;
495
- font-family: Inter, system-ui, sans-serif !important;
496
  max-width: 100% !important;
497
- padding: 0 28px 32px !important;
 
498
  }
 
499
 
500
- /* ── Tabs ─────────────────────────────────────────────────────────── */
501
- .tab-nav button {
 
 
502
  background: transparent !important;
503
- color: #9ca3af !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
504
  border: none !important;
505
  border-bottom: 2px solid transparent !important;
506
  font-family: Inter, sans-serif !important;
507
  font-size: 13px !important;
508
  font-weight: 500 !important;
509
- padding: 10px 18px !important;
 
 
510
  transition: color .15s, border-color .15s !important;
 
511
  }
512
- .tab-nav button:hover { color: #ededed !important; }
513
- .tab-nav button.selected {
514
  color: #00d084 !important;
515
  border-bottom-color: #00d084 !important;
516
  }
517
- .tabitem { background: transparent !important; border: none !important; padding: 24px 0 0 !important; }
 
 
 
 
518
 
519
- /* ── Hero bar ─────────────────────────────────────────────────────── */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
520
  .hero {
521
- display: flex;
522
- gap: 32px;
523
- align-items: center;
524
- padding: 28px 32px;
525
  background: #141414;
526
- border: 1px solid #262626;
527
- border-radius: 10px;
528
- margin-bottom: 28px;
529
- flex-wrap: wrap;
530
- }
531
- .hero-title { flex: 1; }
532
- .hero-title h1 { font-size: 22px; font-weight: 700; color: #ededed; line-height: 1.3; }
533
- .hero-title p { font-size: 13px; color: #9ca3af; margin-top: 4px; }
534
- .hero-stats { display: flex; gap: 28px; flex-wrap: wrap; }
535
- .stat-pill {
536
- display: flex; flex-direction: column; align-items: center;
537
- padding: 8px 18px;
538
- background: #0a0a0a;
539
- border: 1px solid #262626;
 
 
 
 
 
 
 
 
 
 
 
 
540
  border-radius: 8px;
541
- min-width: 80px;
542
  }
543
- .stat-pill .num { font-size: 22px; font-weight: 700; color: #00d084; font-family: JetBrains Mono, monospace; }
544
- .stat-pill .lbl { font-size: 11px; color: #9ca3af; margin-top: 2px; text-transform: uppercase; letter-spacing: .5px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
545
 
546
  /* ── Section typography ───────────────────────────────────────────── */
547
- .section-h { font-size: 17px; font-weight: 600; color: #ededed; margin: 28px 0 8px; }
548
- .section-sub { font-size: 13px; color: #9ca3af; margin-bottom: 20px; line-height: 1.6; }
549
- .muted { color: #9ca3af; }
550
- .tier-header { font-size: 13px; font-weight: 600; letter-spacing: 1px; margin: 28px 0 12px; font-family: JetBrains Mono, monospace; }
551
 
552
- /* ── Unique cards grid ────────────────────────────────────────────── */
553
  .unique-grid {
554
  display: grid;
555
- grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
556
- gap: 16px;
 
557
  }
558
  .unique-card {
559
  background: #141414;
560
- border: 1px solid #262626;
561
  border-radius: 10px;
562
- padding: 20px;
563
  transition: border-color .2s, transform .2s;
564
  }
565
- .unique-card:hover { border-color: #00d084; transform: translateY(-2px); }
566
- .card-icon { font-size: 24px; margin-bottom: 10px; }
567
- .card-title { font-size: 14px; font-weight: 600; color: #ededed; margin-bottom: 6px; }
568
- .card-body { font-size: 13px; color: #9ca3af; line-height: 1.6; }
569
-
570
- /* ── Architecture box ─────────────────────────────────────────────── */
571
- .arch-box { background: #141414; border: 1px solid #262626; border-radius: 10px; overflow: hidden; }
572
-
573
- /* ── Scenario cards ───────────────────────────────────────────────── */
574
- .scen-card {
575
- background: #141414;
576
- border: 1px solid #262626;
577
- border-radius: 10px;
578
- padding: 18px 20px;
579
- margin-bottom: 12px;
580
- transition: border-color .2s;
581
- }
582
- .scen-card:hover { border-color: #404040; }
583
- .scen-header { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
584
- .ticket-id { font-family: JetBrains Mono, monospace; font-size: 12px; color: #9ca3af; margin-left: auto; }
585
- .scen-message {
586
- font-size: 13px; color: #ededed; line-height: 1.6;
587
- border-left: 3px solid #00d08444;
588
- padding: 8px 14px;
589
- background: #0a0a0a;
590
- border-radius: 0 6px 6px 0;
591
- margin-bottom: 14px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
592
  font-style: italic;
593
  }
594
- .scen-meta { display: flex; gap: 20px; flex-wrap: wrap; }
595
- .meta-item { display: flex; flex-direction: column; gap: 4px; }
596
- .meta-label { font-size: 11px; color: #9ca3af; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
597
- .kw-tag {
598
- display: inline-block; padding: 1px 7px; border-radius: 4px;
599
- background: #1a1a1a; color: #9ca3af; border: 1px solid #333;
600
- font-size: 11px; font-family: JetBrains Mono, monospace; margin: 2px;
 
 
 
601
  }
602
 
603
- /* ── Playground ───────────────────────────────────────────────────── */
604
- .pg-placeholder { color: #5a5a5a; font-size: 13px; padding: 16px; font-style: italic; }
605
- .pg-code {
606
- background: #0a0a0a;
607
- border: 1px solid #262626;
608
- border-radius: 8px;
609
- padding: 16px;
610
- font-family: JetBrains Mono, monospace;
611
- font-size: 12px;
612
- color: #9ca3af;
613
- overflow-x: auto;
614
- white-space: pre;
615
- line-height: 1.6;
616
- }
617
- .pg-status {
618
  display: flex;
619
- gap: 0;
 
 
 
 
 
 
 
 
 
620
  background: #141414;
621
- border: 1px solid #262626;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
622
  border-radius: 8px;
623
  overflow: hidden;
624
  }
625
- .stat-item {
626
- display: flex; flex-direction: column; gap: 4px;
627
- padding: 14px 20px;
628
- border-right: 1px solid #262626;
629
- flex: 1;
630
- }
631
- .stat-item:last-child { border-right: none; }
632
- .stat-label { font-size: 11px; color: #9ca3af; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
633
- .stat-val { font-size: 15px; font-weight: 700; color: #ededed; font-family: JetBrains Mono, monospace; }
634
- .score-badge {
635
- display: inline-block; padding: 2px 9px; border-radius: 4px;
636
- font-size: 12px; font-weight: 600; font-family: JetBrains Mono, monospace;
637
- margin: 2px;
 
 
 
 
638
  }
639
 
640
- /* ── Trace steps ─────────────────────────────────────────────────── */
641
- .trace-wrap { display: flex; flex-direction: column; gap: 6px; }
642
- .trace-step {
643
- padding: 10px 14px;
644
- border-radius: 6px;
645
- font-size: 12px;
646
- line-height: 1.5;
 
 
 
647
  }
648
- .trace-step code { font-family: JetBrains Mono, monospace; color: #ededed; background: none; }
 
 
649
 
650
- /* ── Team assignment ─────────────────────────────────────────────── */
651
- .team-wrap { display: flex; flex-direction: column; gap: 6px; }
652
- .team-row {
653
- padding: 10px 14px;
 
 
 
654
  background: #141414;
655
- border: 1px solid #ffa94d33;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
656
  border-left: 3px solid #ffa94d;
 
 
 
 
 
 
 
657
  border-radius: 6px;
658
- font-size: 12px;
 
 
659
  }
660
- .team-row code { font-family: JetBrains Mono, monospace; color: #ffa94d; background: none; }
661
-
662
- /* ── History ─────────────────────────────────────────────────────── */
663
- .hist-wrap { display: flex; flex-direction: column; gap: 4px; }
664
- .hist-row { padding: 7px 12px; border-radius: 5px; font-size: 12px; line-height: 1.5; }
665
- .hist-agent { background: #60a5fa0d; border-left: 3px solid #60a5fa; color: #ededed; }
666
- .hist-system { background: #0a0a0a; border-left: 3px solid #333; color: #9ca3af; font-style: italic; }
667
 
668
- /* ── Agent message ───────────────────────────────────────────────── */
669
- .agent-msg {
 
670
  background: #141414;
671
- border: 1px solid #00d08433;
672
  border-left: 3px solid #00d084;
673
  border-radius: 8px;
674
- padding: 14px 18px;
675
  font-size: 13px;
676
- line-height: 1.7;
677
- color: #ededed;
 
678
  }
679
 
680
- /* ── Try It code blocks ──────────────────────────────────────────── */
681
  .code-block {
682
- background: #161b22;
683
- border: 1px solid #30363d;
684
  border-radius: 8px;
685
  overflow: hidden;
 
686
  }
687
  .code-block pre {
688
- padding: 18px 20px;
689
- font-family: JetBrains Mono, monospace;
690
  font-size: 12px;
691
- color: #9ca3af;
692
- line-height: 1.7;
693
  white-space: pre;
694
  overflow-x: auto;
 
695
  }
696
- .scoring-grid {
697
- background: #141414;
698
- border: 1px solid #262626;
699
- border-radius: 8px;
700
- overflow: hidden;
701
- }
702
- .scoring-row {
703
- display: grid;
704
- grid-template-columns: 1fr 1fr 1fr;
705
- padding: 10px 16px;
706
- border-bottom: 1px solid #1f1f1f;
707
- font-size: 13px;
708
- font-family: JetBrains Mono, monospace;
709
- }
710
- .scoring-row.header {
711
- background: #0a0a0a;
712
- font-size: 11px;
713
- text-transform: uppercase;
714
- letter-spacing: .5px;
715
- color: #5a5a5a;
716
- font-weight: 600;
717
- }
718
- .scoring-row:last-child { border-bottom: none; }
719
 
720
- /* ── Gradio component overrides ──────────────────────────────────── */
721
- .gradio-container label { color: #9ca3af !important; font-size: 12px !important; }
722
- .gradio-container input, .gradio-container select, .gradio-container textarea {
723
- background: #141414 !important;
724
- border-color: #262626 !important;
725
- color: #ededed !important;
726
- font-family: JetBrains Mono, monospace !important;
727
- font-size: 12px !important;
728
- }
729
- .gradio-container .gr-button-primary, button.primary {
730
- background: #00d084 !important;
731
- color: #0a0a0a !important;
732
- border: 1px solid #00a866 !important;
733
- font-weight: 600 !important;
734
- font-family: Inter, sans-serif !important;
735
- }
736
- .gradio-container .gr-button-primary:hover { background: #00b870 !important; }
737
- .gradio-container .gr-button-secondary, button.secondary {
738
- background: #141414 !important;
739
- color: #ededed !important;
740
- border: 1px solid #262626 !important;
741
- }
742
- .gradio-container .gr-button-secondary:hover { border-color: #404040 !important; }
743
- .gradio-container .gr-accordion {
744
- background: #141414 !important;
745
- border-color: #262626 !important;
746
- }
747
- .gradio-container .block.svelte-1gfkfd6 {
748
- background: transparent !important;
749
- border: none !important;
750
- }
751
-
752
- /* ── Footer ──────────────────────────────────────────────────────── */
753
  .footer {
754
  margin-top: 48px;
755
- padding-top: 20px;
756
- border-top: 1px solid #1f1f1f;
757
- text-align: center;
758
  font-size: 12px;
759
- color: #5a5a5a;
760
- line-height: 1.8;
761
  }
762
- .footer a { color: #9ca3af; text-decoration: none; }
763
  .footer a:hover { color: #00d084; }
764
  """
765
 
766
- HERO_HTML = """
 
 
 
 
 
 
 
 
 
 
 
 
767
  <div class='hero'>
768
- <div class='hero-title'>
769
- <h1>Customer Support Agent</h1>
770
- <p>OpenEnv-compliant autonomous BPO agent Β· Meta PyTorch Hackathon x Scaler</p>
 
 
 
 
 
 
771
  </div>
772
- <div class='hero-stats'>
773
- <div class='stat-pill'><span class='num'>15</span><span class='lbl'>Tickets</span></div>
774
- <div class='stat-pill'><span class='num'>3</span><span class='lbl'>Tiers</span></div>
775
- <div class='stat-pill'><span class='num'>3</span><span class='lbl'>Phases</span></div>
776
- <div class='stat-pill'><span class='num'>6</span><span class='lbl'>Teams</span></div>
777
- <div class='stat-pill'><span class='num'>5</span><span class='lbl'>Max Steps</span></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
778
  </div>
779
- </div>
780
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
781
 
782
- FOOTER_HTML = """
783
- <div class='footer'>
784
- customer-support-agent · 3-phase MDP · 15 tickets · 6 specialist teams · deterministic grader · reward ∈ [0.002, 0.998]<br/>
785
- <a href='https://github.com/AdityaK-labs/Support-Agent/tree/Tarun'>github</a> Β·
786
- <a href='https://huggingface.co/spaces/Tarun21W/MetaAI'>huggingface</a>
787
- </div>
788
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
789
 
790
  # ---------------------------------------------------------------------------
791
- # Gradio UI functions
792
  # ---------------------------------------------------------------------------
793
 
794
  def ui_reset(task_choice: str):
795
  global _agent_history
796
  _agent_history = []
797
- task_name = TASK_MAP.get(task_choice, "easy")
798
  res = env.reset(task_name)
799
  obs_json = res.observation.model_dump_json(indent=2)
 
800
  return (
801
  _obs_html(obs_json),
802
  _msg_html(""),
803
  _steps_html([]),
804
- "<div class='pg-placeholder'>No scores yet.</div>",
805
  _history_html(),
806
  _team_html([]),
807
  )
@@ -814,16 +1126,16 @@ async def ui_auto_step():
814
  return (
815
  _obs_html(env.get_current_observation().model_dump_json(indent=2)),
816
  _msg_html(""),
817
- "<div class='pg-placeholder'>Episode finished β€” please reset.</div>",
818
- "<div class='pg-placeholder'>Episode finished.</div>",
819
  _history_html(),
820
  _team_html([]),
821
  )
822
 
823
- all_steps = []
824
- all_rewards = []
825
  last_message = ""
826
- team_lines = []
827
 
828
  for step_num in range(1, 6):
829
  if env.done:
@@ -843,7 +1155,7 @@ async def ui_auto_step():
843
  elif current_phase == 2:
844
  action = Action(action_type="assign", team="management_team")
845
  else:
846
- action = Action(action_type="respond", response="Thank you for contacting us.")
847
 
848
  result = env.step(action)
849
  reward = result.reward
@@ -852,18 +1164,21 @@ async def ui_auto_step():
852
  _agent_history = env.history.copy()
853
  all_rewards.append(reward)
854
 
855
- phase_label = _PHASE_NAMES.get(current_phase, str(current_phase))
856
- step_line = f"[Phase {current_phase}: {phase_label}] step={step_num} {action.action_type}"
857
- if action.team: step_line += f" β†’ {action.team}"
858
- step_line += f" | score: {reward:.3f}"
859
- if error_msg: step_line += f" ⚠ {error_msg[:60]}"
860
- all_steps.append(step_line)
 
 
 
861
 
862
  if action.team:
863
- desc = TEAM_DESCRIPTIONS.get(action.team, action.team)
864
- sub = TEAM_SUBTITLES.get(action.team, "")
865
  tid = obs.ticket_id if hasattr(obs, "ticket_id") else "?"
866
- team_lines.append(f"[{tid}] {desc} β€” {sub}")
867
 
868
  if action.response:
869
  last_message = action.response
@@ -889,13 +1204,14 @@ def ui_manual_step(a_type: str, t_name: str, resp_text: str):
889
  return (
890
  _obs_html(env.get_current_observation().model_dump_json(indent=2)),
891
  _msg_html(""),
892
- "<div class='pg-placeholder'>Episode finished β€” please reset.</div>",
893
- "<div class='pg-placeholder'>Episode finished.</div>",
894
  _history_html(),
895
  _team_html([]),
896
  )
897
 
898
  try:
 
899
  action = Action(
900
  action_type=a_type,
901
  team=t_name or None,
@@ -906,33 +1222,42 @@ def ui_manual_step(a_type: str, t_name: str, resp_text: str):
906
  done = result.done
907
  _agent_history = env.history.copy()
908
 
909
- phase_num = result.info.get("phase", env.phase)
910
- phase_lbl = _PHASE_NAMES.get(phase_num - 1, str(phase_num - 1))
911
- step_line = f"[Phase {phase_num - 1}: {phase_lbl}] {a_type}"
912
- if t_name: step_line += f" β†’ {t_name}"
913
- step_line += f" | score: {reward:.3f}"
 
 
 
 
914
 
915
  team_lines = []
916
  if t_name:
917
- desc = TEAM_DESCRIPTIONS.get(t_name, t_name)
918
- sub = TEAM_SUBTITLES.get(t_name, "")
919
- team_lines.append(f"[{env.current_scenario.ticket.ticket_id}] {desc} β€” {sub}")
 
 
 
 
920
 
921
  return (
922
  _obs_html(result.observation.model_dump_json(indent=2)),
923
  _msg_html(resp_text or ""),
924
- _steps_html([step_line]),
925
- _manual_score_html(reward, done, result.info.get("feedback", "")),
926
  _history_html(),
927
  _team_html(team_lines),
928
  )
929
 
930
  except Exception as exc:
 
931
  return (
932
  _obs_html(env.get_current_observation().model_dump_json(indent=2)),
933
  _msg_html(""),
934
- f"<div class='pg-placeholder' style='color:#ff6b6b'>Error: {_esc(str(exc))}</div>",
935
- "<div class='pg-placeholder'>β€”</div>",
936
  _history_html(),
937
  _team_html([]),
938
  )
@@ -941,73 +1266,67 @@ def ui_manual_step(a_type: str, t_name: str, resp_text: str):
941
  # Gradio layout
942
  # ---------------------------------------------------------------------------
943
 
 
 
944
  with gr.Blocks(css=CSS, title="Customer Support Agent β€” OpenEnv") as demo:
945
 
946
- gr.HTML(HERO_HTML)
947
 
948
  with gr.Tabs():
949
 
950
- # ── Tab 1: Overview ───────────────────────────────────────────
951
  with gr.Tab("Overview"):
952
  gr.HTML(_overview_html())
953
 
954
- # ── Tab 2: Scenarios ──────────────────────────────────────────
955
  with gr.Tab("Scenarios"):
956
- gr.HTML(f"<h2 class='section-h'>15 support tickets Β· 3 difficulty tiers</h2>")
957
- gr.HTML(f"<p class='section-sub'>Each scenario runs the full 3-phase MDP. Phase 3 action and keywords shown are the ground truth the grader checks against.</p>")
958
  gr.HTML(_scenarios_html())
959
 
960
- # ── Tab 3: Playground ─────────────────────────────────────────
961
  with gr.Tab("Playground"):
962
- gr.HTML("<h2 class='section-h'>Live interactive episode</h2>")
963
- gr.HTML("<p class='section-sub'>Select a task tier, reset the environment, then run the full 3-phase episode automatically β€” or step through each phase manually.</p>")
964
 
965
  with gr.Row():
966
- task_dd = gr.Dropdown(choices=list(TASK_MAP.keys()), value="Easy (Classification)", label="Task Tier", scale=4)
967
- reset_btn = gr.Button("Reset Episode", variant="secondary", scale=1, min_width=140)
968
- auto_btn = gr.Button("Run Agent (Full Episode)", variant="primary", scale=2, min_width=200)
969
 
970
  with gr.Row():
971
  with gr.Column(scale=1):
972
- gr.HTML("<div class='section-h' style='margin:16px 0 8px'>Current Observation</div>")
973
- obs_out = gr.HTML(_obs_html(""), label="")
974
-
975
- gr.HTML("<div class='section-h' style='margin:16px 0 8px'>Action History</div>")
976
- hist_out = gr.HTML(_history_html(), label="")
977
 
978
  with gr.Column(scale=1):
979
- gr.HTML("<div class='section-h' style='margin:16px 0 8px'>Phase Steps</div>")
980
- steps_out = gr.HTML(_steps_html([]), label="")
981
-
982
- gr.HTML("<div class='section-h' style='margin:16px 0 8px'>Team Assignment</div>")
983
- team_out = gr.HTML(_team_html([]), label="")
984
-
985
- gr.HTML("<div class='section-h' style='margin:16px 0 8px'>Agent Response</div>")
986
- msg_out = gr.HTML(_msg_html(""), label="")
987
 
988
- gr.HTML("<div class='section-h' style='margin:16px 0 8px'>Score</div>")
989
- score_out = gr.HTML("<div class='pg-placeholder'>No scores yet.</div>", label="")
990
 
991
- with gr.Accordion("Manual Step (override agent)", open=False):
 
992
  with gr.Row():
993
- act_type = gr.Dropdown(choices=["classify","assign","respond","refund","escalate"], value="classify", label="Action Type", scale=1)
994
- act_team = gr.Textbox(label="Team (optional)", scale=1)
 
 
 
995
  with gr.Row():
996
- act_resp = gr.Textbox(label="Response text (optional)", lines=2, scale=3)
997
- manual_btn = gr.Button("Submit Manual Action", variant="primary", scale=1, min_width=160)
 
998
 
999
- # ── Tab 4: Try It ─────────────────────────────────────────────
1000
  with gr.Tab("Try It"):
1001
  gr.HTML(_try_it_html())
1002
 
1003
- gr.HTML(FOOTER_HTML)
1004
 
1005
- # ── Event wiring ─────────────────────────────────────────────────
1006
  _outputs = [obs_out, msg_out, steps_out, score_out, hist_out, team_out]
1007
 
1008
- reset_btn.click(ui_reset, inputs=[task_dd], outputs=_outputs)
1009
- auto_btn.click( ui_auto_step, inputs=[], outputs=_outputs)
1010
- manual_btn.click(ui_manual_step, inputs=[act_type, act_team, act_resp], outputs=_outputs)
1011
 
1012
  demo.queue()
1013
  app = gr.mount_gradio_app(app, demo, path="/")
 
212
  return json.loads(match.group(1))
213
 
214
  # ---------------------------------------------------------------------------
215
+ # Design tokens
216
  # ---------------------------------------------------------------------------
217
 
218
+ _PHASE_COLORS = {1: "#60a5fa", 2: "#ffa94d", 3: "#00d084"}
219
+ _PHASE_NAMES = {1: "Triage", 2: "Route", 3: "Resolve"}
220
+ _TIER_COLORS = {"easy": "#00d084", "medium": "#ffa94d", "hard": "#ff6b6b"}
221
+ _SENT_COLORS = {"positive": "#00d084", "neutral": "#9ca3af", "negative": "#ffa94d", "angry": "#ff6b6b"}
222
+ _PRIO_COLORS = {"low": "#9ca3af", "medium": "#60a5fa", "high": "#ffa94d", "critical": "#ff6b6b"}
223
+ _ACTION_COLORS = {"classify": "#60a5fa", "assign": "#ffa94d", "respond": "#00d084", "refund": "#c084fc", "escalate": "#ff6b6b"}
224
+ _TEAM_NAMES = {
225
  "logistics_team": "Logistics Team",
226
  "tech_support_team": "Tech Support Team",
227
  "safety_team": "Safety Team",
 
229
  "orders_team": "Orders Team",
230
  "management_team": "Management Team",
231
  }
232
+ _TEAM_SUBTITLES = {
 
233
  "logistics_team": "Shipping, delivery, lost packages",
234
  "tech_support_team": "Login, bugs, API errors, data loss",
235
  "safety_team": "Defects, overheating, recalls, hazards",
236
+ "finance_team": "Invoices, billing, tax, payments",
237
  "orders_team": "Bulk orders, returns, subscriptions",
238
  "management_team": "Escalated complaints, manager requests",
239
  }
240
 
 
 
 
 
 
 
 
241
  _agent_history: List[str] = []
242
 
243
+ # ---------------------------------------------------------------------------
244
+ # HTML utility helpers
245
+ # ---------------------------------------------------------------------------
246
 
247
+ def _esc(s) -> str:
248
  return str(s).replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
249
 
250
  def _score_color(s: float) -> str:
251
+ if s >= 0.80: return "#00d084"
252
+ if s >= 0.50: return "#ffa94d"
253
  return "#ff6b6b"
254
 
255
+ def _badge(label: str, color: str, size: str = "12") -> str:
256
  return (
257
+ f"<span style='display:inline-flex;align-items:center;padding:2px 9px;"
258
+ f"border-radius:4px;background:{color}1a;color:{color};"
259
+ f"border:1px solid {color}44;font-size:{size}px;font-weight:600;"
260
+ f"font-family:\"JetBrains Mono\",monospace;letter-spacing:.3px;"
261
+ f"text-transform:uppercase;line-height:1.6'>{_esc(label)}</span>"
262
  )
263
 
264
+ def _icon_box(svg_path: str) -> str:
265
+ return (
266
+ f"<div style='width:40px;height:40px;background:#0a2a1a;"
267
+ f"border:1px solid #1a4a2a;border-radius:8px;"
268
+ f"display:flex;align-items:center;justify-content:center;margin-bottom:14px;flex-shrink:0'>"
269
+ f"<svg width='18' height='18' viewBox='0 0 24 24' fill='none' "
270
+ f"stroke='#00d084' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'>"
271
+ f"{svg_path}</svg></div>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
 
274
+ # SVG icon paths (Lucide-style)
275
+ _ICONS = {
276
+ "zap": "<polygon points='13 2 3 14 12 14 11 22 21 10 12 10 13 2'/>",
277
+ "layers": "<polygon points='12 2 2 7 12 12 22 7 12 2'/><polyline points='2 17 12 22 22 17'/><polyline points='2 12 12 17 22 12'/>",
278
+ "git": "<line x1='6' y1='3' x2='6' y2='15'/><circle cx='18' cy='6' r='3'/><circle cx='6' cy='18' r='3'/><path d='M18 9a9 9 0 0 1-9 9'/>",
279
+ "scale": "<line x1='12' y1='3' x2='12' y2='21'/><path d='M3 9l4.5 9'/><path d='M21 9l-4.5 9'/><path d='M3 18a4.5 4.5 0 0 0 9 0'/><path d='M12 18a4.5 4.5 0 0 0 9 0'/>",
280
+ "bar": "<line x1='18' y1='20' x2='18' y2='10'/><line x1='12' y1='20' x2='12' y2='4'/><line x1='6' y1='20' x2='6' y2='14'/><line x1='2' y1='20' x2='22' y2='20'/>",
281
+ "lock": "<rect x='3' y='11' width='18' height='11' rx='2' ry='2'/><path d='M7 11V7a5 5 0 0 1 10 0v4'/>",
282
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
 
284
  # ---------------------------------------------------------------------------
285
  # CSS
 
288
  CSS = """
289
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');
290
 
291
+ /* ── Global reset ─────────────────────────────────────────────────── */
292
+ *, *::before, *::after { box-sizing: border-box; }
293
 
294
  .gradio-container {
295
+ background: #0d0d0d !important;
296
+ color: #e8e8e8 !important;
297
+ font-family: Inter, system-ui, -apple-system, sans-serif !important;
298
  max-width: 100% !important;
299
+ padding: 0 !important;
300
+ min-height: 100vh !important;
301
  }
302
+ .gradio-container > .main { padding: 0 32px 40px !important; }
303
 
304
+ /* ── Strip default Gradio chrome from HTML containers ────────────── */
305
+ .gradio-container .block,
306
+ .gradio-container .form,
307
+ .gradio-container .gap {
308
  background: transparent !important;
309
+ border: none !important;
310
+ box-shadow: none !important;
311
+ padding: 0 !important;
312
+ gap: 0 !important;
313
+ }
314
+ .gradio-container .wrap { border: none !important; }
315
+ .gradio-container .output-html { padding: 0 !important; }
316
+
317
+ /* ── Tab bar ──────────────────────────────────────────────────────── */
318
+ .gradio-container .tab-nav {
319
+ background: #0d0d0d !important;
320
+ border-bottom: 1px solid #1f1f1f !important;
321
+ padding: 0 32px !important;
322
+ gap: 0 !important;
323
+ }
324
+ .gradio-container .tab-nav button {
325
+ background: transparent !important;
326
+ color: #666 !important;
327
  border: none !important;
328
  border-bottom: 2px solid transparent !important;
329
  font-family: Inter, sans-serif !important;
330
  font-size: 13px !important;
331
  font-weight: 500 !important;
332
+ padding: 14px 20px !important;
333
+ margin: 0 !important;
334
+ border-radius: 0 !important;
335
  transition: color .15s, border-color .15s !important;
336
+ letter-spacing: .2px !important;
337
  }
338
+ .gradio-container .tab-nav button:hover { color: #ccc !important; }
339
+ .gradio-container .tab-nav button.selected {
340
  color: #00d084 !important;
341
  border-bottom-color: #00d084 !important;
342
  }
343
+ .gradio-container .tabitem {
344
+ background: transparent !important;
345
+ border: none !important;
346
+ padding: 32px 0 0 !important;
347
+ }
348
 
349
+ /* ── Gradio input component overrides ────────────────────────────── */
350
+ .gradio-container select,
351
+ .gradio-container input[type=text],
352
+ .gradio-container textarea {
353
+ background: #1a1a1a !important;
354
+ border: 1px solid #2a2a2a !important;
355
+ color: #e8e8e8 !important;
356
+ font-family: "JetBrains Mono", monospace !important;
357
+ font-size: 12px !important;
358
+ border-radius: 6px !important;
359
+ }
360
+ .gradio-container select:focus,
361
+ .gradio-container input:focus,
362
+ .gradio-container textarea:focus {
363
+ border-color: #00d084 !important;
364
+ outline: none !important;
365
+ box-shadow: 0 0 0 2px #00d08422 !important;
366
+ }
367
+ .gradio-container label span {
368
+ color: #666 !important;
369
+ font-size: 11px !important;
370
+ font-weight: 600 !important;
371
+ text-transform: uppercase !important;
372
+ letter-spacing: .6px !important;
373
+ font-family: Inter, sans-serif !important;
374
+ }
375
+ button.primary, .gradio-container button.primary {
376
+ background: #00d084 !important;
377
+ color: #0a0a0a !important;
378
+ border: 1px solid #00a866 !important;
379
+ border-radius: 6px !important;
380
+ font-family: Inter, sans-serif !important;
381
+ font-weight: 600 !important;
382
+ font-size: 13px !important;
383
+ transition: background .15s !important;
384
+ }
385
+ button.primary:hover { background: #00b870 !important; }
386
+ button.secondary, .gradio-container button.secondary {
387
+ background: #1a1a1a !important;
388
+ color: #ccc !important;
389
+ border: 1px solid #2a2a2a !important;
390
+ border-radius: 6px !important;
391
+ font-family: Inter, sans-serif !important;
392
+ font-weight: 500 !important;
393
+ font-size: 13px !important;
394
+ transition: border-color .15s !important;
395
+ }
396
+ button.secondary:hover { border-color: #444 !important; color: #e8e8e8 !important; }
397
+ .gradio-container .gr-accordion {
398
+ background: #141414 !important;
399
+ border: 1px solid #222 !important;
400
+ border-radius: 8px !important;
401
+ margin-top: 16px !important;
402
+ }
403
+ .gradio-container .gr-accordion > .label-wrap {
404
+ padding: 12px 16px !important;
405
+ color: #888 !important;
406
+ font-size: 12px !important;
407
+ font-weight: 600 !important;
408
+ text-transform: uppercase !important;
409
+ letter-spacing: .5px !important;
410
+ }
411
+
412
+ /* ── Hero ─────────────────────────────────────────────────────────── */
413
  .hero {
 
 
 
 
414
  background: #141414;
415
+ border-bottom: 1px solid #1f1f1f;
416
+ padding: 32px 32px 28px;
417
+ }
418
+ .hero-title {
419
+ font-size: 26px;
420
+ font-weight: 700;
421
+ color: #f0f0f0;
422
+ line-height: 1.2;
423
+ margin-bottom: 10px;
424
+ letter-spacing: -.3px;
425
+ }
426
+ .hero-desc {
427
+ font-size: 13px;
428
+ color: #666;
429
+ line-height: 1.75;
430
+ max-width: 860px;
431
+ }
432
+ .stat-grid {
433
+ display: grid;
434
+ grid-template-columns: repeat(6, 1fr);
435
+ gap: 10px;
436
+ margin-top: 24px;
437
+ }
438
+ .stat-card {
439
+ background: #0d0d0d;
440
+ border: 1px solid #1f1f1f;
441
  border-radius: 8px;
442
+ padding: 18px 16px 14px;
443
  }
444
+ .sc-label {
445
+ font-size: 10px;
446
+ font-weight: 600;
447
+ color: #444;
448
+ text-transform: uppercase;
449
+ letter-spacing: 1.2px;
450
+ margin-bottom: 10px;
451
+ }
452
+ .sc-num {
453
+ font-size: 38px;
454
+ font-weight: 700;
455
+ color: #e8e8e8;
456
+ font-family: "JetBrains Mono", monospace;
457
+ line-height: 1;
458
+ }
459
+ .sc-num.sm { font-size: 22px; padding-top: 8px; }
460
 
461
  /* ── Section typography ───────────────────────────────────────────── */
462
+ .section-h { font-size: 18px; font-weight: 600; color: #f0f0f0; margin: 0 0 8px; }
463
+ .section-sub { font-size: 13px; color: #666; margin-bottom: 28px; line-height: 1.6; }
 
 
464
 
465
+ /* ── Overview unique cards ────────────────────────────────────────── */
466
  .unique-grid {
467
  display: grid;
468
+ grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
469
+ gap: 14px;
470
+ margin-top: 4px;
471
  }
472
  .unique-card {
473
  background: #141414;
474
+ border: 1px solid #222;
475
  border-radius: 10px;
476
+ padding: 22px 22px 20px;
477
  transition: border-color .2s, transform .2s;
478
  }
479
+ .unique-card:hover { border-color: #00d08466; transform: translateY(-2px); }
480
+ .uc-title { font-size: 14px; font-weight: 600; color: #f0f0f0; margin-bottom: 8px; }
481
+ .uc-body { font-size: 13px; color: #777; line-height: 1.7; }
482
+
483
+ /* ── Data tables (shared) ─────────────────────────────────────────── */
484
+ .data-table {
485
+ width: 100%;
486
+ border-collapse: collapse;
487
+ font-size: 12px;
488
+ font-family: "JetBrains Mono", monospace;
489
+ }
490
+ .data-table thead tr {
491
+ background: #0d0d0d;
492
+ border-bottom: 2px solid #1f1f1f;
493
+ }
494
+ .data-table th {
495
+ padding: 10px 14px;
496
+ text-align: left;
497
+ font-size: 10px;
498
+ font-weight: 600;
499
+ color: #444;
500
+ text-transform: uppercase;
501
+ letter-spacing: 1px;
502
+ white-space: nowrap;
503
+ }
504
+ .data-table th.tc { text-align: center; }
505
+ .data-table th.tr { text-align: right; }
506
+ .data-table td {
507
+ padding: 11px 14px;
508
+ border-bottom: 1px solid #1a1a1a;
509
+ vertical-align: middle;
510
+ color: #ccc;
511
+ line-height: 1.5;
512
+ }
513
+ .data-table td.tc { text-align: center; }
514
+ .data-table td.tr { text-align: right; }
515
+ .data-table tbody tr:hover { background: #161616; }
516
+ .data-table tbody tr:last-child td { border-bottom: none; }
517
+ .msg-cell {
518
+ max-width: 320px;
519
+ overflow: hidden;
520
+ text-overflow: ellipsis;
521
+ white-space: nowrap;
522
+ color: #888;
523
  font-style: italic;
524
  }
525
+ .kw-cell { max-width: 240px; }
526
+ .kw-tag {
527
+ display: inline-block;
528
+ padding: 1px 6px;
529
+ border-radius: 3px;
530
+ background: #1f1f1f;
531
+ border: 1px solid #2a2a2a;
532
+ color: #777;
533
+ font-size: 10px;
534
+ margin: 1px;
535
  }
536
 
537
+ /* ── Tier section ─────────────────────────────────────────────────── */
538
+ .tier-section { margin-bottom: 32px; }
539
+ .tier-header-row {
 
 
 
 
 
 
 
 
 
 
 
 
540
  display: flex;
541
+ align-items: center;
542
+ gap: 12px;
543
+ padding: 14px 16px;
544
+ background: #111;
545
+ border: 1px solid #1f1f1f;
546
+ border-radius: 8px 8px 0 0;
547
+ border-bottom: none;
548
+ }
549
+ .tier-info { font-size: 12px; color: #555; font-family: "JetBrains Mono", monospace; }
550
+ .table-wrap {
551
  background: #141414;
552
+ border: 1px solid #1f1f1f;
553
+ border-radius: 0 0 8px 8px;
554
+ overflow: hidden;
555
+ }
556
+
557
+ /* ── Playground panels ────────────────────────────────────────────── */
558
+ .panel-title {
559
+ font-size: 11px;
560
+ font-weight: 600;
561
+ color: #444;
562
+ text-transform: uppercase;
563
+ letter-spacing: 1px;
564
+ padding: 0 0 8px;
565
+ margin-bottom: 0;
566
+ }
567
+ .pg-panel {
568
+ background: #141414;
569
+ border: 1px solid #1f1f1f;
570
  border-radius: 8px;
571
  overflow: hidden;
572
  }
573
+ .pg-panel-head {
574
+ background: #111;
575
+ border-bottom: 1px solid #1f1f1f;
576
+ padding: 10px 16px;
577
+ font-size: 11px;
578
+ font-weight: 600;
579
+ color: #555;
580
+ text-transform: uppercase;
581
+ letter-spacing: 1px;
582
+ }
583
+ .pg-panel-body { padding: 0; }
584
+ .empty-state {
585
+ padding: 24px 16px;
586
+ color: #3a3a3a;
587
+ font-size: 13px;
588
+ font-style: italic;
589
+ text-align: center;
590
  }
591
 
592
+ /* Observation table inside panel */
593
+ .obs-table { width: 100%; border-collapse: collapse; }
594
+ .obs-table td { padding: 9px 16px; border-bottom: 1px solid #1a1a1a; font-size: 12px; vertical-align: top; }
595
+ .obs-table tr:last-child td { border-bottom: none; }
596
+ .obs-key {
597
+ width: 100px;
598
+ color: #444;
599
+ font-family: "JetBrains Mono", monospace;
600
+ font-size: 11px;
601
+ white-space: nowrap;
602
  }
603
+ .obs-val { color: #ccc; font-family: "JetBrains Mono", monospace; font-size: 12px; word-break: break-word; }
604
+ .obs-message { font-family: Inter, sans-serif; font-size: 12px; color: #999; font-style: italic; line-height: 1.6; }
605
+ .hist-mini { font-size: 11px; color: #555; line-height: 1.6; }
606
 
607
+ /* Episode score metrics bar */
608
+ .metrics-bar {
609
+ display: grid;
610
+ grid-template-columns: repeat(4, 1fr);
611
+ border: 1px solid #1f1f1f;
612
+ border-radius: 8px;
613
+ overflow: hidden;
614
  background: #141414;
615
+ }
616
+ .metric-cell {
617
+ padding: 16px;
618
+ border-right: 1px solid #1f1f1f;
619
+ }
620
+ .metric-cell:last-child { border-right: none; }
621
+ .metric-label { font-size: 10px; font-weight: 600; color: #444; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
622
+ .metric-val { font-size: 28px; font-weight: 700; color: #e8e8e8; font-family: "JetBrains Mono", monospace; line-height: 1; }
623
+ .metric-val.sm { font-size: 14px; padding-top: 7px; }
624
+ .score-pill {
625
+ display: inline-flex; align-items: center;
626
+ padding: 3px 10px; border-radius: 4px;
627
+ font-size: 12px; font-weight: 700;
628
+ font-family: "JetBrains Mono", monospace;
629
+ margin: 2px;
630
+ }
631
+
632
+ /* Team assignment card */
633
+ .team-card {
634
+ display: flex;
635
+ align-items: flex-start;
636
+ gap: 14px;
637
+ padding: 16px;
638
+ background: #141414;
639
+ border: 1px solid #1f1f1f;
640
  border-left: 3px solid #ffa94d;
641
+ border-radius: 8px;
642
+ margin-bottom: 8px;
643
+ }
644
+ .team-icon {
645
+ width: 36px; height: 36px;
646
+ background: #1f1500;
647
+ border: 1px solid #3a2800;
648
  border-radius: 6px;
649
+ display: flex; align-items: center; justify-content: center;
650
+ flex-shrink: 0;
651
+ font-size: 16px;
652
  }
653
+ .team-name { font-size: 13px; font-weight: 600; color: #e8e8e8; margin-bottom: 3px; }
654
+ .team-sub { font-size: 11px; color: #666; }
 
 
 
 
 
655
 
656
+ /* Agent response */
657
+ .agent-response {
658
+ padding: 16px;
659
  background: #141414;
660
+ border: 1px solid #00d08422;
661
  border-left: 3px solid #00d084;
662
  border-radius: 8px;
 
663
  font-size: 13px;
664
+ color: #ccc;
665
+ line-height: 1.75;
666
+ font-family: Inter, sans-serif;
667
  }
668
 
669
+ /* Try It code blocks */
670
  .code-block {
671
+ background: #0d1117;
672
+ border: 1px solid #21262d;
673
  border-radius: 8px;
674
  overflow: hidden;
675
+ margin: 16px 0;
676
  }
677
  .code-block pre {
678
+ padding: 20px 24px;
679
+ font-family: "JetBrains Mono", monospace;
680
  font-size: 12px;
681
+ color: #8b949e;
682
+ line-height: 1.75;
683
  white-space: pre;
684
  overflow-x: auto;
685
+ margin: 0;
686
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
687
 
688
+ /* Footer */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
689
  .footer {
690
  margin-top: 48px;
691
+ padding: 20px 32px;
692
+ border-top: 1px solid #1a1a1a;
 
693
  font-size: 12px;
694
+ color: #3a3a3a;
695
+ line-height: 1.9;
696
  }
697
+ .footer a { color: #555; text-decoration: none; }
698
  .footer a:hover { color: #00d084; }
699
  """
700
 
701
+ # ---------------------------------------------------------------------------
702
+ # Static HTML sections
703
+ # ---------------------------------------------------------------------------
704
+
705
+ def _hero_html() -> str:
706
+ desc = (
707
+ "A 3-phase Markov Decision Process where LLM agents triage, route, and resolve "
708
+ "customer support tickets across a structured action space β€” classify, assign, respond, "
709
+ "refund, escalate. Covers e-commerce and SaaS BPO workflows across 3 difficulty tiers. "
710
+ "Deterministic per-phase reward shaping. Parameter-randomized ticket selection prevents "
711
+ "memorization β€” agents must learn the decision pattern, not specific tickets."
712
+ )
713
+ return f"""
714
  <div class='hero'>
715
+ <div class='hero-title'>Customer Support Agent</div>
716
+ <div class='hero-desc'>{desc}</div>
717
+ <div class='stat-grid'>
718
+ <div class='stat-card'><div class='sc-label'>Tickets</div><div class='sc-num'>15</div></div>
719
+ <div class='stat-card'><div class='sc-label'>Tiers</div><div class='sc-num'>3</div></div>
720
+ <div class='stat-card'><div class='sc-label'>Phases</div><div class='sc-num'>3</div></div>
721
+ <div class='stat-card'><div class='sc-label'>Teams</div><div class='sc-num'>6</div></div>
722
+ <div class='stat-card'><div class='sc-label'>Max Steps</div><div class='sc-num'>5</div></div>
723
+ <div class='stat-card'><div class='sc-label'>Reward</div><div class='sc-num sm'>[0.002, 0.998]</div></div>
724
  </div>
725
+ </div>"""
726
+
727
+
728
+ def _overview_html() -> str:
729
+ cards = [
730
+ ("zap", "3-Phase MDP, Not a Bandit",
731
+ "Every ticket runs Triage β†’ Route β†’ Resolve with state evolving between steps. "
732
+ "The agent makes 3 sequential decisions per episode β€” a proper Markov Decision "
733
+ "Process, not a single-shot classification task."),
734
+ ("layers", "Dense Per-Phase Rewards",
735
+ "Intermediate reward at every phase. No sparse end-of-episode signal. "
736
+ "Phase 1 binary (classify or not), Phase 2 graded by team accuracy, "
737
+ "Phase 3 proportional quality scoring across action + team + keyword coverage."),
738
+ ("git", "Evolving Observation State",
739
+ "After Phase 1, issue_type updates from 'unknown' to the true category. "
740
+ "After Phase 2, the assigned team appears in history. The agent sees richer "
741
+ "context at each step β€” state transitions are real, not simulated."),
742
+ ("scale", "Asymmetric Business Penalties",
743
+ "Refund (βˆ’0.50) > Escalation (βˆ’0.30) > Wrong Team (βˆ’0.15). "
744
+ "Mirrors actual BPO cost: an unwarranted refund is immediate financial loss, "
745
+ "a false escalation wastes senior time, wrong routing is recoverable."),
746
+ ("bar", "Proportional Normalization",
747
+ "Phase 3 scores normalize raw_score / max_possible. A simple ticket needing "
748
+ "only classify can still achieve 0.998 without being penalized for omitting "
749
+ "team or response components it never required."),
750
+ ("lock", "Deterministic Grader",
751
+ "Same action + same ticket = same reward. No stochasticity in the grader. "
752
+ "Reproducible RL training and evaluation without environment noise "
753
+ "contaminating the reward signal across runs."),
754
+ ]
755
+ grid = "".join(
756
+ f"<div class='unique-card'>{_icon_box(_ICONS[icon])}"
757
+ f"<div class='uc-title'>{title}</div><div class='uc-body'>{body}</div></div>"
758
+ for icon, title, body in cards
759
+ )
760
+ arch = """<div class='code-block'><pre>Episode Flow β€” 3 sequential steps per ticket:
761
+
762
+ reset() β†’ Observation { issue_type: "unknown", sentiment, priority, message }
763
+
764
+ step({"action_type": "classify"}) ← Phase 1: Triage
765
+ reward: 0.998 (correct) | 0.002 (wrong)
766
+ effect: issue_type revealed in next observation
767
+
768
+ step({"action_type": "assign", "team": "…"}) ← Phase 2: Route
769
+ reward: 0.998 (correct team) | 0.400 (wrong team) | 0.002 (wrong action)
770
+ effect: team context appended to history
771
+
772
+ step({"action_type": "respond|refund|escalate"}) ← Phase 3: Resolve
773
+ reward: proportional quality score in [0.002, 0.998]
774
+ effect: done = True
775
+
776
+ episode_score = mean(r1, r2, r3)</pre></div>"""
777
+ return f"""
778
+ <h2 class='section-h'>What makes this unique</h2>
779
+ <p class='section-sub'>Six design decisions that differentiate this environment from single-step LLM evaluation benchmarks.</p>
780
+ <div class='unique-grid'>{grid}</div>
781
+ <h2 class='section-h' style='margin-top:40px'>Episode Architecture</h2>
782
+ <p class='section-sub'>Each episode is a deterministic 3-step MDP. Observation state updates between phases.</p>
783
+ {arch}"""
784
+
785
+
786
+ def _scenarios_html() -> str:
787
+ out = ""
788
+ tier_meta = {
789
+ "easy": ("5 tickets", "respond, refund"),
790
+ "medium": ("5 tickets", "respond, escalate"),
791
+ "hard": ("5 tickets", "escalate, refund, respond"),
792
+ }
793
+ for tier in ["easy", "medium", "hard"]:
794
+ tc = _TIER_COLORS[tier]
795
+ tickets, actions = tier_meta[tier]
796
+ badge = _badge(tier, tc)
797
+ rows = ""
798
+ for sc in TASK_REGISTRY[tier]:
799
+ t = sc.ticket
800
+ gt = sc.ground_truth
801
+ sc_color = _ACTION_COLORS.get(gt.action_type, "#9ca3af")
802
+ sent_c = _SENT_COLORS.get(t.sentiment, "#9ca3af")
803
+ prio_c = _PRIO_COLORS.get(t.priority, "#9ca3af")
804
+ kws = " ".join(
805
+ f"<span class='kw-tag'>{_esc(k)}</span>"
806
+ for k in gt.response_keywords
807
+ ) if gt.response_keywords else "<span style='color:#333'>β€”</span>"
808
+ team_html = (
809
+ f"<code style='color:#ffa94d;font-size:11px'>{_esc(gt.team)}</code>"
810
+ if gt.team else "<span style='color:#333'>β€”</span>"
811
+ )
812
+ msg_short = t.message[:72] + "…" if len(t.message) > 72 else t.message
813
+ rows += f"""
814
+ <tr>
815
+ <td><code style='color:#666;font-size:11px'>{_esc(t.ticket_id)}</code></td>
816
+ <td><span style='color:{sent_c};font-weight:500'>{_esc(t.sentiment)}</span></td>
817
+ <td><span style='color:{prio_c};font-weight:500'>{_esc(t.priority)}</span></td>
818
+ <td class='msg-cell' title='{_esc(t.message)}'>&ldquo;{_esc(msg_short)}&rdquo;</td>
819
+ <td>{_badge(gt.action_type, sc_color, "11")}</td>
820
+ <td>{team_html}</td>
821
+ <td class='kw-cell'>{kws}</td>
822
+ </tr>"""
823
+ out += f"""
824
+ <div class='tier-section'>
825
+ <div class='tier-header-row'>
826
+ {badge}
827
+ <span class='tier-info'>{tickets} Β· Phase 3 actions: {actions}</span>
828
  </div>
829
+ <div class='table-wrap'>
830
+ <table class='data-table'>
831
+ <thead>
832
+ <tr>
833
+ <th>Ticket ID</th>
834
+ <th>Sentiment</th>
835
+ <th>Priority</th>
836
+ <th>Customer Message</th>
837
+ <th>Phase 3 Action</th>
838
+ <th>Target Team</th>
839
+ <th>Response Keywords</th>
840
+ </tr>
841
+ </thead>
842
+ <tbody>{rows}</tbody>
843
+ </table>
844
+ </div>
845
+ </div>"""
846
+ return f"""
847
+ <h2 class='section-h'>15 support tickets Β· 3 difficulty tiers</h2>
848
+ <p class='section-sub'>
849
+ Each scenario runs the full 3-phase MDP. Hover over a message cell to read the full text.
850
+ Phase 3 action and keywords are ground truth β€” the deterministic grader checks against these.
851
+ </p>
852
+ {out}"""
853
 
854
+
855
+ def _try_it_html() -> str:
856
+ m = _esc(MODEL_NAME)
857
+ return f"""
858
+ <h2 class='section-h'>Run the baseline yourself</h2>
859
+ <p class='section-sub'>
860
+ The validator runs <code style='color:#9ca3af;font-size:12px'>inference.py</code> and parses structured stdout logs.
861
+ Set the two required env vars and run:
862
+ </p>
863
+ <div class='code-block'><pre>export API_BASE_URL=https://your-llm-proxy/v1
864
+ export HF_TOKEN=your_token_here
865
+ export MODEL_NAME={m} # optional
866
+
867
+ python inference.py</pre></div>
868
+
869
+ <h2 class='section-h' style='margin-top:36px'>Expected output</h2>
870
+ <div class='code-block'><pre>[INFO] Using API_BASE_URL=https://... MODEL_NAME={m}
871
+
872
+ [START] task=easy env=support_env model={m}
873
+ [STEP] step=1 action={{"action_type":"classify"}} reward=1.00 done=false error=null
874
+ [STEP] step=2 action={{"action_type":"assign","team":"orders_team"}} reward=1.00 done=false error=null
875
+ [STEP] step=3 action={{"action_type":"respond","response":"..."}} reward=0.87 done=true error=null
876
+ [END] success=true steps=3 score=0.957 rewards=1.00,1.00,0.87
877
+
878
+ [START] task=medium ...
879
+ [START] task=hard ...</pre></div>
880
+
881
+ <h2 class='section-h' style='margin-top:36px'>Reward breakdown</h2>
882
+ <div class='table-wrap' style='border-radius:8px'>
883
+ <table class='data-table'>
884
+ <thead>
885
+ <tr>
886
+ <th>Phase</th>
887
+ <th>Correct</th>
888
+ <th>Wrong action type</th>
889
+ <th>Wrong team</th>
890
+ <th>Penalty</th>
891
+ </tr>
892
+ </thead>
893
+ <tbody>
894
+ <tr>
895
+ <td><span style='color:#60a5fa;font-weight:600'>Phase 1 β€” Triage</span></td>
896
+ <td><span style='color:#00d084;font-weight:700'>0.998</span></td>
897
+ <td><span style='color:#ff6b6b'>0.002</span></td>
898
+ <td><span style='color:#555'>n/a</span></td>
899
+ <td><span style='color:#555'>β€”</span></td>
900
+ </tr>
901
+ <tr>
902
+ <td><span style='color:#ffa94d;font-weight:600'>Phase 2 β€” Route</span></td>
903
+ <td><span style='color:#00d084;font-weight:700'>0.998</span></td>
904
+ <td><span style='color:#ff6b6b'>0.002</span></td>
905
+ <td><span style='color:#ffa94d'>0.400</span></td>
906
+ <td><span style='color:#555'>β€”</span></td>
907
+ </tr>
908
+ <tr>
909
+ <td><span style='color:#00d084;font-weight:600'>Phase 3 β€” Resolve</span></td>
910
+ <td><span style='color:#00d084;font-weight:700'>0.002 – 0.998</span></td>
911
+ <td><span style='color:#ff6b6b'>0.002</span></td>
912
+ <td><span style='color:#ff6b6b'>βˆ’0.15</span></td>
913
+ <td><span style='color:#ff6b6b'>refund βˆ’0.50 Β· escalate βˆ’0.30</span></td>
914
+ </tr>
915
+ <tr style='background:#0d0d0d;font-weight:600'>
916
+ <td style='color:#888'>Episode Score</td>
917
+ <td colspan='4' style='color:#888'>mean(phase1, phase2, phase3) Β· clamped to [0.002, 0.998]</td>
918
+ </tr>
919
+ </tbody>
920
+ </table>
921
+ </div>"""
922
+
923
+ # ---------------------------------------------------------------------------
924
+ # Playground HTML renderers
925
+ # ---------------------------------------------------------------------------
926
+
927
+ def _obs_html(obs_json: str) -> str:
928
+ if not obs_json:
929
+ return "<div class='empty-state'>Reset the environment to load a ticket.</div>"
930
+ try:
931
+ obs = json.loads(obs_json)
932
+ except Exception:
933
+ return f"<div class='empty-state'>β€”</div>"
934
+
935
+ def _val(key, val):
936
+ if key == "ticket_id":
937
+ return f"<code style='color:#888'>{_esc(val)}</code>"
938
+ if key == "issue_type":
939
+ if val == "unknown":
940
+ return f"<span style='color:#333;font-style:italic'>unknown</span>"
941
+ return f"<span style='color:#00d084;font-weight:600'>{_esc(val)}</span>"
942
+ if key == "sentiment":
943
+ c = _SENT_COLORS.get(val, "#9ca3af")
944
+ return f"<span style='color:{c};font-weight:500'>{_esc(val)}</span>"
945
+ if key == "priority":
946
+ c = _PRIO_COLORS.get(val, "#9ca3af")
947
+ return f"<span style='color:{c};font-weight:500'>{_esc(val)}</span>"
948
+ if key == "message":
949
+ return f"<span class='obs-message'>&ldquo;{_esc(val)}&rdquo;</span>"
950
+ return f"<span style='color:#aaa'>{_esc(str(val))}</span>"
951
+
952
+ rows = "".join(
953
+ f"<tr><td class='obs-key'>{key}</td><td class='obs-val'>{_val(key, obs.get(key,'β€”'))}</td></tr>"
954
+ for key in ["ticket_id", "issue_type", "sentiment", "priority", "message"]
955
+ )
956
+ history = obs.get("history", [])
957
+ if history:
958
+ hist_html = "".join(f"<div class='hist-mini'>{_esc(h)}</div>" for h in history[-5:])
959
+ rows += f"<tr><td class='obs-key'>history</td><td class='obs-val'>{hist_html}</td></tr>"
960
+
961
+ return f"""
962
+ <div class='pg-panel'>
963
+ <div class='pg-panel-head'>Current Ticket</div>
964
+ <div class='pg-panel-body'><table class='obs-table'><tbody>{rows}</tbody></table></div>
965
+ </div>"""
966
+
967
+
968
+ def _steps_html(steps: List[dict]) -> str:
969
+ if not steps:
970
+ return f"""
971
+ <div class='pg-panel'>
972
+ <div class='pg-panel-head'>Phase Steps</div>
973
+ <div class='pg-panel-body'><div class='empty-state'>No steps taken yet. Click Run Agent to start.</div></div>
974
+ </div>"""
975
+ rows = ""
976
+ for s in steps:
977
+ pc = _PHASE_COLORS.get(s["phase"], "#9ca3af")
978
+ sc = _score_color(s["score"])
979
+ ac = _ACTION_COLORS.get(s["action"], "#9ca3af")
980
+ err = f"<span style='color:#ff6b6b;font-size:10px'> ⚠</span>" if s.get("error") else ""
981
+ rows += f"""
982
+ <tr>
983
+ <td class='tc'><code style='color:#555'>{s["step"]}</code></td>
984
+ <td><span style='color:{pc};font-weight:600;font-size:11px'>{_esc(s["phase_name"])}</span></td>
985
+ <td>{_badge(s["action"], ac, "11")}</td>
986
+ <td><code style='color:#ffa94d;font-size:11px'>{_esc(s["team"])}</code></td>
987
+ <td class='tr'><span style='color:{sc};font-weight:700'>{s["score"]:.3f}</span>{err}</td>
988
+ </tr>"""
989
+ return f"""
990
+ <div class='pg-panel'>
991
+ <div class='pg-panel-head'>Phase Steps</div>
992
+ <div class='pg-panel-body'>
993
+ <table class='data-table'>
994
+ <thead><tr><th class='tc'>Step</th><th>Phase</th><th>Action</th><th>Team Routed</th><th class='tr'>Score</th></tr></thead>
995
+ <tbody>{rows}</tbody>
996
+ </table>
997
+ </div>
998
+ </div>"""
999
+
1000
+
1001
+ def _score_html(rewards: List[float], avg: float, done: bool) -> str:
1002
+ if not rewards:
1003
+ return f"""
1004
+ <div class='pg-panel'>
1005
+ <div class='pg-panel-head'>Episode Score</div>
1006
+ <div class='pg-panel-body'><div class='empty-state'>No scores yet.</div></div>
1007
+ </div>"""
1008
+ ac = _score_color(avg)
1009
+ dc = "#00d084" if done else "#ffa94d"
1010
+ pills = "".join(
1011
+ f"<span class='score-pill' style='background:{_score_color(r)}1a;color:{_score_color(r)};border:1px solid {_score_color(r)}44'>{r:.3f}</span>"
1012
+ for r in rewards
1013
+ )
1014
+ return f"""
1015
+ <div class='metrics-bar'>
1016
+ <div class='metric-cell'><div class='metric-label'>Avg Score</div>
1017
+ <div class='metric-val' style='color:{ac}'>{avg:.3f}</div></div>
1018
+ <div class='metric-cell'><div class='metric-label'>Steps</div>
1019
+ <div class='metric-val'>{len(rewards)}</div></div>
1020
+ <div class='metric-cell'><div class='metric-label'>Done</div>
1021
+ <div class='metric-val sm' style='color:{dc}'>{str(done).lower()}</div></div>
1022
+ <div class='metric-cell'><div class='metric-label'>Per-Phase</div>
1023
+ <div style='padding-top:6px'>{pills}</div></div>
1024
+ </div>"""
1025
+
1026
+
1027
+ def _team_html(team_lines: List[str]) -> str:
1028
+ if not team_lines:
1029
+ return f"""
1030
+ <div class='pg-panel'>
1031
+ <div class='pg-panel-head'>Team Assignment</div>
1032
+ <div class='pg-panel-body'><div class='empty-state'>No team assigned yet.</div></div>
1033
+ </div>"""
1034
+ ICONS_MAP = {
1035
+ "logistics_team": "🚚", "tech_support_team": "πŸ› ",
1036
+ "safety_team": "⚠️", "finance_team": "πŸ’³",
1037
+ "orders_team": "πŸ“¦", "management_team": "πŸ‘”",
1038
+ }
1039
+ cards = ""
1040
+ for line in team_lines:
1041
+ # line format: "[TKT-XXX] Team Name β€” subtitle"
1042
+ parts = line.split(" ", 1)
1043
+ tid_str = parts[0] if parts else line
1044
+ rest = parts[1] if len(parts) > 1 else ""
1045
+ # find which team key matches
1046
+ matched_key = next((k for k in _TEAM_NAMES if _TEAM_NAMES[k] in rest), None)
1047
+ icon = ICONS_MAP.get(matched_key, "πŸ“‹")
1048
+ name = _TEAM_NAMES.get(matched_key, rest.split(" β€” ")[0]) if matched_key else rest.split(" β€” ")[0]
1049
+ sub = _TEAM_SUBTITLES.get(matched_key, rest.split(" β€” ", 1)[1] if " β€” " in rest else "")
1050
+ cards += f"""
1051
+ <div class='team-card'>
1052
+ <div class='team-icon'>{icon}</div>
1053
+ <div>
1054
+ <div class='team-name'>{_esc(name)}</div>
1055
+ <div class='team-sub'><code style='font-size:11px;color:#444'>{_esc(tid_str)}</code> Β· {_esc(sub)}</div>
1056
+ </div>
1057
+ </div>"""
1058
+ return f"""
1059
+ <div class='pg-panel'>
1060
+ <div class='pg-panel-head'>Team Assignment</div>
1061
+ <div class='pg-panel-body' style='padding:12px'>{cards}</div>
1062
+ </div>"""
1063
+
1064
+
1065
+ def _msg_html(msg: str) -> str:
1066
+ if not msg:
1067
+ return f"""
1068
+ <div class='pg-panel'>
1069
+ <div class='pg-panel-head'>Agent Response</div>
1070
+ <div class='pg-panel-body'><div class='empty-state'>No customer-facing message (triage or route phase).</div></div>
1071
+ </div>"""
1072
+ return f"""
1073
+ <div class='pg-panel'>
1074
+ <div class='pg-panel-head'>Agent Response</div>
1075
+ <div class='pg-panel-body' style='padding:16px'>
1076
+ <div class='agent-response'>{_esc(msg)}</div>
1077
+ </div>
1078
+ </div>"""
1079
+
1080
+
1081
+ def _history_html() -> str:
1082
+ if not env.history:
1083
+ return f"""
1084
+ <div class='pg-panel'>
1085
+ <div class='pg-panel-head'>Action History</div>
1086
+ <div class='pg-panel-body'><div class='empty-state'>History will appear here after reset.</div></div>
1087
+ </div>"""
1088
+ rows = ""
1089
+ for entry in env.history:
1090
+ is_sys = entry.startswith("System:") or entry.startswith("Customer:")
1091
+ cl = "#1f1f1f" if is_sys else "#60a5fa0d"
1092
+ bl = "#2a2a2a" if is_sys else "#60a5fa"
1093
+ fc = "#555" if is_sys else "#ccc"
1094
+ rows += f"<div style='padding:8px 16px;border-bottom:1px solid #1a1a1a;border-left:3px solid {bl};background:{cl};font-size:12px;color:{fc};line-height:1.5'>{_esc(entry)}</div>"
1095
+ return f"""
1096
+ <div class='pg-panel'>
1097
+ <div class='pg-panel-head'>Action History</div>
1098
+ <div class='pg-panel-body'>{rows}</div>
1099
+ </div>"""
1100
 
1101
  # ---------------------------------------------------------------------------
1102
+ # Gradio event handlers
1103
  # ---------------------------------------------------------------------------
1104
 
1105
  def ui_reset(task_choice: str):
1106
  global _agent_history
1107
  _agent_history = []
1108
+ task_name = {"Easy (Classification)": "easy", "Medium (Assignment)": "medium", "Hard (Full Resolution)": "hard"}.get(task_choice, "easy")
1109
  res = env.reset(task_name)
1110
  obs_json = res.observation.model_dump_json(indent=2)
1111
+ empty_score = "<div class='pg-panel'><div class='pg-panel-head'>Episode Score</div><div class='pg-panel-body'><div class='empty-state'>No scores yet.</div></div></div>"
1112
  return (
1113
  _obs_html(obs_json),
1114
  _msg_html(""),
1115
  _steps_html([]),
1116
+ empty_score,
1117
  _history_html(),
1118
  _team_html([]),
1119
  )
 
1126
  return (
1127
  _obs_html(env.get_current_observation().model_dump_json(indent=2)),
1128
  _msg_html(""),
1129
+ _steps_html([]),
1130
+ _score_html([], 0.0, True),
1131
  _history_html(),
1132
  _team_html([]),
1133
  )
1134
 
1135
+ all_steps: List[dict] = []
1136
+ all_rewards: List[float] = []
1137
  last_message = ""
1138
+ team_lines: List[str] = []
1139
 
1140
  for step_num in range(1, 6):
1141
  if env.done:
 
1155
  elif current_phase == 2:
1156
  action = Action(action_type="assign", team="management_team")
1157
  else:
1158
+ action = Action(action_type="respond", response="Thank you for contacting us. Our team will look into this shortly.")
1159
 
1160
  result = env.step(action)
1161
  reward = result.reward
 
1164
  _agent_history = env.history.copy()
1165
  all_rewards.append(reward)
1166
 
1167
+ all_steps.append({
1168
+ "step": step_num,
1169
+ "phase": current_phase,
1170
+ "phase_name": _PHASE_NAMES.get(current_phase, str(current_phase)),
1171
+ "action": action.action_type,
1172
+ "team": action.team or "β€”",
1173
+ "score": reward,
1174
+ "error": error_msg,
1175
+ })
1176
 
1177
  if action.team:
1178
+ name = _TEAM_NAMES.get(action.team, action.team)
1179
+ sub = _TEAM_SUBTITLES.get(action.team, "")
1180
  tid = obs.ticket_id if hasattr(obs, "ticket_id") else "?"
1181
+ team_lines.append(f"[{tid}] {name} β€” {sub}")
1182
 
1183
  if action.response:
1184
  last_message = action.response
 
1204
  return (
1205
  _obs_html(env.get_current_observation().model_dump_json(indent=2)),
1206
  _msg_html(""),
1207
+ _steps_html([]),
1208
+ _score_html([], 0.0, True),
1209
  _history_html(),
1210
  _team_html([]),
1211
  )
1212
 
1213
  try:
1214
+ current_phase = env.phase
1215
  action = Action(
1216
  action_type=a_type,
1217
  team=t_name or None,
 
1222
  done = result.done
1223
  _agent_history = env.history.copy()
1224
 
1225
+ steps = [{
1226
+ "step": env.step_count,
1227
+ "phase": current_phase,
1228
+ "phase_name": _PHASE_NAMES.get(current_phase, str(current_phase)),
1229
+ "action": a_type,
1230
+ "team": t_name or "β€”",
1231
+ "score": reward,
1232
+ "error": None,
1233
+ }]
1234
 
1235
  team_lines = []
1236
  if t_name:
1237
+ name = _TEAM_NAMES.get(t_name, t_name)
1238
+ sub = _TEAM_SUBTITLES.get(t_name, "")
1239
+ if env.current_scenario:
1240
+ tid = env.current_scenario.ticket.ticket_id
1241
+ else:
1242
+ tid = "?"
1243
+ team_lines.append(f"[{tid}] {name} β€” {sub}")
1244
 
1245
  return (
1246
  _obs_html(result.observation.model_dump_json(indent=2)),
1247
  _msg_html(resp_text or ""),
1248
+ _steps_html(steps),
1249
+ _score_html([reward], reward, done),
1250
  _history_html(),
1251
  _team_html(team_lines),
1252
  )
1253
 
1254
  except Exception as exc:
1255
+ err_html = f"<div style='padding:16px;color:#ff6b6b;font-size:13px'>Error: {_esc(str(exc))}</div>"
1256
  return (
1257
  _obs_html(env.get_current_observation().model_dump_json(indent=2)),
1258
  _msg_html(""),
1259
+ f"<div class='pg-panel'><div class='pg-panel-head'>Error</div><div class='pg-panel-body'>{err_html}</div></div>",
1260
+ "<div class='pg-panel'><div class='pg-panel-head'>Episode Score</div><div class='pg-panel-body'><div class='empty-state'>β€”</div></div></div>",
1261
  _history_html(),
1262
  _team_html([]),
1263
  )
 
1266
  # Gradio layout
1267
  # ---------------------------------------------------------------------------
1268
 
1269
+ TASK_CHOICES = ["Easy (Classification)", "Medium (Assignment)", "Hard (Full Resolution)"]
1270
+
1271
  with gr.Blocks(css=CSS, title="Customer Support Agent β€” OpenEnv") as demo:
1272
 
1273
+ gr.HTML(_hero_html())
1274
 
1275
  with gr.Tabs():
1276
 
1277
+ # ── Tab: Overview ─────────────────────────────────────────────
1278
  with gr.Tab("Overview"):
1279
  gr.HTML(_overview_html())
1280
 
1281
+ # ── Tab: Scenarios ────────────────────────────────────────────
1282
  with gr.Tab("Scenarios"):
 
 
1283
  gr.HTML(_scenarios_html())
1284
 
1285
+ # ── Tab: Playground ───────────────────────────────────────────
1286
  with gr.Tab("Playground"):
1287
+ gr.HTML("<h2 class='section-h'>Live interactive episode</h2><p class='section-sub'>Select a tier, reset the environment, then run the full 3-phase episode automatically or step through manually.</p>")
 
1288
 
1289
  with gr.Row():
1290
+ task_dd = gr.Dropdown(choices=TASK_CHOICES, value=TASK_CHOICES[0], label="Task Tier", scale=4)
1291
+ reset_btn = gr.Button("Reset Episode", variant="secondary", scale=1, min_width=140)
1292
+ auto_btn = gr.Button("Run Agent (Full Episode)", variant="primary", scale=2, min_width=200)
1293
 
1294
  with gr.Row():
1295
  with gr.Column(scale=1):
1296
+ obs_out = gr.HTML(_obs_html(""))
1297
+ hist_out = gr.HTML(_history_html())
 
 
 
1298
 
1299
  with gr.Column(scale=1):
1300
+ steps_out = gr.HTML(_steps_html([]))
1301
+ team_out = gr.HTML(_team_html([]))
1302
+ msg_out = gr.HTML(_msg_html(""))
 
 
 
 
 
1303
 
1304
+ score_out = gr.HTML("<div class='pg-panel'><div class='pg-panel-head'>Episode Score</div><div class='pg-panel-body'><div class='empty-state'>No scores yet.</div></div></div>")
 
1305
 
1306
+ with gr.Accordion("Manual Step Override", open=False):
1307
+ gr.HTML("<p style='font-size:12px;color:#555;padding:4px 0 12px'>Step through individual phases manually. Phase 1 requires classify, Phase 2 requires assign + team, Phase 3 requires respond/refund/escalate.</p>")
1308
  with gr.Row():
1309
+ act_type = gr.Dropdown(
1310
+ choices=["classify", "assign", "respond", "refund", "escalate"],
1311
+ value="classify", label="Action Type", scale=1,
1312
+ )
1313
+ act_team = gr.Textbox(label="Team (Phase 2 only)", scale=1, placeholder="e.g. tech_support_team")
1314
  with gr.Row():
1315
+ act_resp = gr.Textbox(label="Response Text (Phase 3 only)", lines=2, scale=3,
1316
+ placeholder="Write the customer-facing response here...")
1317
+ manual_btn = gr.Button("Submit Action", variant="primary", scale=1, min_width=140)
1318
 
1319
+ # ── Tab: Try It ────────────────────────────────────────────────
1320
  with gr.Tab("Try It"):
1321
  gr.HTML(_try_it_html())
1322
 
1323
+ gr.HTML("<div class='footer'>customer-support-agent · 3-phase MDP · 15 tickets · 6 specialist teams · deterministic grader · reward ∈ [0.002, 0.998]<br/><a href='https://github.com/AdityaK-labs/Support-Agent/tree/Tarun'>github</a> · <a href='https://huggingface.co/spaces/Tarun21W/MetaAI'>huggingface</a></div>")
1324
 
 
1325
  _outputs = [obs_out, msg_out, steps_out, score_out, hist_out, team_out]
1326
 
1327
+ reset_btn.click( ui_reset, inputs=[task_dd], outputs=_outputs)
1328
+ auto_btn.click( ui_auto_step, inputs=[], outputs=_outputs)
1329
+ manual_btn.click(ui_manual_step, inputs=[act_type, act_team, act_resp], outputs=_outputs)
1330
 
1331
  demo.queue()
1332
  app = gr.mount_gradio_app(app, demo, path="/")