Skip to content

feat(sight): show LLM latency metrics in agent sessions - #2586

Open
yefuyou wants to merge 3 commits into
alibaba:mainfrom
yefuyou:feat/sight/agent-latency-panel
Open

feat(sight): show LLM latency metrics in agent sessions#2586
yefuyou wants to merge 3 commits into
alibaba:mainfrom
yefuyou:feat/sight/agent-latency-panel

Conversation

@yefuyou

@yefuyou yefuyou commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Completes the AgentSight latency metrics UI part of #2339, following the backend/API work merged in #2578.

This adds per-agent LLM latency and throughput percentiles to the Agent Health page using the existing /api/metrics/latency endpoint. The Agent Sessions page remains focused on session history.

Refs #2339

Changes

  • add fetchLatencyMetrics() for /api/metrics/latency
  • show per-agent TTFT, TPS, TPOT, and E2E p50/p95/p99 metrics
  • reuse the existing 24h / 7d / 30d time-range presets
  • render unavailable first-output metrics as instead of 0
  • keep latency loading/error state independent from agent status and interruption data
  • preserve the existing latency table while a new time-range request is loading
  • guard against stale latency requests when the range changes quickly
  • keep per-agent aggregation in the backend response; no new Agent dropdown is added to the Health page
  • add en-US / zh-CN strings for the new UI
  • use an in-page language menu so locale changes do not open the browser's native select popup
  • add API client regression coverage for filters, nullable metrics, and percentiles

The current branch is based on main after the Agent-name casing follow-up was merged; no frontend casing workaround is included.

Validation

  • npm run test:api-client — 12 passed
  • npm run test:i18n — 4 passed
  • npm run typecheck
  • npm run build
  • npm run build:embed
  • git diff --check

All passed. Builds emit only the existing bundle-size warning.

Manual UI verification

  • Agent Health page order: Agent Status → Latency Metrics → Interruptions
  • agents with observable TTFT/TPS/TPOT/E2E metrics
  • SSE calls without observable first output (TTFT / TPS / TPOT shown as , while E2E remains available)
  • 24h / 7d / 30d range switching while retaining the existing table during refresh
  • English / 简体中文 switching through the in-page menu
  • no new browser console errors or warnings

Scope

This PR is frontend-only. It does not change backend metric semantics, Rust code, eBPF, schema, or add the cleanup changes from #2583.

Screenshot

image

@github-actions github-actions Bot added the component:sight src/agentsight/ label Aug 15, 2026
@yefuyou
yefuyou marked this pull request as ready for review August 15, 2026 16:44

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fbe5f7ae6d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agentsight/dashboard/src/pages/AgentSessionsPage.tsx Outdated

@chengshuyi chengshuyi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review 反馈

感谢这个 PR!代码质量不错——stale request guard、nullable 指标降级为 、独立 loading 状态等设计都很合理。

设计建议:面板放置位置

建议将 latency metrics 面板从「会话列表」(/sessions) 移到「Agent 看板」(/health) 页面。

理由:

  1. 语义对齐 — Agent 看板已经在做 per-agent 运行状态监控(健康/卡顿/崩溃/离线),延迟指标(TTFT/TPS/TPOT/E2E)本质上就是 Agent 的性能 vital signs,和 CPU 利用率是同一类信息——看的是"这个 agent 当前工作状态如何"。
  2. 粒度匹配/api/metrics/latency 返回的是 per-agent 聚合数据(GROUP BY agent_name),不是 per-session 的。放在会话列表里,用户需要在"会话明细"和"聚合指标"之间做心理切换。
  3. 现有结构天然适配 — AgentHealthPage 的 AgentCard 已按 agent 分卡片展示,可以在卡片上追加 mini 指标行(如 TTFT p50: 320ms · TPS p50: 42 t/s),或在卡片网格下方加一个"延迟百分位"表格 section。
  4. 会话列表保持纯粹 — AgentSessionsPage 的核心职责是"找到某个会话 → 点进去看轨迹",聚合面板会分散注意力。

其他 minor findings

  • 合并顺序#2590 尚未合并,需确保 #2590#2586 的顺序,否则 agent filter 大小写不匹配会返回空数据。
  • i18n 位置:zh-CN 的 latency 键被插入到对象最顶部(app.title 之前),建议移到与 en-US 相同的相对位置,方便对照维护。
  • unit 前导空格unit=" tokens/s" 与其他 unit="ms" 不一致,建议统一在组件内部加空格分隔。
  • 刷新按钮disabled={loading} 可考虑加上 || latencyLoading

以上 minor 项不阻塞,主要想讨论的是面板位置的设计方向。

@yefuyou
yefuyou force-pushed the feat/sight/agent-latency-panel branch from fbe5f7a to 481a579 Compare August 17, 2026 15:27
@yefuyou

yefuyou commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author
agentsight-pr2586-latency-fixed agentsight-language-menu-fixed

@yefuyou

yefuyou commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Review 反馈

感谢这个 PR!代码质量不错——stale request guard、nullable 指标降级为 、独立 loading 状态等设计都很合理。

设计建议:面板放置位置

建议将 latency metrics 面板从「会话列表」(/sessions) 移到「Agent 看板」(/health) 页面。

理由:

  1. 语义对齐 — Agent 看板已经在做 per-agent 运行状态监控(健康/卡顿/崩溃/离线),延迟指标(TTFT/TPS/TPOT/E2E)本质上就是 Agent 的性能 vital signs,和 CPU 利用率是同一类信息——看的是"这个 agent 当前工作状态如何"。
  2. 粒度匹配/api/metrics/latency 返回的是 per-agent 聚合数据(GROUP BY agent_name),不是 per-session 的。放在会话列表里,用户需要在"会话明细"和"聚合指标"之间做心理切换。
  3. 现有结构天然适配 — AgentHealthPage 的 AgentCard 已按 agent 分卡片展示,可以在卡片上追加 mini 指标行(如 TTFT p50: 320ms · TPS p50: 42 t/s),或在卡片网格下方加一个"延迟百分位"表格 section。
  4. 会话列表保持纯粹 — AgentSessionsPage 的核心职责是"找到某个会话 → 点进去看轨迹",聚合面板会分散注意力。

其他 minor findings

以上 minor 项不阻塞,主要想讨论的是面板位置的设计方向。

感谢 Review,已经按建议调整了这一版:
latency metrics 已从 /sessions 移到 /health 的 Agent 看板,放在 Agent 状态区和中断事件之间,Sessions 页面恢复为只关注会话列表和轨迹入口。
保留 per-agent 聚合展示,支持 24h / 7d / 30d,并继续保留 stale request guard、独立 loading/error 状态和 nullable 指标显示为 —。
#2590 已经合并,当前分支已基于包含该修复的 main,不再需要前端大小写 workaround。
已调整 zh-CN latency i18n keys 的位置,并统一了 unit spacing。
原来关于 Sessions 刷新按钮和 latencyLoading 的建议,在 latency 面板迁出 Sessions 后已经自然不再适用。
本地验证已通过 API tests、i18n tests、typecheck、build、build:embed 和 git diff --check,也做了中英文及时间范围切换的手动 UI 验证。
目前 GitHub 正在出现 Pull Requests / Actions 相关故障,我这边暂时无法稳定编辑 PR 页面、更新最新截图,也无法正常看到 merge status / CI 状态。代码和最新 commit 已经 push,等 GitHub 恢复后我会再补上新的截图并确认 CI 状态。感谢!

@chengshuyi chengshuyi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

二轮 Review:延迟指标应嵌入 AgentCard 内部

感谢快速响应上一轮反馈!面板迁移到 /health、i18n 对齐、unit 统一等都已确认 OK。

设计调整:指标嵌入卡片

当前实现是一个独立的 LatencyMetricsSection 表格,放在 AgentStatusSection 和 InterruptionSection 之间。希望改为将延迟指标嵌入到每个 AgentCard 内部,理由:

  1. 一一对应 — 看板的核心交互单元是卡片(per-agent),指标跟着卡片走,用户不需要在"卡片网格"和"下方表格"之间做视觉跳转再按 agent name 匹配。
  2. 信息内聚 — 卡片已经在展示 latency_ms(健康探活延迟),LLM 延迟百分位(TTFT/TPS/TPOT/E2E)是同一维度的延伸,放在一起更自然。
  3. 空间效率 — 独立表格在 agent 数量少(1-3 个,最常见场景)时显得空旷,嵌入卡片后布局更紧凑。

建议实现方式

在 AgentCard 的 PID/状态行下方追加一行 compact 指标:

// AgentCard 内部,PID 行之后
{latency && (
  <div className="mt-1.5 pt-1.5 border-t border-gray-100 text-[11px] text-gray-500 flex flex-wrap gap-x-3 gap-y-0.5">
    <span>TTFT <b className="text-gray-700">{fmt(latency.ttft_ms?.p50)}ms</b></span>
    <span>TPS <b className="text-gray-700">{fmt(latency.tps?.p50)} t/s</b></span>
    <span>E2E <b className="text-gray-700">{fmt(latency.e2e?.p50)}ms</b></span>
  </div>
)}

要点:

  • 默认只展示 p50(卡片空间有限),p95/p99 可以通过 tooltip 或 hover 展示
  • 无数据的指标显示 ,整行无数据时不渲染
  • 时间范围选择器(24h/7d/30d)提升到 AgentStatusSection 的标题行右侧,作为全局控制
  • fetchLatencyMetrics 返回的是 per-agent 聚合,按 agent_name 匹配分发到各卡片即可

保留的部分

  • apiClient.ts 的接口定义和 fetchLatencyMetrics 函数 ✅ 无需改动
  • 回归测试 ✅ 无需改动
  • i18n keys ✅ 无需改动(可能需微调,如去掉 latency.agent 列头键)
  • stale request guard / 独立 loading 状态 ✅ 逻辑保留,只是渲染位置从独立 section 移到 section 内部

其他

  • codex bot 的 casing thread 可以 resolve 了(#2590 已合并)
  • LanguageSwitcher 重写质量不错,LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:sight src/agentsight/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants