Skip to main content

The Hierarchy

A single agent conversation maps to this four-level hierarchy:
LevelWhat it isCount
TrajectoryThe entire conversation, start to finishOne per conversation
StepA snapshot of the conversation at one decision point, containing all messages up to that point (cumulative)One per turn
TurnOne user → agent exchange (user speaks, agent thinks/acts/responds)One or more per trajectory
MessageA single message: user input, assistant output, tool call, or tool resultOne or more per turn

Trajectory

A Trajectory is the SDK’s top-level output — one per conversation. It wraps the full multi-turn agent session into a single, structured object.
FieldTypeDescription
taskTaskConversation metadata (ID, source, turn count, tokens, cost)
stepslist[Step]Ordered decision-point snapshots (one per turn)
rewardRewardOptional aggregate reward signal for the whole conversation
metricsTrajectoryMetricsToken counts, tool call stats, error rates
execution_metricsExecutionMetricsTiming data (LLM time, total time)
errorstrError message if the conversation failed

Step & Turn

A Turn is one user-to-agent exchange: the user sends a message, the agent may call tools, and the agent responds. Turns are the conceptual building block of a conversation. A Step is a Turn’s representation inside a Trajectory. Each Step contains the cumulative message history up to that point — not just the messages from that turn, but every message from the start of the conversation. This cumulative design means each Step is a self-contained training example: given this full context, here is what the agent did next. Step 1 would contain 4 messages (system, user, tool, assistant). Step 2 would contain all 4 messages from Step 1 plus the 4 new messages from Turn 2 — 8 messages total.

Message

A Message is the atomic unit — a single piece of content in the conversation. Each Message has a role that identifies who produced it:
RoleWhat it representsExample
systemSystem promptInstructions to the agent
userHuman input”What’s the weather?”
assistantModel output (text or tool calls)“It’s 62°F and foggy.”
toolTool execution result{"temp": 62}
When the assistant invokes a tool, its message has a tool_calls list instead of (or in addition to) text content. The matching tool message carries a tool_response with the result or error.

How the SDK Builds This

The SDK fetches raw traces from your observability provider, groups them into turns, builds cumulative steps, wraps everything in a Trajectory, and saves it to disk. See the API Reference for full field definitions on all data models.