Spaces:
Paused

dushyantsingh0 Claude Sonnet 4.6 commited on
Commit
548b54e
·
1 Parent(s): 73e742d

Improve AI performance narrative: tier badges, insight-driven prompts

Browse files

- Add _compute_tier() to classify agents as TOP/STRONG/STEADY/AT_RISK/CRITICAL
based on SLA compliance and resolved-ticket thresholds
- Store tier in activity_summary JSON for frontend consumption
- Rewrite LLM prompt: produces a single insight sentence focused on implication
rather than repeating numbers already visible in adjacent table columns;
bans repetitive openers like "Over the past 30 days, the staff member..."
- Frontend: replace sparkle+plain-text narrative cell with color-coded tier badge
+ insight text in a column layout
- Add TIER_CONFIG map and getSlaColor() helper (3-tier: green/amber/red)
- Add .tierBadge, .narrativeText, .narrativeCellTd CSS classes

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

frontend/apps/internal/src/components/AnalyticsDashboard.module.css CHANGED
@@ -691,14 +691,34 @@
691
  font-weight: 800;
692
  }
693
 
 
 
 
 
694
  .narrativeCell {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
695
  font-size: 12px;
696
- color: var(--text-muted);
697
- line-height: 1.5;
698
  font-weight: 500;
699
- display: flex;
700
- align-items: flex-start;
701
- gap: 8px;
702
  }
703
 
704
  .inlineSparkle {
 
691
  font-weight: 800;
692
  }
693
 
694
+ .narrativeCellTd {
695
+ max-width: 380px;
696
+ }
697
+
698
  .narrativeCell {
699
+ display: flex;
700
+ flex-direction: column;
701
+ gap: 6px;
702
+ }
703
+
704
+ .tierBadge {
705
+ display: inline-flex;
706
+ align-items: center;
707
+ padding: 2px 8px;
708
+ border-radius: 6px;
709
+ font-size: 9px;
710
+ font-weight: 900;
711
+ letter-spacing: 0.1em;
712
+ text-transform: uppercase;
713
+ width: fit-content;
714
+ line-height: 1.6;
715
+ }
716
+
717
+ .narrativeText {
718
  font-size: 12px;
719
+ color: var(--text-dim);
720
+ line-height: 1.55;
721
  font-weight: 500;
 
 
 
722
  }
723
 
724
  .inlineSparkle {
frontend/apps/internal/src/components/AnalyticsDashboard.tsx CHANGED
@@ -32,6 +32,19 @@ interface AnalyticsDashboardProps {
32
  readOnly?: boolean;
33
  }
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  const MiniTrend = ({ data, color }: { data: number[], color: string }) => {
36
  if (!data || data.length < 2) return null;
37
  const width = 60;
@@ -348,15 +361,31 @@ export const AnalyticsDashboard: React.FC<AnalyticsDashboardProps> = ({ workspac
348
  {user.active_tickets}
349
  </td>
350
  <td className={styles.slaCell}>
351
- <div className={styles.slaPill} style={{ background: 'var(--bg-dark)', color: user.sla_compliance > 0.9 ? 'var(--success)' : 'var(--warning)', border: `1px solid ${user.sla_compliance > 0.9 ? 'var(--success)' : 'var(--warning)'}33` }}>
352
- {Math.round(user.sla_compliance * 100)}%
353
- </div>
 
 
 
 
 
354
  </td>
355
  <td className={styles.narrativeCellTd}>
356
- <div className={styles.narrativeCell}>
357
- <Sparkles size={14} className={styles.inlineSparkle} />
358
- {user.ai_narrative}
359
- </div>
 
 
 
 
 
 
 
 
 
 
 
360
  </td>
361
  </tr>
362
  )) : (
 
32
  readOnly?: boolean;
33
  }
34
 
35
+ const TIER_CONFIG = {
36
+ TOP: { label: 'TOP', color: '#059669', bg: '#D1FAE5', border: '#6EE7B7' },
37
+ STRONG: { label: 'STRONG', color: '#2563EB', bg: '#DBEAFE', border: '#93C5FD' },
38
+ STEADY: { label: 'STEADY', color: '#7C3AED', bg: '#EDE9FE', border: '#C4B5FD' },
39
+ AT_RISK: { label: 'AT RISK', color: '#D97706', bg: '#FEF3C7', border: '#FCD34D' },
40
+ CRITICAL: { label: 'CRITICAL', color: '#DC2626', bg: '#FEE2E2', border: '#FCA5A5' },
41
+ } as const;
42
+
43
+ type TierKey = keyof typeof TIER_CONFIG;
44
+
45
+ const getSlaColor = (v: number) =>
46
+ v >= 0.9 ? 'var(--success)' : v >= 0.5 ? 'var(--warning)' : 'var(--error)';
47
+
48
  const MiniTrend = ({ data, color }: { data: number[], color: string }) => {
49
  if (!data || data.length < 2) return null;
50
  const width = 60;
 
361
  {user.active_tickets}
362
  </td>
363
  <td className={styles.slaCell}>
364
+ {(() => {
365
+ const c = getSlaColor(user.sla_compliance);
366
+ return (
367
+ <div className={styles.slaPill} style={{ background: 'var(--bg-dark)', color: c, border: `1px solid ${c}44` }}>
368
+ {Math.round(user.sla_compliance * 100)}%
369
+ </div>
370
+ );
371
+ })()}
372
  </td>
373
  <td className={styles.narrativeCellTd}>
374
+ {(() => {
375
+ const tier = (user.activity_summary?.tier ?? 'STEADY') as TierKey;
376
+ const cfg = TIER_CONFIG[tier] ?? TIER_CONFIG.STEADY;
377
+ return (
378
+ <div className={styles.narrativeCell}>
379
+ <span
380
+ className={styles.tierBadge}
381
+ style={{ color: cfg.color, background: cfg.bg, border: `1px solid ${cfg.border}` }}
382
+ >
383
+ {cfg.label}
384
+ </span>
385
+ <span className={styles.narrativeText}>{user.ai_narrative}</span>
386
+ </div>
387
+ );
388
+ })()}
389
  </td>
390
  </tr>
391
  )) : (
tasks/analytics.py CHANGED
@@ -19,6 +19,18 @@ from langchain_core.prompts import ChatPromptTemplate
19
 
20
  logger = get_logger(__name__)
21
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  async def harvest_expertise_task(ctx, ticket_id: UUID, **kwargs):
23
  """Analyze a resolved ticket and harvest skills for the agent."""
24
  from agents.staff_profiler import harvest_agent_skills
@@ -131,16 +143,25 @@ async def generate_nightly_personnel_analytics(ctx, workspace_id: str = None, us
131
  """
132
 
133
  prompt = ChatPromptTemplate.from_template("""
134
- You are a senior service operations analyst. Generate a forensic, professional, and objective 2-sentence performance narrative for a support staff member based on these 30-day metrics:
 
 
135
  {metrics}
136
-
137
- CRITICAL INSTRUCTIONS:
138
- 1. STRICT ADHERENCE: Use the EXACT SLA Compliance percentage provided. If it is 0% or low, do NOT describe it as "reliable" or "100%".
139
- 2. THROUGHPUT: If Resolved (30d) is 0, explicitly mention the lack of output/resolutions.
140
- 3. TONE: Analytical, direct, and clinical. Avoid generic praise. Focus on bottlenecks if they exist.
141
- 4. NO HALLUCINATIONS: Do not invent reasons for low performance. State the facts.
142
-
143
- Output ONLY the 2-sentence narrative.
 
 
 
 
 
 
 
144
  """)
145
 
146
  narrative_res = await (prompt | llm).ainvoke({"metrics": metrics_summary})
@@ -151,6 +172,7 @@ async def generate_nightly_personnel_analytics(ctx, workspace_id: str = None, us
151
  "compliance": compliance,
152
  "avg_res_h": avg_res_h,
153
  "active_load": active_count,
 
154
  "last_calculated": now.isoformat()
155
  }
156
  db.add(uw)
 
19
 
20
  logger = get_logger(__name__)
21
 
22
+ def _compute_tier(compliance: int, resolved: int, active_load: int) -> str:
23
+ if compliance >= 90 and resolved >= 8:
24
+ return "TOP"
25
+ elif compliance >= 75 and resolved >= 3:
26
+ return "STRONG"
27
+ elif compliance >= 55:
28
+ return "STEADY"
29
+ elif compliance >= 30:
30
+ return "AT_RISK"
31
+ else:
32
+ return "CRITICAL"
33
+
34
  async def harvest_expertise_task(ctx, ticket_id: UUID, **kwargs):
35
  """Analyze a resolved ticket and harvest skills for the agent."""
36
  from agents.staff_profiler import harvest_agent_skills
 
143
  """
144
 
145
  prompt = ChatPromptTemplate.from_template("""
146
+ You are a service operations analyst. Generate ONE concise, insight-driven sentence about this support agent's performance pattern — focus on what the data implies, not what it says.
147
+
148
+ Metrics (do NOT restate these numbers directly):
149
  {metrics}
150
+
151
+ Rules:
152
+ - Do NOT start with "The agent", "Over the past 30 days", "The staff member", or any similar opener
153
+ - Start directly with the core finding, risk, or strength
154
+ - Highlight the most significant signal: bottleneck, throughput gap, SLA risk, or standout pattern
155
+ - If Resolved is 0, flag the throughput gap; if SLA is below 50%, flag the compliance risk
156
+ - Be specific and actionable — no generic observations
157
+
158
+ Good examples:
159
+ - "Backlog pressure is intensifying — 7 unresolved cases with no recent throughput signals capacity saturation."
160
+ - "High throughput combined with 9.9h average resolution suggests complex-case specialization rather than general volume handling."
161
+ - "Zero resolutions despite active load indicates potential assignment-pipeline misalignment or escalation dependency."
162
+ - "SLA compliance at 14% signals systemic delays — active cases are consistently breaching agreed response windows."
163
+
164
+ Output ONLY the single insight sentence.
165
  """)
166
 
167
  narrative_res = await (prompt | llm).ainvoke({"metrics": metrics_summary})
 
172
  "compliance": compliance,
173
  "avg_res_h": avg_res_h,
174
  "active_load": active_count,
175
+ "tier": _compute_tier(compliance, res_count, active_count),
176
  "last_calculated": now.isoformat()
177
  }
178
  db.add(uw)