agent-tracing
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAgent Tracing CLI Guide
Agent Tracing CLI 使用指南
@lobechat/agent-tracing@lobechat/agent-tracingHow It Works
工作原理
In , automatically records each step to as partial snapshots. When the operation completes, the partial is finalized into a complete JSON file.
NODE_ENV=developmentAgentRuntimeService.executeStep().agent-tracing/ExecutionSnapshotData flow: executeStep loop -> build -> write partial snapshot to disk -> on completion, finalize to
StepPresentationData.agent-tracing/{timestamp}_{traceId}.jsonContext engine capture: In , the executor emits a event after processes messages. This event carries the full (DB messages, systemRole, model, knowledge, tools, userMemory, etc.) and the processed messages (the final LLM payload).
RuntimeExecutors.tscall_llmcontext_engine_resultserverMessagesEngine()contextEngineInputoutput在 环境下, 会自动将每个步骤作为部分快照记录到 目录。当操作完成后,部分快照会被整理为完整的 JSON 文件。
NODE_ENV=developmentAgentRuntimeService.executeStep().agent-tracing/ExecutionSnapshot数据流:executeStep 循环 → 构建 → 将部分快照写入磁盘 → 操作完成后,整理为 文件
StepPresentationData.agent-tracing/{timestamp}_{traceId}.json上下文引擎捕获:在 中, 执行器在 处理完消息后,会触发 事件。该事件携带完整的 (数据库消息、systemRole、模型、知识库、工具、用户记忆等)以及处理后的 消息(最终LLM负载)。
RuntimeExecutors.tscall_llmserverMessagesEngine()context_engine_resultcontextEngineInputoutputPackage Location
包位置
packages/agent-tracing/
src/
types.ts # ExecutionSnapshot, StepSnapshot, SnapshotSummary
store/
types.ts # ISnapshotStore interface
file-store.ts # FileSnapshotStore (.agent-tracing/*.json)
recorder/
index.ts # appendStepToPartial(), finalizeSnapshot()
viewer/
index.ts # Terminal rendering: renderSnapshot, renderStepDetail, renderMessageDetail, renderSummaryTable, renderPayload, renderPayloadTools, renderMemory
cli/
index.ts # CLI entry point (#!/usr/bin/env bun)
inspect.ts # Inspect command (default)
partial.ts # Partial snapshot commands (list, inspect, clean)
index.ts # Barrel exportspackages/agent-tracing/
src/
types.ts # ExecutionSnapshot, StepSnapshot, SnapshotSummary
store/
types.ts # ISnapshotStore 接口
file-store.ts # FileSnapshotStore(.agent-tracing/*.json)
recorder/
index.ts # appendStepToPartial(), finalizeSnapshot()
viewer/
index.ts # 终端渲染:renderSnapshot, renderStepDetail, renderMessageDetail, renderSummaryTable, renderPayload, renderPayloadTools, renderMemory
cli/
index.ts # CLI 入口(#!/usr/bin/env bun)
inspect.ts # 检查命令(默认)
partial.ts # 部分快照命令(列表、检查、清理)
index.ts # 桶导出Data Storage
数据存储
- Completed snapshots:
.agent-tracing/{ISO-timestamp}_{traceId-short}.json - Latest symlink:
.agent-tracing/latest.json - In-progress partials:
.agent-tracing/_partial/{operationId}.json - resolves from
FileSnapshotStore— run CLI from the repo rootprocess.cwd()
- 已完成快照:
.agent-tracing/{ISO-timestamp}_{traceId-short}.json - 最新快照软链接:
.agent-tracing/latest.json - 进行中的部分快照:
.agent-tracing/_partial/{operationId}.json - 基于
FileSnapshotStore路径解析 — 请在仓库根目录运行CLIprocess.cwd()
CLI Commands
CLI 命令
All commands run from the repo root:
bash
undefined所有命令需在仓库根目录运行:
bash
undefinedView latest trace (tree overview, inspect
is the default command)
inspect查看最新追踪记录(树状概览,inspect
是默认命令)
inspectagent-tracing
agent-tracing inspect
agent-tracing inspect <traceId>
agent-tracing inspect latest
agent-tracing
agent-tracing inspect
agent-tracing inspect <traceId>
agent-tracing inspect latest
List recent snapshots
列出近期快照
agent-tracing list
agent-tracing list -l 20
agent-tracing list
agent-tracing list -l 20
Inspect specific step (-s is short for --step)
检查特定步骤(-s 是 --step 的缩写)
agent-tracing inspect <traceId> -s 0
agent-tracing inspect <traceId> -s 0
View messages (-m is short for --messages)
查看消息(-m 是 --messages 的缩写)
agent-tracing inspect <traceId> -s 0 -m
agent-tracing inspect <traceId> -s 0 -m
View full content of a specific message (by index shown in -m output)
查看特定消息的完整内容(使用 -m 输出中的索引)
agent-tracing inspect <traceId> -s 0 --msg 2
agent-tracing inspect <traceId> -s 0 --msg-input 1
agent-tracing inspect <traceId> -s 0 --msg 2
agent-tracing inspect <traceId> -s 0 --msg-input 1
View tool call/result details (-t is short for --tools)
查看工具调用/结果详情(-t 是 --tools 的缩写)
agent-tracing inspect <traceId> -s 1 -t
agent-tracing inspect <traceId> -s 1 -t
View raw events (-e is short for --events)
查看原始事件(-e 是 --events 的缩写)
agent-tracing inspect <traceId> -s 0 -e
agent-tracing inspect <traceId> -s 0 -e
View runtime context (-c is short for --context)
查看运行时上下文(-c 是 --context 的缩写)
agent-tracing inspect <traceId> -s 0 -c
agent-tracing inspect <traceId> -s 0 -c
View context engine input overview (-p is short for --payload)
查看上下文引擎输入概览(-p 是 --payload 的缩写)
agent-tracing inspect <traceId> -p
agent-tracing inspect <traceId> -s 0 -p
agent-tracing inspect <traceId> -p
agent-tracing inspect <traceId> -s 0 -p
View available tools in payload (-T is short for --payload-tools)
查看负载中的可用工具(-T 是 --payload-tools 的缩写)
agent-tracing inspect <traceId> -T
agent-tracing inspect <traceId> -s 0 -T
agent-tracing inspect <traceId> -T
agent-tracing inspect <traceId> -s 0 -T
View user memory (-M is short for --memory)
查看用户记忆(-M 是 --memory 的缩写)
agent-tracing inspect <traceId> -M
agent-tracing inspect <traceId> -s 0 -M
agent-tracing inspect <traceId> -M
agent-tracing inspect <traceId> -s 0 -M
Raw JSON output (-j is short for --json)
输出原始JSON格式(-j 是 --json 的缩写)
agent-tracing inspect <traceId> -j
agent-tracing inspect <traceId> -s 0 -j
agent-tracing inspect <traceId> -j
agent-tracing inspect <traceId> -s 0 -j
List in-progress partial snapshots
列出进行中的部分快照
agent-tracing partial list
agent-tracing partial list
Inspect a partial (use inspect
directly — all flags work with partial IDs)
inspect检查部分快照(直接使用 inspect
命令 — 所有参数均适用于部分快照ID)
inspectagent-tracing inspect <partialOperationId>
agent-tracing inspect <partialOperationId> -T
agent-tracing inspect <partialOperationId> -p
agent-tracing inspect <partialOperationId>
agent-tracing inspect <partialOperationId> -T
agent-tracing inspect <partialOperationId> -p
Clean up stale partial snapshots
清理过期的部分快照
agent-tracing partial clean
undefinedagent-tracing partial clean
undefinedInspect Flag Reference
检查命令参数参考
| Flag | Short | Description | Default Step |
|---|---|---|---|
| | Target a specific step | — |
| | Messages context (CE input → params → LLM payload) | — |
| | Tool calls & results (what agent invoked) | — |
| | Raw events (llm_start, llm_result, etc.) | — |
| | Runtime context & payload (raw) | — |
| | Full system role content | 0 |
| Environment context | 0 | |
| | Context engine input overview (model, knowledge, tools summary, memory summary, platform context) | 0 |
| | Available tools detail (plugin manifests + LLM function definitions) | 0 |
| | Full user memory (persona, identity, contexts, preferences, experiences) | 0 |
| | Diff against step N (use with | — |
| Full content of message N from Final LLM Payload | — | |
| Full content of message N from Context Engine Input | — | |
| | Output as JSON (combinable with any flag above) | — |
Flags marked "Default Step: 0" auto-select step 0 if is not provided. All flags support or omitted traceId.
--steplatest| 参数 | 缩写 | 描述 | 默认步骤 |
|---|---|---|---|
| | 定位到特定步骤 | — |
| | 消息上下文(上下文引擎输入 → 参数 → LLM负载) | — |
| | 工具调用与结果(Agent调用的内容) | — |
| | 原始事件(llm_start、llm_result等) | — |
| | 运行时上下文与负载(原始格式) | — |
| | 完整system role内容 | 0 |
| 环境上下文 | 0 | |
| | 上下文引擎输入概览(模型、知识库、工具摘要、记忆摘要、平台上下文) | 0 |
| | 可用工具详情(插件清单 + LLM函数定义) | 0 |
| | 完整用户记忆(角色设定、身份信息、上下文、偏好设置、过往经历) | 0 |
| | 与第N步进行对比(需配合 | — |
| 查看最终LLM负载中第N条消息的完整内容 | — | |
| 查看上下文引擎输入中第N条消息的完整内容 | — | |
| | 以JSON格式输出(可与上述任意参数组合使用) | — |
标记为“默认步骤:0”的参数,若未指定,则默认选择第0步。所有参数均支持使用或省略traceId。
--steplatestTypical Debug Workflow
典型调试流程
bash
undefinedbash
undefined1. Trigger an agent operation in the dev UI
1. 在开发UI中触发Agent操作
2. See the overview
2. 查看概览
agent-tracing inspect
agent-tracing inspect
3. List all traces, get traceId
3. 列出所有追踪记录,获取traceId
agent-tracing list
agent-tracing list
4. Quick overview of what was fed into context engine
4. 快速查看上下文引擎输入概览
agent-tracing inspect -p
agent-tracing inspect -p
5. Inspect a specific step's messages to see what was sent to the LLM
5. 检查特定步骤的消息,查看发送给LLM的内容
agent-tracing inspect TRACE_ID -s 0 -m
agent-tracing inspect TRACE_ID -s 0 -m
6. Drill into a truncated message for full content
6. 查看截断消息的完整内容
agent-tracing inspect TRACE_ID -s 0 --msg 2
agent-tracing inspect TRACE_ID -s 0 --msg 2
7. Check available tools vs actual tool calls
7. 对比可用工具与实际调用的工具
agent-tracing inspect -T # available tools
agent-tracing inspect -s 1 -t # actual tool calls & results
agent-tracing inspect -T # 可用工具
agent-tracing inspect -s 1 -t # 实际工具调用与结果
8. Inspect user memory injected into the conversation
8. 检查注入对话的用户记忆
agent-tracing inspect -M
agent-tracing inspect -M
9. Diff system role between steps (multi-step agents)
9. 对比多步骤Agent中不同步骤的system role
agent-tracing inspect TRACE_ID -r -d 2
undefinedagent-tracing inspect TRACE_ID -r -d 2
undefinedKey Types
关键类型定义
typescript
interface ExecutionSnapshot {
traceId: string;
operationId: string;
model?: string;
provider?: string;
startedAt: number;
completedAt?: number;
completionReason?:
| 'done'
| 'error'
| 'interrupted'
| 'max_steps'
| 'cost_limit'
| 'waiting_for_human';
totalSteps: number;
totalTokens: number;
totalCost: number;
error?: { type: string; message: string };
steps: StepSnapshot[];
}
interface StepSnapshot {
stepIndex: number;
stepType: 'call_llm' | 'call_tool';
executionTimeMs: number;
content?: string; // LLM output
reasoning?: string; // Reasoning/thinking
inputTokens?: number;
outputTokens?: number;
toolsCalling?: Array<{ apiName: string; identifier: string; arguments?: string }>;
toolsResult?: Array<{
apiName: string;
identifier: string;
isSuccess?: boolean;
output?: string;
}>;
messages?: any[]; // DB messages before step
context?: { phase: string; payload?: unknown; stepContext?: unknown };
events?: Array<{ type: string; [key: string]: unknown }>;
// context_engine_result event contains:
// input: full contextEngineInput (messages, systemRole, model, knowledge, tools, userMemory, ...)
// output: processed messages array (final LLM payload)
}typescript
interface ExecutionSnapshot {
traceId: string;
operationId: string;
model?: string;
provider?: string;
startedAt: number;
completedAt?: number;
completionReason?:
| 'done'
| 'error'
| 'interrupted'
| 'max_steps'
| 'cost_limit'
| 'waiting_for_human';
totalSteps: number;
totalTokens: number;
totalCost: number;
error?: { type: string; message: string };
steps: StepSnapshot[];
}
interface StepSnapshot {
stepIndex: number;
stepType: 'call_llm' | 'call_tool';
executionTimeMs: number;
content?: string; // LLM输出
reasoning?: string; // 推理/思考过程
inputTokens?: number;
outputTokens?: number;
toolsCalling?: Array<{ apiName: string; identifier: string; arguments?: string }>;
toolsResult?: Array<{
apiName: string;
identifier: string;
isSuccess?: boolean;
output?: string;
}>;
messages?: any[]; // 步骤执行前的数据库消息
context?: { phase: string; payload?: unknown; stepContext?: unknown };
events?: Array<{ type: string; [key: string]: unknown }>;
// context_engine_result 事件包含:
// input: 完整contextEngineInput(消息、systemRole、模型、知识库、工具、用户记忆等)
// output: 处理后的消息数组(最终LLM负载)
}--messages Output Structure
--messages 输出结构
When using , the output shows three sections (if context engine data is available):
--messages- Context Engine Input — DB messages passed to the engine, with ,
[0], ... indices. Use[1]to view full content.--msg-input N - Context Engine Params — systemRole, model, provider, knowledge, tools, userMemory, etc.
- Final LLM Payload — Processed messages after context engine (system date injection, user memory, history truncation, etc.), with ,
[0], ... indices. Use[1]to view full content.--msg N
使用参数时,输出会包含三个部分(若上下文引擎数据可用):
--messages- 上下文引擎输入 — 传入引擎的数据库消息,带有、
[0]……索引。使用[1]可查看完整内容。--msg-input N - 上下文引擎参数 — systemRole、模型、供应商、知识库、工具、用户记忆等。
- 最终LLM负载 — 上下文引擎处理后的消息(包含系统日期注入、用户记忆、历史截断等),带有、
[0]……索引。使用[1]可查看完整内容。--msg N
Integration Points
集成点
- Recording: — in the
src/server/services/agentRuntime/AgentRuntimeService.tsmethod, after buildingexecuteStep(), writes partial snapshot in dev modestepPresentationData - Context engine event: — in
src/server/modules/AgentRuntime/RuntimeExecutors.tsexecutor, aftercall_llmreturns, emitsserverMessagesEngine()eventcontext_engine_result - Store: reads/writes to
FileSnapshotStorerelative to.agent-tracing/process.cwd()
- 记录功能:— 在
src/server/services/agentRuntime/AgentRuntimeService.ts方法中,构建完executeStep()后,在开发模式下写入部分快照stepPresentationData - 上下文引擎事件:— 在
src/server/modules/AgentRuntime/RuntimeExecutors.ts执行器中,call_llm返回后,触发serverMessagesEngine()事件context_engine_result - 存储:读取/写入相对
FileSnapshotStore路径的process.cwd()目录.agent-tracing/