pub struct AgentSession {
pub session_id: String,
pub agent_id: AgentId,
pub steps: Vec<ReActStep>,
pub memory_hits: usize,
pub graph_lookups: usize,
pub duration_ms: u64,
pub checkpoint_errors: Vec<String>,
}Expand description
The result of a single agent run.
Fields§
§session_id: StringStable unique identifier for this session (UUID v4 string).
agent_id: AgentIdThe agent ID used for this session.
steps: Vec<ReActStep>All ReAct steps executed during the session.
memory_hits: usizeNumber of episodic memory retrievals made during the session.
graph_lookups: usizeNumber of graph lookups made during the session.
duration_ms: u64Wall-clock duration of the session in milliseconds.
checkpoint_errors: Vec<String>Non-fatal errors encountered while saving per-step checkpoints.
Populated only when a persistence backend is configured. A non-empty list means some step snapshots may be missing from storage, but the session itself completed successfully.
Implementations§
Source§impl AgentSession
impl AgentSession
Sourcepub fn step_count(&self) -> usize
pub fn step_count(&self) -> usize
Return the number of steps in the session.
Each ReActStep in steps carries a step_duration_ms field measuring
wall-clock time from inference call to observation for that individual step.
Use this to identify slow steps:
for (i, step) in session.steps.iter().enumerate() {
println!("step {i}: {}ms", step.step_duration_ms);
}Sourcepub fn final_answer(&self) -> Option<String>
pub fn final_answer(&self) -> Option<String>
Return the final answer text from the last step, if available.
Extracts the content after FINAL_ANSWER in the last step’s action field.
Returns None if there are no steps or the last action is not a FINAL_ANSWER.
Sourcepub fn is_successful(&self) -> bool
pub fn is_successful(&self) -> bool
Return true if the session ended with a FINAL_ANSWER action.
This is the normal successful exit from a ReAct loop. false means the
loop was cut short by a timeout, max-iterations limit, or an error.
Sourcepub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
Return the session wall-clock duration as a std::time::Duration.
Sourcepub fn tool_calls_made(&self) -> usize
pub fn tool_calls_made(&self) -> usize
Return the number of tool-call actions dispatched during the session.
Each ReActStep whose action parses as a ToolCall (not a FinalAnswer)
is counted.
Sourcepub fn total_step_duration_ms(&self) -> u64
pub fn total_step_duration_ms(&self) -> u64
Return the sum of all individual step durations in milliseconds.
This is the cumulative inference + tool execution time across all steps,
which may differ from duration_ms due to overhead between steps.
Sourcepub fn average_step_duration_ms(&self) -> u64
pub fn average_step_duration_ms(&self) -> u64
Return the average step duration in milliseconds.
Returns 0 when there are no steps.
Sourcepub fn slowest_step(&self) -> Option<&ReActStep>
pub fn slowest_step(&self) -> Option<&ReActStep>
Return a reference to the slowest step (highest step_duration_ms).
Returns None when there are no steps.
Sourcepub fn fastest_step(&self) -> Option<&ReActStep>
pub fn fastest_step(&self) -> Option<&ReActStep>
Return a reference to the fastest step (lowest step_duration_ms).
Returns None when there are no steps.
Sourcepub fn filter_tool_call_steps(&self) -> Vec<&ReActStep>
pub fn filter_tool_call_steps(&self) -> Vec<&ReActStep>
Return references to all steps that are tool calls (not FINAL_ANSWER).
Sourcepub fn slowest_step_index(&self) -> Option<usize>
pub fn slowest_step_index(&self) -> Option<usize>
Return the zero-based index of the slowest step, or None if there are no steps.
Sourcepub fn fastest_step_index(&self) -> Option<usize>
pub fn fastest_step_index(&self) -> Option<usize>
Return the zero-based index of the fastest step, or None if there are no steps.
Sourcepub fn last_step(&self) -> Option<&ReActStep>
pub fn last_step(&self) -> Option<&ReActStep>
Return a reference to the last step, or None if there are no steps.
Sourcepub fn first_step(&self) -> Option<&ReActStep>
pub fn first_step(&self) -> Option<&ReActStep>
Return a reference to the first step taken, or None if there are no steps.
Sourcepub fn step_at(&self, idx: usize) -> Option<&ReActStep>
pub fn step_at(&self, idx: usize) -> Option<&ReActStep>
Return a reference to the step at zero-based index idx, or None if out of bounds.
Sourcepub fn observation_at(&self, idx: usize) -> Option<&str>
pub fn observation_at(&self, idx: usize) -> Option<&str>
Return the observation string at step idx, or None if out of bounds.
Sourcepub fn action_at(&self, idx: usize) -> Option<&str>
pub fn action_at(&self, idx: usize) -> Option<&str>
Return the action string at step idx, or None if out of bounds.
Sourcepub fn observations_matching(&self, pattern: &str) -> Vec<&ReActStep>
pub fn observations_matching(&self, pattern: &str) -> Vec<&ReActStep>
Return steps whose observation contains pattern (case-insensitive).
Sourcepub fn thoughts_containing(&self, pattern: &str) -> Vec<&ReActStep>
pub fn thoughts_containing(&self, pattern: &str) -> Vec<&ReActStep>
Return steps whose thought contains pattern (case-insensitive).
Sourcepub fn has_action(&self, action_name: &str) -> bool
pub fn has_action(&self, action_name: &str) -> bool
Return true if any step in this session used action_name.
Sourcepub fn thought_at(&self, idx: usize) -> Option<&str>
pub fn thought_at(&self, idx: usize) -> Option<&str>
Return the thought string at step idx, or None if out of bounds.
Sourcepub fn step_count_for_action(&self, action_name: &str) -> usize
pub fn step_count_for_action(&self, action_name: &str) -> usize
Count how many steps used action_name as their action.
Returns 0 if the action was never invoked. Complements
has_action, which only tests for presence.
Sourcepub fn observations(&self) -> Vec<&str>
pub fn observations(&self) -> Vec<&str>
Return all observation strings in step order.
Each string is a borrow of the corresponding ReActStep::observation
field. Useful for bulk post-processing of tool results.
Sourcepub fn observation_count(&self) -> usize
pub fn observation_count(&self) -> usize
Return the number of steps that have a non-empty observation string.
Sourcepub fn last_n_observations(&self, n: usize) -> Vec<&str>
pub fn last_n_observations(&self, n: usize) -> Vec<&str>
Return up to the last n non-empty observation strings, ordered oldest
to newest.
Empty observations are skipped. If the session has fewer than n
non-empty observations, all of them are returned.
Sourcepub fn actions_in_window(&self, n: usize) -> Vec<&str>
pub fn actions_in_window(&self, n: usize) -> Vec<&str>
Return the action names from the last n steps, ordered oldest to newest.
If the session has fewer than n steps, all action names are returned.
Sourcepub fn steps_without_observation(&self) -> usize
pub fn steps_without_observation(&self) -> usize
Return the number of steps whose observation string is empty.
Sourcepub fn first_thought(&self) -> Option<&str>
pub fn first_thought(&self) -> Option<&str>
Return the thought string from the first step, or None if the session
has no steps.
Sourcepub fn last_thought(&self) -> Option<&str>
pub fn last_thought(&self) -> Option<&str>
Return the thought string from the last step, or None if the session
has no steps.
Sourcepub fn first_action(&self) -> Option<&str>
pub fn first_action(&self) -> Option<&str>
Return the action name from the first step, or None if the session
has no steps.
Sourcepub fn last_action(&self) -> Option<&str>
pub fn last_action(&self) -> Option<&str>
Return the action name from the last step, or None if the session
has no steps.
Sourcepub fn last_n_steps(&self, n: usize) -> &[ReActStep]
pub fn last_n_steps(&self, n: usize) -> &[ReActStep]
Return a slice of the last n steps.
If n is greater than or equal to the total step count, all steps are
returned. An empty slice is returned for sessions with no steps.
Sourcepub fn step_durations_ms(&self) -> Vec<u64>
pub fn step_durations_ms(&self) -> Vec<u64>
Return all per-step durations in milliseconds, in order.
Useful for computing custom percentiles or detecting slow outlier steps.
Sourcepub fn total_latency_ms(&self) -> u64
pub fn total_latency_ms(&self) -> u64
Return the sum of all step durations in milliseconds.
Equivalent to step_durations_ms().iter().sum() but avoids allocating
a temporary Vec.
Sourcepub fn avg_step_duration_ms(&self) -> f64
pub fn avg_step_duration_ms(&self) -> f64
Return the arithmetic mean step duration in milliseconds.
Returns 0.0 for sessions with no steps.
Sourcepub fn longest_step(&self) -> Option<&ReActStep>
pub fn longest_step(&self) -> Option<&ReActStep>
Return a reference to the step with the largest step_duration_ms.
Returns None if the session has no steps. When multiple steps share
the maximum duration the first one (lowest index) is returned.
Sourcepub fn shortest_step(&self) -> Option<&ReActStep>
pub fn shortest_step(&self) -> Option<&ReActStep>
Return a reference to the step with the smallest step_duration_ms.
Returns None if the session has no steps. When multiple steps share
the minimum duration the first one (lowest index) is returned.
Sourcepub fn action_sequence(&self) -> Vec<String>
pub fn action_sequence(&self) -> Vec<String>
Return the sequence of action names taken, in step order.
Unlike all_actions() this returns owned Strings so the result can
outlive the session borrow.
Sourcepub fn unique_tools_used(&self) -> Vec<String>
pub fn unique_tools_used(&self) -> Vec<String>
Return the sorted, deduplicated set of tool names invoked during the session.
Tool-call steps are identified by the same heuristic as tool_calls_made:
a non-empty action that does not start with FINAL_ANSWER.
Sourcepub fn all_thoughts(&self) -> Vec<&str>
pub fn all_thoughts(&self) -> Vec<&str>
Collect all thought strings from every step, in order.
Sourcepub fn all_actions(&self) -> Vec<&str>
pub fn all_actions(&self) -> Vec<&str>
Collect all action strings from every step, in order.
Sourcepub fn all_observations(&self) -> Vec<&str>
pub fn all_observations(&self) -> Vec<&str>
Collect all observation strings from every step, in order.
Sourcepub fn failed_steps(&self) -> Vec<&ReActStep>
pub fn failed_steps(&self) -> Vec<&ReActStep>
Return references to steps where the observation indicates a tool error.
A step is classified as failed when its observation starts with
{"error" (the structured error JSON produced by required-field
validation) or contains the substring "error" (case-insensitive).
Sourcepub fn failed_tool_call_count(&self) -> usize
pub fn failed_tool_call_count(&self) -> usize
Return the number of tool-call steps whose observation indicates an error.
Equivalent to failed_steps().len() but avoids collecting a Vec.
Sourcepub fn action_counts(&self) -> HashMap<String, usize>
pub fn action_counts(&self) -> HashMap<String, usize>
Return a count of how many times each action was taken in this session.
The map key is the action name (e.g. "search", "FINAL_ANSWER").
Sourcepub fn unique_actions(&self) -> Vec<String>
pub fn unique_actions(&self) -> Vec<String>
Return a sorted list of unique action names used in this session.
Sourcepub fn most_used_action(&self) -> Option<String>
pub fn most_used_action(&self) -> Option<String>
Return the action name used most often during the session.
Returns None for sessions with no steps. When multiple actions tie
for the maximum count, any one of them may be returned.
Sourcepub fn last_observation(&self) -> Option<&str>
pub fn last_observation(&self) -> Option<&str>
Return the observation string from the most recent step that has one.
Steps with an empty observation are skipped. Returns None when no
step has produced an observation yet.
Sourcepub fn thought_count(&self) -> usize
pub fn thought_count(&self) -> usize
Return the number of steps that have a non-empty thought string.
Sourcepub fn observation_rate(&self) -> f64
pub fn observation_rate(&self) -> f64
Return the fraction of steps that contain a non-empty observation.
Returns 0.0 for sessions with no steps.
Sourcepub fn has_graph_lookups(&self) -> bool
pub fn has_graph_lookups(&self) -> bool
Return true if at least one knowledge-graph lookup was performed during
this session.
Sourcepub fn consecutive_same_action_at_end(&self) -> usize
pub fn consecutive_same_action_at_end(&self) -> usize
Return how many times the last action in the session repeats consecutively at the end of the step list.
Returns 0 for empty sessions or single-step sessions where no repeat
is possible. Useful for detecting a stuck agent that keeps retrying the
same action.
Sourcepub fn action_repetition_rate(&self) -> f64
pub fn action_repetition_rate(&self) -> f64
Return the fraction of steps (from the second onward) that repeat the immediately preceding action.
Returns 0.0 for sessions with fewer than two steps. A high value
may indicate the agent is stuck in a loop.
Sourcepub fn max_consecutive_failures(&self) -> usize
pub fn max_consecutive_failures(&self) -> usize
Return the length of the longest consecutive run of failed steps.
A step is considered failed when its observation starts with {"error"
or contains the substring "error" (case-insensitive).
Returns 0 for sessions with no steps or no failures.
Sourcepub fn avg_thought_length(&self) -> f64
pub fn avg_thought_length(&self) -> f64
Return the mean character length of non-empty thought strings.
Only steps with a non-empty thought field are included.
Returns 0.0 when no step has a thought.
Sourcepub fn graph_lookup_rate(&self) -> f64
pub fn graph_lookup_rate(&self) -> f64
Return the rate of knowledge-graph lookups per step.
Computed as graph_lookups / step_count. Returns 0.0 when there
are no steps, to avoid division by zero.
Sourcepub fn has_checkpoint_errors(&self) -> bool
pub fn has_checkpoint_errors(&self) -> bool
Return true if any checkpoint errors were recorded during the session.
A non-empty checkpoint_errors list means some step snapshots may be
missing from storage, but the session itself completed successfully.
Sourcepub fn checkpoint_error_count(&self) -> usize
pub fn checkpoint_error_count(&self) -> usize
Return the number of checkpoint errors recorded during this session.
Sourcepub fn graph_lookup_count(&self) -> usize
pub fn graph_lookup_count(&self) -> usize
Return the number of knowledge-graph lookups performed during this session.
Sourcepub fn memory_hit_rate(&self) -> f64
pub fn memory_hit_rate(&self) -> f64
Return the episodic memory hit rate for this session.
Computed as memory_hits / step_count. Returns 0.0 when there are
no steps, to avoid division by zero.
Sourcepub fn total_memory_hits(&self) -> usize
pub fn total_memory_hits(&self) -> usize
Return the raw count of episodic memory hits for this session.
Sourcepub fn throughput_steps_per_sec(&self) -> f64
pub fn throughput_steps_per_sec(&self) -> f64
Return the session throughput in steps per second.
Computed as step_count / (duration_ms / 1000.0). Returns 0.0
if duration_ms is zero.
Sourcepub fn duration_secs(&self) -> u64
pub fn duration_secs(&self) -> u64
Return the session duration in full seconds (rounded down).
Sourcepub fn steps_above_thought_length(&self, threshold: usize) -> usize
pub fn steps_above_thought_length(&self, threshold: usize) -> usize
Return the count of steps whose thought string is longer than threshold bytes.
Sourcepub fn has_final_answer(&self) -> bool
pub fn has_final_answer(&self) -> bool
Return true if any step’s action begins with "FINAL_ANSWER" (case-insensitive).
Sourcepub fn avg_action_length(&self) -> f64
pub fn avg_action_length(&self) -> f64
Return the mean byte length of all step action strings.
Returns 0.0 for empty sessions.
Sourcepub fn has_tool_failures(&self) -> bool
pub fn has_tool_failures(&self) -> bool
Return true if any tool-call steps had error observations.
Sourcepub fn tool_call_rate(&self) -> f64
pub fn tool_call_rate(&self) -> f64
Return the fraction of steps that were tool calls.
Computed as tool_calls_made / step_count. Returns 0.0 for empty
sessions to avoid division by zero.
Sourcepub fn step_success_rate(&self) -> f64
pub fn step_success_rate(&self) -> f64
Return the fraction of tool-call steps that succeeded.
Computed as 1.0 - (failed_tool_call_count / step_count). Returns
1.0 for empty sessions (no failures possible).
Sourcepub fn action_diversity(&self) -> f64
pub fn action_diversity(&self) -> f64
Return the ratio of unique actions to total steps.
Returns 0.0 for sessions with no steps. A value of 1.0 means every
step used a different action; lower values indicate repeated actions.
Sourcepub fn total_thought_length(&self) -> usize
pub fn total_thought_length(&self) -> usize
Return the total byte length of all thought strings across all steps.
Sourcepub fn steps_with_empty_observations(&self) -> usize
pub fn steps_with_empty_observations(&self) -> usize
Return the number of steps whose observation string is empty.
Sourcepub fn observation_lengths(&self) -> Vec<usize>
pub fn observation_lengths(&self) -> Vec<usize>
Return the byte length of each observation, in step order.
Sourcepub fn avg_observation_length(&self) -> f64
pub fn avg_observation_length(&self) -> f64
Return the mean observation byte length across all steps.
Returns 0.0 for empty sessions.
Sourcepub fn min_thought_length(&self) -> usize
pub fn min_thought_length(&self) -> usize
Return the byte length of the shortest non-empty thought, or 0 if
no non-empty thoughts exist.
Sourcepub fn longest_observation(&self) -> Option<&str>
pub fn longest_observation(&self) -> Option<&str>
Return the longest observation string in the session, or None if
the session is empty.
Sourcepub fn thought_lengths(&self) -> Vec<usize>
pub fn thought_lengths(&self) -> Vec<usize>
Return the byte length of each step’s thought string, in step order.
Sourcepub fn most_common_action(&self) -> Option<&str>
pub fn most_common_action(&self) -> Option<&str>
Return the action string that appears most often across all steps.
Returns None if the session has no steps.
Sourcepub fn action_lengths(&self) -> Vec<usize>
pub fn action_lengths(&self) -> Vec<usize>
Return the byte length of each step’s action string, in step order.
Sourcepub fn step_success_count(&self) -> usize
pub fn step_success_count(&self) -> usize
Return the count of steps that did not have a tool failure.
Sourcepub fn longest_thought(&self) -> Option<&str>
pub fn longest_thought(&self) -> Option<&str>
Return the thought string of the step with the most bytes.
Returns None if the session has no steps.
Sourcepub fn shortest_action(&self) -> Option<&str>
pub fn shortest_action(&self) -> Option<&str>
Return the action string of the step with the fewest bytes.
Returns None if the session has no steps.
Sourcepub fn total_thought_bytes(&self) -> usize
pub fn total_thought_bytes(&self) -> usize
Return the sum of byte lengths of all thought strings in the session.
Sourcepub fn total_observation_bytes(&self) -> usize
pub fn total_observation_bytes(&self) -> usize
Return the sum of byte lengths of all observation strings in the session.
Sourcepub fn first_step_action(&self) -> Option<&str>
pub fn first_step_action(&self) -> Option<&str>
Return the action string of the first step in the session.
Returns None if the session has no steps.
Sourcepub fn last_step_action(&self) -> Option<&str>
pub fn last_step_action(&self) -> Option<&str>
Return the action string of the last step in the session.
Returns None if the session has no steps.
Sourcepub fn count_nonempty_thoughts(&self) -> usize
pub fn count_nonempty_thoughts(&self) -> usize
Return the count of steps that have a non-empty thought string.
Sourcepub fn observation_contains_count(&self, substring: &str) -> usize
pub fn observation_contains_count(&self, substring: &str) -> usize
Return the count of steps whose observation contains substring.
Sourcepub fn count_steps_with_action(&self, action: &str) -> usize
pub fn count_steps_with_action(&self, action: &str) -> usize
Return the number of steps whose action string matches action exactly.
Sourcepub fn thought_contains_count(&self, substring: &str) -> usize
pub fn thought_contains_count(&self, substring: &str) -> usize
Return the number of steps whose thought contains substring.
Sourcepub fn failure_rate(&self) -> f64
pub fn failure_rate(&self) -> f64
Return the fraction of steps that had a tool failure observation.
Computed as failed_tool_call_count / step_count. Returns 0.0 for
empty sessions.
Sourcepub fn unique_action_count(&self) -> usize
pub fn unique_action_count(&self) -> usize
Return the number of distinct action names used across all steps.
Trait Implementations§
Source§impl Clone for AgentSession
impl Clone for AgentSession
Source§fn clone(&self) -> AgentSession
fn clone(&self) -> AgentSession
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more