| name | agent-tracing |
| description | Agent tracing CLI for execution snapshots. Use for agent-tracing, traces, snapshots, LLM call inspection, context engine data, agent step analysis, execution debugging, or pulling remote/production traces ("拉线上 tracing") by operation id. Also the first stop for debugging agent tool calls — wrong or missing tool_calls, unexpected tool arguments or results, which tools were available at a step, or why a tool ran where it did. |
| user-invocable | false |
Agent Tracing CLI Guide
@lobechat/agent-tracing is a zero-config local dev tool that records agent execution snapshots to disk and provides a CLI to inspect them.
How It Works
In NODE_ENV=development, AgentRuntimeService.executeStep() automatically records each step to .agent-tracing/ as partial snapshots. When the operation completes, the partial is finalized into a complete ExecutionSnapshot JSON file.
Data flow: executeStep loop -> build StepPresentationData -> write partial snapshot to disk -> on completion, finalize to .agent-tracing/{timestamp}_{traceId}.json
Context engine capture: In RuntimeExecutors.ts, the call_llm executor calls ctx.tracingContextEngine(input, output) after serverMessagesEngine() processes messages. AgentRuntimeService.executeStep buffers the call per step and forwards it to OperationTraceRecorder.appendStep as the typed contextEngine field. CE flows through this side channel rather than the events array so its heavy payload (agentDocuments, systemRole, …) never enters the Redis state pipeline (LOBE-9110).
Package 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 exports
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
- Downloaded remote snapshots:
.agent-tracing/_remote/{operationId}.json
FileSnapshotStore resolves from process.cwd() — run CLI from the repo root
Remote Traces (Production / Staging)
Server deployments also upload completed snapshots to object storage (zstd-compressed; the key is stored in agent_operations.trace_s3_key). agent-tracing inspect <operationId> transparently downloads, decompresses, and caches them — no manual S3 access needed.
-
Find the operation id from a business id (users usually hand you a topic id):
SELECT id, trace_s3_key FROM agent_operations WHERE topic_id = 'tpc_xxx';
trace_s3_key IS NULL means no snapshot was recorded; a non-null key can still 404 in storage (retention/TTL).
-
Configure the base URL — the bucket's public domain plus the /agent-traces prefix — either way:
- env var:
TRACING_BASE_URL=https://<bucket-public-domain>/agent-traces
- file:
.agent-tracing/.env in the repo root containing the same TRACING_BASE_URL=... line
The deployment-specific value is private to each deployment and intentionally not recorded in this repo.
-
Inspect by operation id — auto-detected by the op_..._agt_..._tpc_... shape; the snapshot is cached to .agent-tracing/_remote/<opId>.json and every inspect flag works the same as for local traces:
agent-tracing inspect op_xxx_agt_xxx_tpc_xxx_xxxx
agent-tracing inspect op_xxx_agt_xxx_tpc_xxx_xxxx -T
Implementation: packages/agent-tracing/src/store/remote-store.ts (URL is built from the operation id as {base}/{agentId}/{topicId}/{opId}.json.zst).
CLI Commands
All commands run from the repo root:
agent-tracing
agent-tracing inspect
agent-tracing inspect <traceId>
agent-tracing inspect latest
agent-tracing list
agent-tracing list -l 20
agent-tracing inspect <traceId> -s 0
agent-tracing inspect <traceId> -s 0 -m
agent-tracing inspect <traceId> -s 0 --msg 2
agent-tracing inspect <traceId> -s 0 --msg-input 1
agent-tracing inspect <traceId> -s 1 -t
agent-tracing inspect <traceId> -s 0 -e
agent-tracing inspect <traceId> -s 0 -c
agent-tracing inspect <traceId> -p
agent-tracing inspect <traceId> -s 0 -p
agent-tracing inspect <traceId> -T
agent-tracing inspect <traceId> -s 0 -T
agent-tracing inspect <traceId> -M
agent-tracing inspect <traceId> -s 0 -M
agent-tracing inspect <traceId> -j
agent-tracing inspect <traceId> -s 0 -j
agent-tracing partial list
agent-tracing inspect <partialOperationId>
agent-tracing inspect <partialOperationId> -T
agent-tracing inspect <partialOperationId> -p
agent-tracing partial clean
Inspect Flag Reference
| Flag | Short | Description | Default Step |
|---|
--step <n> | -s | Target a specific step | — |
--messages | -m | Messages context (CE input → params → LLM payload) | — |
--tools | -t | Tool calls & results (what agent invoked) | — |
--events | -e | Raw events (llm_start, llm_result, etc.) | — |
--context | -c | Runtime context & payload (raw) | — |
--system-role | -r | Full system role content | 0 |
--env | | Environment context | 0 |
--payload | -p | Context engine input overview (model, knowledge, tools summary, memory summary, platform context) | 0 |
--payload-tools | -T | Available tools detail (plugin manifests + LLM function definitions) | 0 |
--memory | -M | Full user memory (persona, identity, contexts, preferences, experiences) | 0 |
--diff <n> | -d | Diff against step N (use with -r or --env) | — |
--msg <n> | | Full content of message N from Final LLM Payload | — |
--msg-input <n> | | Full content of message N from Context Engine Input | — |
--json | -j | Output as JSON (combinable with any flag above) | — |
Flags marked "Default Step: 0" auto-select step 0 if --step is not provided. All flags support latest or omitted traceId.
Typical Debug Workflow
agent-tracing inspect
agent-tracing list
agent-tracing inspect -p
agent-tracing inspect TRACE_ID -s 0 -m
agent-tracing inspect TRACE_ID -s 0 --msg 2
agent-tracing inspect -T
agent-tracing inspect -s 1 -t
agent-tracing inspect -M
agent-tracing inspect TRACE_ID -r -d 2
Key Types
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;
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 }>;
contextEngine?: {
input?: unknown;
output?: unknown;
};
}
--messages Output Structure
When using --messages, the output shows three sections (if context engine data is available):
- Context Engine Input — DB messages passed to the engine, with
[0], [1], ... indices. Use --msg-input N to view full content.
- 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], [1], ... indices. Use --msg N to view full content.
Integration Points
- Recording:
apps/server/src/services/agentRuntime/AgentRuntimeService.ts — in the executeStep() method, after building stepPresentationData, writes partial snapshot in dev mode
- Context engine capture:
apps/server/src/modules/AgentRuntime/RuntimeExecutors.ts — in call_llm executor, after serverMessagesEngine() returns, calls ctx.tracingContextEngine(input, output). AgentRuntimeService.executeStep buffers it per step and passes it to traceRecorder.appendStep as the typed contextEngine field (kept off the events array to stay out of Redis state).
- Store:
FileSnapshotStore reads/writes to .agent-tracing/ relative to process.cwd()