Building Session-Level Observability for DeepSeek Harness with a Community Plugin
说明与用途
dsh-plugin-agent-insights 插件为 DeepSeek Harness 添加了轻量级、会话级别的可观测性,跟踪代理步骤、LLM 请求、工具调用、持续时间、失败情况以及会话长度,并在会话结束时清理数据,且不影响代理运行。
问题
Agentic systems become hard to debug when a single user request triggers multiple model calls, agent steps, and tool executions, making it unclear how the final response was produced.
结果
The plugin provides lightweight, non‑invasive session‑scoped metrics: tool call counts, success/failure, execution duration, slowest tool, LLM request counts, session duration, and cleanup on disposal, all without modifying Harness core.
工作流
- 1. Register dsh-plugin-agent-insights as a Cordis service (ctx.agentInsights).
- 2. Hook into lifecycle events: agent/request, agent/request-error, tools/execute, session/event, session/disposed.
- 3. For each tool call, wrap execution with performance.now() to record duration, success/failure, and error message.
- 4. Increment counters for total LLM requests and failed requests on agent/request and agent/request-error.
- 5. Store per‑session metrics in a WeakMap
<Session, SessionAgentInsights>to avoid memory leaks. - 6. On session/disposed, retrieve metrics, compute final duration, log a summary, and clean up the WeakMap entry.
- 7. Ensure all metric collection is wrapped in try/catch so observability does not interfere with agent execution.
证据
dsh-plugin-agent-insights is a session-scoped observability plugin for DeepSeek Harness.
The plugin wraps the tool execution around next(): const startTime = performance.now() ... const durationMs = performance.now() - startTime
Session completed 8 steps 5 LLM requests 1 failed request 12 tool calls 2 failed tools 14.32s duration Slowest tool: database-query
- 记录日期: 2026-09-20T03:00:23.929Z