agent-tracing
Original:🇺🇸 English
Translated
Agent tracing CLI for inspecting agent execution snapshots. Use when user mentions 'agent-tracing', 'trace', 'snapshot', wants to debug agent execution, inspect LLM calls, view context engine data, or analyze agent steps. Triggers on agent debugging, trace inspection, or execution analysis tasks.
10installs
Sourcelobehub/lobehub
Added on
NPX Install
npx skill4agent add lobehub/lobehub agent-tracingTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Agent Tracing CLI Guide
@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()contextEngineInputoutputPackage 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 exportsData 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()
CLI Commands
All commands run from the repo root:
bash
# View latest trace (tree overview, `inspect` is the default command)
agent-tracing
agent-tracing inspect
agent-tracing inspect <traceId>
agent-tracing inspect latest
# List recent snapshots
agent-tracing list
agent-tracing list -l 20
# Inspect specific step (-s is short for --step)
agent-tracing inspect <traceId> -s 0
# View messages (-m is short for --messages)
agent-tracing inspect <traceId> -s 0 -m
# View full content of a specific message (by index shown in -m output)
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)
agent-tracing inspect <traceId> -s 1 -t
# View raw events (-e is short for --events)
agent-tracing inspect <traceId> -s 0 -e
# View runtime context (-c is short for --context)
agent-tracing inspect <traceId> -s 0 -c
# View context engine input overview (-p is short for --payload)
agent-tracing inspect <traceId> -p
agent-tracing inspect <traceId> -s 0 -p
# View available tools in payload (-T is short for --payload-tools)
agent-tracing inspect <traceId> -T
agent-tracing inspect <traceId> -s 0 -T
# View user memory (-M is short for --memory)
agent-tracing inspect <traceId> -M
agent-tracing inspect <traceId> -s 0 -M
# Raw JSON output (-j is short for --json)
agent-tracing inspect <traceId> -j
agent-tracing inspect <traceId> -s 0 -j
# List in-progress partial snapshots
agent-tracing partial list
# Inspect a partial (use `inspect` directly — all flags work with partial IDs)
agent-tracing inspect <partialOperationId>
agent-tracing inspect <partialOperationId> -T
agent-tracing inspect <partialOperationId> -p
# Clean up stale partial snapshots
agent-tracing partial cleanInspect 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.
--steplatestTypical Debug Workflow
bash
# 1. Trigger an agent operation in the dev UI
# 2. See the overview
agent-tracing inspect
# 3. List all traces, get traceId
agent-tracing list
# 4. Quick overview of what was fed into context engine
agent-tracing inspect -p
# 5. Inspect a specific step's messages to see what was sent to the LLM
agent-tracing inspect TRACE_ID -s 0 -m
# 6. Drill into a truncated message for full content
agent-tracing inspect TRACE_ID -s 0 --msg 2
# 7. Check available tools vs actual tool calls
agent-tracing inspect -T # available tools
agent-tracing inspect -s 1 -t # actual tool calls & results
# 8. Inspect user memory injected into the conversation
agent-tracing inspect -M
# 9. Diff system role between steps (multi-step agents)
agent-tracing inspect TRACE_ID -r -d 2Key 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)
}--messages Output Structure
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
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()