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 on lines +259 to +260
const agentName = agentFilter === 'all' ? undefined : agentFilter;
const data = await fetchLatencyMetrics(startNs, endNs, agentName);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve backend casing in latency filters

When merged eBPF and log sessions use different casing for the same agent (the existing code explicitly cites Qoder versus qoder), the case-insensitive dropdown keeps whichever spelling appears first, but this value is sent verbatim to the latency endpoint. The backend applies COALESCE(agent_name, process_name) = ?3 case-sensitively, so selecting a lowercase log-derived label can show matching sessions while the latency table incorrectly reports no data for uppercase eBPF records; normalize the comparison server-side or resolve the filter to the backend's recorded spelling.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Valid point. The latency endpoint was introduced in #2578, and its agent matching semantics are not aligned with the existing case-insensitive Agent Sessions identity handling. I’m addressing that in a separate backend follow-up so this PR can remain scoped to the dashboard integration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Backend follow-up opened as #2590. It aligns the latency API with the existing case-insensitive Agent Sessions identity handling. #2586 now notes this dependency explicitly.

@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 状态。感谢!

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