Trajectory
trajectory ¶
Trajectory and trace types for agent execution tracking.
This module defines data structures for capturing agent execution traces, including tool calls, state changes, and token usage metrics.
Examples:
Creating a trajectory from an agent evaluation:
from gepa_adk.domain.trajectory import ADKTrajectory, TokenUsage, ToolCallRecord
trajectory = ADKTrajectory(
tool_calls=(ToolCallRecord("search", {"q": "AI"}, ["result"], 0.1),),
state_deltas=(),
token_usage=TokenUsage(input_tokens=100, output_tokens=50, total_tokens=150),
final_output="Search complete.",
error=None,
)
Note
These types are immutable (frozen dataclasses) to ensure trajectory data cannot be modified after capture, maintaining audit integrity.
See Also
gepa_adk.ports.adapter.EvaluationBatch: Adapter protocol that produces trajectory data during evaluation.
ToolCallRecord dataclass ¶
Record of a single tool call during agent execution.
Captures the invocation details of a tool/function call made by an agent during evaluation, including arguments, results, and timing information.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name | Tool or function name that was called. TYPE: |
arguments | Dictionary of arguments passed to the tool. TYPE: |
result | Return value from the tool execution. TYPE: |
timestamp | Relative time in seconds from evaluation start. TYPE: |
Examples:
record = ToolCallRecord(
name="get_weather",
arguments={"city": "Paris"},
result={"temp": 22, "condition": "sunny"},
timestamp=0.123,
)
Source code in src/gepa_adk/domain/trajectory.py
TokenUsage dataclass ¶
Token usage statistics from LLM calls.
Tracks token consumption for monitoring costs and performance of language model interactions during agent execution.
| ATTRIBUTE | DESCRIPTION |
|---|---|
input_tokens | Number of tokens in the prompt/context. TYPE: |
output_tokens | Number of tokens generated in the response. TYPE: |
total_tokens | Sum of input_tokens and output_tokens. TYPE: |
Examples:
Source code in src/gepa_adk/domain/trajectory.py
ADKTrajectory dataclass ¶
Execution trace from ADK agent evaluation.
Captures complete execution details from a single agent evaluation run, including all tool calls, state changes, token usage, and final output. This data enables debugging, optimization, and reflection-based learning.
| ATTRIBUTE | DESCRIPTION |
|---|---|
tool_calls | Immutable sequence of tool invocations during execution. TYPE: |
state_deltas | Sequence of state changes (session state updates). TYPE: |
token_usage | Optional token consumption metrics from LLM calls. TYPE: |
final_output | Final text response from the agent. TYPE: |
error | Error message if execution failed, None otherwise. TYPE: |
Examples:
trajectory = ADKTrajectory(
tool_calls=(ToolCallRecord("search", {"query": "AI"}, ["result1"], 0.1),),
state_deltas=({"search_count": 1},),
token_usage=TokenUsage(100, 50, 150),
final_output="Based on the search...",
error=None,
)
Note
All fields use immutable types (tuples, not lists) to prevent accidental modification of captured trace data.
Source code in src/gepa_adk/domain/trajectory.py
MultiAgentTrajectory dataclass ¶
Execution trace from multi-agent pipeline evaluation.
Captures individual agent trajectories and overall pipeline metrics.
| ATTRIBUTE | DESCRIPTION |
|---|---|
agent_trajectories | Mapping of agent name to trajectory. TYPE: |
pipeline_output | Final output from the primary agent. TYPE: |
total_token_usage | Aggregated token usage across all agents. TYPE: |
error | Error message if pipeline execution failed. TYPE: |
Examples:
Creating a multi-agent trajectory:
from gepa_adk.domain.trajectory import (
MultiAgentTrajectory,
ADKTrajectory,
TokenUsage,
)
trajectory = MultiAgentTrajectory(
agent_trajectories={
"generator": ADKTrajectory(...),
"critic": ADKTrajectory(...),
},
pipeline_output="Generated code output",
total_token_usage=TokenUsage(200, 100, 300),
error=None,
)
Note
All fields use immutable types to prevent accidental modification of captured trace data. agent_trajectories maps agent names to their individual ADKTrajectory records.