Skip to main content
Workflow tracing records which steps ran via StepTransition. Trace capture goes deeper โ€” it records what happened inside each step: every tool call, thinking block, token count, and cost. The trace is written to a JSONL file during execution, and the file path flows through the workflow journal so analysis tools can find it.

When you need trace capture

  • Markov analysis โ€” fingerprint an agentโ€™s behavioral patterns across runs
  • Cost attribution โ€” break down per-step token usage and cost
  • Debugging โ€” replay exactly what the agent saw, thought, and did
  • Regression detection โ€” compare traces across code changes

Setup

Trace capture requires two things: an agent model that writes trace files, and a workflow client that propagates the path.

1. Configure traceDir on ClaudeAgentModel

The ClaudeAgentModel from agent-client writes a JSONL trace file per call() when traceDir is set:
Each call produces a file like traces/agent-run-20260528-143000-a1b2c3d4.jsonl containing every message in the session.

2. Bridge to a trace-aware AgentClient

The workflow-flows AgentClient is a @FunctionalInterface that returns text. To carry trace metadata, override executeForResult():
Plain lambdas still work โ€” executeForResult() defaults to calling execute() with a null trace path.

3. Use AgentClientStep in a workflow

Each AgentClientStep gets its own trace file. The path flows through to StepTransition:

How it works

The trace path flows through four layers:
The executor clears TRACE_PATH from context after each step so deterministic steps donโ€™t inherit a stale path.

Journal integration

When using workflow-journal, trace paths appear in WorkflowStepEvent and are included in the journalโ€™s JSON output:
The journal event includes tracePath when present:

JDBC persistence

JdbcTraceRecorder stores trace paths in the trace_path column of step_transitions:

ClaudeStep vs AgentClientStep

For any workflow where you need to analyze what the agent did โ€” use AgentClientStep.

Maven coordinates

Or use the AgentWorks BOM (1.1.0+) for managed versions.

Durability

JdbcTraceRecorder, CheckpointingStepRunner

API Reference

StepTransition, TraceRecorder, WorkflowExecutor