Skip to main content

AgentSession

Struct AgentSession 

Source
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: String

Stable unique identifier for this session (UUID v4 string).

§agent_id: AgentId

The agent ID used for this session.

§steps: Vec<ReActStep>

All ReAct steps executed during the session.

§memory_hits: usize

Number of episodic memory retrievals made during the session.

§graph_lookups: usize

Number of graph lookups made during the session.

§duration_ms: u64

Wall-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

Source

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);
}
Source

pub fn is_empty(&self) -> bool

Return true if the session has no recorded steps.

Source

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.

Source

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.

Source

pub fn elapsed(&self) -> Duration

Return the session wall-clock duration as a std::time::Duration.

Source

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.

Source

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.

Source

pub fn average_step_duration_ms(&self) -> u64

Return the average step duration in milliseconds.

Returns 0 when there are no steps.

Source

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.

Source

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.

Source

pub fn filter_tool_call_steps(&self) -> Vec<&ReActStep>

Return references to all steps that are tool calls (not FINAL_ANSWER).

Source

pub fn slowest_step_index(&self) -> Option<usize>

Return the zero-based index of the slowest step, or None if there are no steps.

Source

pub fn fastest_step_index(&self) -> Option<usize>

Return the zero-based index of the fastest step, or None if there are no steps.

Source

pub fn last_step(&self) -> Option<&ReActStep>

Return a reference to the last step, or None if there are no steps.

Source

pub fn first_step(&self) -> Option<&ReActStep>

Return a reference to the first step taken, or None if there are no steps.

Source

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.

Source

pub fn observation_at(&self, idx: usize) -> Option<&str>

Return the observation string at step idx, or None if out of bounds.

Source

pub fn action_at(&self, idx: usize) -> Option<&str>

Return the action string at step idx, or None if out of bounds.

Source

pub fn observations_matching(&self, pattern: &str) -> Vec<&ReActStep>

Return steps whose observation contains pattern (case-insensitive).

Source

pub fn thoughts_containing(&self, pattern: &str) -> Vec<&ReActStep>

Return steps whose thought contains pattern (case-insensitive).

Source

pub fn has_action(&self, action_name: &str) -> bool

Return true if any step in this session used action_name.

Source

pub fn thought_at(&self, idx: usize) -> Option<&str>

Return the thought string at step idx, or None if out of bounds.

Source

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.

Source

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.

Source

pub fn observation_count(&self) -> usize

Return the number of steps that have a non-empty observation string.

Source

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.

Source

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.

Source

pub fn steps_without_observation(&self) -> usize

Return the number of steps whose observation string is empty.

Source

pub fn first_thought(&self) -> Option<&str>

Return the thought string from the first step, or None if the session has no steps.

Source

pub fn last_thought(&self) -> Option<&str>

Return the thought string from the last step, or None if the session has no steps.

Source

pub fn first_action(&self) -> Option<&str>

Return the action name from the first step, or None if the session has no steps.

Source

pub fn last_action(&self) -> Option<&str>

Return the action name from the last step, or None if the session has no steps.

Source

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.

Source

pub fn first_n_steps(&self, n: usize) -> &[ReActStep]

Return a slice containing at most the first n steps.

If the session has fewer than n steps all steps are returned. Returns an empty slice for n == 0 or an empty session.

Source

pub fn steps_with_tool<'a>(&'a self, tool_name: &str) -> Vec<&'a ReActStep>

Return references to steps whose action string contains tool_name.

Useful for auditing which steps invoked a specific tool. The comparison is case-sensitive.

Source

pub fn total_chars(&self) -> usize

Return the total character count across all thought, action, and observation strings in the session.

Useful for estimating context consumption. Returns 0 for empty sessions.

Source

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.

Source

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.

Source

pub fn avg_step_duration_ms(&self) -> f64

Return the arithmetic mean step duration in milliseconds.

Returns 0.0 for sessions with no steps.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn all_thoughts(&self) -> Vec<&str>

Collect all thought strings from every step, in order.

Source

pub fn all_actions(&self) -> Vec<&str>

Collect all action strings from every step, in order.

Source

pub fn all_observations(&self) -> Vec<&str>

Collect all observation strings from every step, in order.

Source

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).

Source

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.

Source

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").

Source

pub fn unique_actions(&self) -> Vec<String>

Return a sorted list of unique action names used in this session.

Source

pub fn has_duplicate_actions(&self) -> bool

Return true when at least one action string appears more than once.

Useful for detecting repetitive or looping agent behaviour without iterating over the full step list manually.

Source

pub fn step_indices_with_tool(&self, tool_name: &str) -> Vec<usize>

Return the 0-based indices of steps whose action contains tool_name.

Returns an empty Vec when no step matches. Useful when you need positions rather than step references for further slicing.

Source

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.

Source

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.

Source

pub fn thought_count(&self) -> usize

Return the number of steps that have a non-empty thought string.

Source

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.

Source

pub fn has_graph_lookups(&self) -> bool

Return true if at least one knowledge-graph lookup was performed during this session.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn checkpoint_error_count(&self) -> usize

Return the number of checkpoint errors recorded during this session.

Source

pub fn graph_lookup_count(&self) -> usize

Return the number of knowledge-graph lookups performed during this session.

Source

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.

Source

pub fn total_memory_hits(&self) -> usize

Return the raw count of episodic memory hits for this session.

Source

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.

Source

pub fn duration_secs(&self) -> u64

Return the session duration in full seconds (rounded down).

Source

pub fn steps_above_thought_length(&self, threshold: usize) -> usize

Return the count of steps whose thought string is longer than threshold bytes.

Source

pub fn has_final_answer(&self) -> bool

Return true if any step’s action begins with "FINAL_ANSWER" (case-insensitive).

Source

pub fn avg_action_length(&self) -> f64

Return the mean byte length of all step action strings.

Returns 0.0 for empty sessions.

Source

pub fn has_tool_failures(&self) -> bool

Return true if any tool-call steps had error observations.

Source

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.

Source

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).

Source

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.

Source

pub fn total_thought_length(&self) -> usize

Return the total byte length of all thought strings across all steps.

Source

pub fn steps_with_empty_observations(&self) -> usize

Return the number of steps whose observation string is empty.

Source

pub fn observation_lengths(&self) -> Vec<usize>

Return the byte length of each observation, in step order.

Source

pub fn avg_observation_length(&self) -> f64

Return the mean observation byte length across all steps.

Returns 0.0 for empty sessions.

Source

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.

Source

pub fn longest_observation(&self) -> Option<&str>

Return the longest observation string in the session, or None if the session is empty.

Source

pub fn thought_lengths(&self) -> Vec<usize>

Return the byte length of each step’s thought string, in step order.

Source

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.

Source

pub fn action_lengths(&self) -> Vec<usize>

Return the byte length of each step’s action string, in step order.

Source

pub fn step_success_count(&self) -> usize

Return the count of steps that did not have a tool failure.

Source

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.

Source

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.

Source

pub fn total_thought_bytes(&self) -> usize

Return the sum of byte lengths of all thought strings in the session.

Source

pub fn total_observation_bytes(&self) -> usize

Return the sum of byte lengths of all observation strings in the session.

Source

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.

Source

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.

Source

pub fn count_nonempty_thoughts(&self) -> usize

Return the count of steps that have a non-empty thought string.

Source

pub fn observation_contains_count(&self, substring: &str) -> usize

Return the count of steps whose observation contains substring.

Source

pub fn count_steps_with_action(&self, action: &str) -> usize

Return the number of steps whose action string matches action exactly.

Source

pub fn thought_contains_count(&self, substring: &str) -> usize

Return the number of steps whose thought contains substring.

Source

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.

Source

pub fn unique_action_count(&self) -> usize

Return the number of distinct action names used across all steps.

Source

pub fn steps_in_range(&self, start: usize, end: usize) -> Vec<&ReActStep>

Return references to steps whose indices fall in [start, end).

Clamps end to step_count() so out-of-bounds ranges are safe. Returns an empty Vec when start >= step_count() or start >= end.

Source

pub fn median_step_duration_ms(&self) -> u64

Return the median step duration in milliseconds.

Sorts step durations and picks the middle value (lower median for even counts). Returns 0 when the session has no steps.

Source

pub fn p95_step_duration_ms(&self) -> u64

Return the 95th-percentile step duration in milliseconds.

Uses the nearest-rank method: the value at index ⌈0.95 × n⌉ − 1 in the sorted list of step durations. Returns 0 when the session has no steps.

Source

pub fn p99_step_duration_ms(&self) -> u64

Return the 99th-percentile step duration in milliseconds.

Uses the nearest-rank method: the value at index ⌈0.99 × n⌉ − 1 in the sorted list of step durations. Returns 0 when the session has no steps.

Source

pub fn step_count_above_duration_ms(&self, threshold_ms: u64) -> usize

Return the count of steps whose step_duration_ms is strictly greater than threshold_ms.

Useful for identifying sessions that contain outlier-slow steps. Returns 0 for empty sessions.

Source

pub fn min_step_duration_ms(&self) -> u64

Return the minimum step_duration_ms across all steps in the session.

Returns 0 for empty sessions.

Source

pub fn max_step_duration_ms(&self) -> u64

Return the maximum step_duration_ms across all steps in the session.

Returns 0 for empty sessions.

Source

pub fn total_action_bytes(&self) -> usize

Return the sum of byte lengths of all action strings in the session.

Useful alongside total_thought_bytes and total_observation_bytes to estimate the full token budget consumed by a session.

Source

pub fn step_duration_variance_ms(&self) -> f64

Return the population variance of step durations in milliseconds squared.

Returns 0.0 for sessions with fewer than two steps.

Source

pub fn steps_with_errors(&self) -> Vec<&ReActStep>

Return references to steps whose observation contains "error" (case-insensitive).

A quick filter for identifying tool-call failures without inspecting the full observation string. For more control use observations_matching.

Source

pub fn steps_with_long_observations( &self, threshold_bytes: usize, ) -> Vec<&ReActStep>

Return references to steps whose observation byte length exceeds threshold_bytes.

Useful for identifying steps that produced unusually verbose tool output.

Source

pub fn observations_above_bytes(&self, min_bytes: usize) -> Vec<&ReActStep>

Return steps whose observation is strictly longer than min_bytes.

Equivalent to steps_with_long_observations but uses the name “above” for consistency with other filtering predicates.

Source

pub fn total_step_chars(&self) -> usize

Return the total character count across all steps.

Sums thought.chars().count() + action.chars().count() + observation.chars().count() for every step. Useful as a proxy for token budget estimation.

Source

pub fn unique_observations_count(&self) -> usize

Return the number of distinct observation strings across all steps.

Two steps with the same observation text are counted as one. Returns 0 for empty sessions.

Source

pub fn thought_max_bytes(&self) -> usize

Return the maximum byte length of any thought string in the session.

Returns 0 for empty sessions or sessions where every thought is empty.

Source

pub fn observation_max_bytes(&self) -> usize

Return the maximum byte length of any observation string in the session.

Returns 0 for empty sessions or sessions where every observation is empty.

Source

pub fn step_count_below_duration_ms(&self, threshold_ms: u64) -> usize

Return the count of steps whose step_duration_ms is strictly less than threshold_ms.

Complements step_count_above_duration_ms. Returns 0 for empty sessions.

Source

pub fn max_action_bytes(&self) -> usize

Return the maximum byte length of any action string across all steps.

Returns 0 for sessions with no steps or where every action is empty.

Source

pub fn min_action_bytes(&self) -> usize

Return the minimum byte length of any action string across all steps.

Returns 0 for sessions with no steps or where every action is empty.

Source

pub fn proportion_tool_calls(&self) -> f64

Return the fraction of steps that are tool calls (not FINAL_ANSWER).

Returns 0.0 for sessions with no steps.

Source

pub fn thought_density(&self) -> f64

Return the ratio of total thought bytes to the total bytes across all step fields (thoughts + actions + observations).

Returns 0.0 for sessions with no steps or where no bytes exist.

Source

pub fn step_throughput_per_sec(&self) -> f64

Return the average number of ReAct steps completed per second.

Computed as step_count / (duration_ms / 1000.0). Returns 0.0 for sessions with no steps or zero duration.

Source

pub fn avg_action_bytes(&self) -> f64

Return the mean byte length of action strings across all steps.

Returns 0.0 for sessions with no steps.

Source

pub fn avg_observation_bytes(&self) -> f64

Return the mean byte length of observation strings across all steps.

Returns 0.0 for sessions with no steps.

Source

pub fn total_observation_count(&self) -> usize

Return the number of steps that have a non-empty observation string.

Steps where the tool produced no output (empty string) are excluded.

Source

pub fn actions_containing<'a>(&'a self, substring: &str) -> Vec<&'a ReActStep>

Return references to steps whose action string contains substring.

The comparison is case-sensitive. Returns an empty slice when no step matches or the session has no steps.

Source

pub fn avg_thought_bytes(&self) -> f64

Return the mean byte length of thought strings across all steps.

Returns 0.0 for sessions with no steps.

Source

pub fn steps_above_action_bytes(&self, min_bytes: usize) -> Vec<&ReActStep>

Return references to steps whose action byte length exceeds min_bytes.

Returns an empty Vec for sessions with no steps or when no step action exceeds min_bytes.

Source

pub fn steps_between(&self, start: usize, end: usize) -> Vec<&ReActStep>

Return the steps in the half-open index range [start, end).

Both bounds are clamped to [0, step_count]. Returns an empty Vec when start >= end or the session has no steps.

Source

pub fn step_observation_rate(&self) -> f64

Return the fraction of steps that have a non-empty observation string.

Returns 0.0 for sessions with no steps.

Source

pub fn steps_below_thought_bytes(&self, max_bytes: usize) -> Vec<&ReActStep>

Return references to steps whose thought byte length is strictly less than max_bytes.

Returns an empty Vec when no steps qualify or the session is empty.

Source

pub fn steps_with_duplicate_thoughts(&self) -> Vec<&ReActStep>

Return references to steps whose thought string duplicates an earlier step’s thought.

The first occurrence of each thought is not included; only the subsequent duplicates are returned. Useful for detecting repetitive reasoning loops.

Source

pub fn max_thought_bytes(&self) -> usize

Return the byte length of the longest thought in this session.

Returns 0 for an empty session or when all thoughts are empty strings.

Source

pub fn steps_by_action_prefix<'a>(&'a self, prefix: &str) -> Vec<&'a ReActStep>

Return references to steps whose action starts with prefix.

Useful for filtering tool-call steps by tool name prefix (e.g. all "search_" actions). Returns an empty Vec when no step qualifies.

Source

pub fn action_count(&self) -> usize

Return the number of tool-call steps in this session.

Counts steps whose action is non-empty and is not a FINAL_ANSWER. Returns 0 for an empty session.

Source

pub fn steps_above_observation_bytes(&self, min_bytes: usize) -> Vec<&ReActStep>

Return references to steps whose observation byte length exceeds min_bytes.

Useful for finding steps that produced unexpectedly large observations. Returns an empty Vec for an empty session or when no step qualifies.

Source

pub fn steps_matching_observation<'a>( &'a self, substr: &str, ) -> Vec<&'a ReActStep>

Return references to steps whose observation contains substr.

Case-sensitive substring match. Returns an empty Vec when no step matches or the session is empty.

Source

pub fn step_action_lengths(&self) -> Vec<usize>

Return the byte lengths of each step’s action field, in order.

Returns an empty Vec for an empty session.

Source

pub fn has_thought_starting_with(&self, prefix: &str) -> bool

Return true if any step’s thought starts with prefix.

Returns false for an empty session.

Source

pub fn step_count_above_action_bytes(&self, min_bytes: usize) -> usize

Return the number of steps whose action byte length exceeds min_bytes.

Returns 0 for an empty session.

Source

pub fn steps_with_empty_action(&self) -> Vec<&ReActStep>

Return all steps whose action field is empty.

Returns an empty Vec when no steps have an empty action.

Source

pub fn has_action_containing(&self, substr: &str) -> bool

Return true if any step’s action contains substr as a substring.

Returns false for an empty session.

Source

pub fn max_observation_chars(&self) -> usize

Return the maximum UTF-8 character count among all observation strings.

Returns 0 for an empty session.

Source

pub fn step_index_of_longest_thought(&self) -> Option<usize>

Return the 0-based index of the step with the longest thought by character count, or None for an empty session.

When multiple steps tie for the longest thought the smallest index wins.

Source

pub fn observation_word_counts(&self) -> Vec<usize>

Return the number of whitespace-delimited words in each observation, in step order.

Returns an empty Vec for an empty session.

Source

pub fn observation_starts_with_any(&self, prefixes: &[&str]) -> bool

Return true if any observation starts with one of the given prefixes.

Returns false for an empty session or when no prefix matches.

Source

pub fn has_repeated_actions(&self) -> bool

Return true if any action string appears more than once in the session.

Non-empty duplicate actions often signal a stuck or looping agent. Returns false for a session with fewer than two steps.

Source

pub fn thought_starts_with_any(&self, prefixes: &[&str]) -> bool

Return true if any step thought starts with one of the given prefixes.

Returns false for an empty session or when no prefix matches.

Source

pub fn action_word_count(&self) -> usize

Return the total number of whitespace-delimited words across all action strings in this session.

Returns 0 for an empty session.

Source

pub fn steps_above_thought_chars(&self, min: usize) -> usize

Return the number of steps whose thought character count exceeds min.

Returns 0 for an empty session.

Source

pub fn steps_with_non_empty_observation(&self) -> Vec<&ReActStep>

Return all steps that have a non-empty observation string.

Returns an empty Vec for an empty session.

Source

pub fn observations_containing(&self, substr: &str) -> Vec<&ReActStep>

Return all steps whose observation contains substr.

Returns an empty Vec for an empty session or no matches.

Source

pub fn thought_observation_ratio(&self) -> f64

Return the ratio of total thought characters to total observation characters.

Returns 0.0 when there are no observation characters to avoid division by zero.

Source

pub fn steps_matching_thought(&self, substr: &str) -> Vec<&ReActStep>

Return all steps whose thought contains substr as a substring.

Returns an empty Vec for an empty session or no matches.

Source

pub fn median_observation_chars(&self) -> usize

Return the median observation character count across all steps.

Returns 0 for an empty session. Uses the lower median when the step count is even.

Source

pub fn cumulative_thought_chars(&self) -> Vec<usize>

Return the cumulative sum of thought character counts, step by step.

The i-th element is the total thought characters from step 0 through step i inclusive. Returns an empty Vec for an empty session.

Source

pub fn count_steps_with_thought_containing(&self, substr: &str) -> usize

Return the number of steps whose thought contains substr.

Returns 0 for an empty session.

Source

pub fn min_observation_bytes(&self) -> usize

Return the smallest byte length of non-empty observation strings in this session.

Steps with an empty observation are excluded. Returns 0 if no non-empty observations exist.

Source

pub fn min_thought_bytes(&self) -> usize

Return the smallest byte length of non-empty thought strings in this session.

Steps with an empty thought are excluded. Returns 0 if no non-empty thoughts exist.

Source

pub fn proportion_empty_thoughts(&self) -> f64

Return the proportion of steps whose thought field is empty.

Returns 0.0 for an empty session.

Source

pub fn has_failed_steps(&self) -> bool

Return true if any step in this session is marked as failed.

A step is considered failed when its observation starts with "[error]" (the convention used by the built-in tool dispatcher).

Source

pub fn total_thought_chars(&self) -> usize

Return the total number of UTF-8 characters across all step thought fields.

Returns 0 for an empty session.

Source

pub fn total_action_chars(&self) -> usize

Return the total number of UTF-8 characters across all step action fields.

Returns 0 for an empty session.

Source

pub fn total_observation_chars(&self) -> usize

Return the total number of UTF-8 characters across all step observation fields.

Returns 0 for an empty session.

Source

pub fn action_byte_variance(&self) -> f64

Return the statistical variance of action byte lengths across all steps.

Useful for detecting inconsistent action sizes. Returns 0.0 for a session with fewer than two steps or all equal lengths.

Source

pub fn non_empty_action_count(&self) -> usize

Return the count of steps that have a non-empty action string.

Returns 0 for an empty session.

Source

pub fn total_step_bytes(&self) -> usize

Return the total byte count across all fields (thought + action + observation) for every step in the session.

Returns 0 for an empty session.

Source

pub fn last_thought_bytes(&self) -> usize

Return the byte length of the last step’s thought field, or 0 if the session has no steps.

Source

pub fn first_observation_bytes(&self) -> usize

Return the byte length of the first step’s observation field, or 0 if the session has no steps.

Source

pub fn has_step_with_empty_observation(&self) -> bool

Return true if any step has an empty observation field.

Useful for detecting incomplete ReAct traces where a tool produced no output.

Source

pub fn thought_to_action_byte_ratio(&self) -> f64

Return the ratio of total thought bytes to total action bytes.

Returns 0.0 when there are no action bytes (avoids division by zero).

Source

pub fn observation_above_bytes_count(&self, min_bytes: usize) -> usize

Return the number of steps whose observation byte length exceeds min_bytes.

Returns 0 when the session is empty or no step qualifies.

Source

pub fn steps_with_both_thought_and_action(&self) -> usize

Return the number of steps where both the thought and action fields are non-empty.

Returns 0 for an empty session.

Source

pub fn steps_with_observation_prefix(&self, prefix: &str) -> usize

Return the number of steps whose observation field starts with prefix.

Returns 0 for an empty session or when no step qualifies.

Source

pub fn observation_bytes_total(&self) -> usize

Return the total byte count of all observation fields across all steps.

Returns 0 for an empty session.

Source

pub fn first_thought_chars(&self) -> usize

Return the character count of the first step’s thought field.

Returns 0 for an empty session.

Source

pub fn last_observation_chars(&self) -> usize

Return the character count of the last step’s observation field.

Returns 0 for an empty session.

Source

pub fn observation_word_count_total(&self) -> usize

Return the total word count across all observation fields.

Words are split on whitespace. Returns 0 for an empty session.

Source

pub fn action_ends_with_count(&self, suffix: &str) -> usize

Return the count of steps whose action field ends with suffix.

Returns 0 for an empty session or when no step qualifies.

Source

pub fn avg_observation_words(&self) -> f64

Return the average word count per observation field across all steps.

Returns 0.0 for an empty session.

Source

pub fn thought_byte_variance(&self) -> f64

Return the statistical variance of thought byte lengths across all steps.

Returns 0.0 for a session with fewer than two steps.

Source

pub fn steps_above_thought_bytes(&self, min_bytes: usize) -> Vec<&ReActStep>

Return all steps whose thought byte length exceeds min_bytes.

Returns an empty Vec if no step qualifies.

Source

pub fn total_empty_steps(&self) -> usize

Return the number of steps where all three fields (thought, action, and observation) are empty strings.

Fully empty steps typically indicate a malformed or aborted iteration.

Source

pub fn action_starts_with_count(&self, prefix: &str) -> usize

Return the number of steps whose action begins with prefix.

Returns 0 for an empty session or when no action matches.

Source

pub fn longest_action(&self) -> Option<&str>

Return the longest action string in the session, or None if the session is empty.

When multiple steps share the maximum byte length, the first one is returned.

Source

pub fn thought_completeness(&self) -> f64

Return the proportion of steps that have a non-empty thought string.

Returns 0.0 for an empty session.

Source

pub fn final_answer_step_index(&self) -> Option<usize>

Return the 0-based index of the first FINAL_ANSWER step, or None if no such step exists in the session.

Useful when you need the position of the answer step rather than just testing whether one exists (see has_final_answer).

Source

pub fn step_duration_range_ms(&self) -> (u64, u64)

Return the (min, max) step duration range in milliseconds.

Returns (0, 0) for sessions with no steps.

Source

pub fn count_unique_thoughts(&self) -> usize

Return the number of distinct thought strings across all steps.

Two steps with identical thought text are counted once. Returns 0 for empty sessions.

Source

pub fn steps_with_empty_thoughts(&self) -> Vec<&ReActStep>

Return references to steps whose thought string is empty.

Useful for detecting steps where the model skipped the reasoning phase.

Source

pub fn steps_with_long_thoughts( &self, threshold_bytes: usize, ) -> Vec<&ReActStep>

Return references to steps whose thought byte length exceeds threshold_bytes.

Useful for identifying steps with unusually verbose reasoning traces.

Source

pub fn action_count_containing(&self, substring: &str) -> usize

Return the number of steps whose action string contains substring.

The comparison is case-sensitive. Returns 0 for empty sessions or when no step matches.

Source

pub fn total_thought_count(&self) -> usize

Return the number of steps that have a non-empty thought string.

Complement of steps_with_empty_thoughts. Returns 0 for empty sessions.

Source

pub fn has_thought_containing(&self, substring: &str) -> bool

Return true if any step’s thought field contains substring (case-sensitive).

Returns false for empty sessions or when no step matches.

Source

pub fn steps_with_action_length_above( &self, min_bytes: usize, ) -> Vec<&ReActStep>

Return references to steps whose action field is longer than min_bytes bytes.

Returns an empty Vec when no step qualifies.

Source

pub fn into_steps(self) -> Vec<ReActStep>

Consume this session and return its steps as an owned Vec.

Useful when the caller needs owned ReActStep values — for example to move them into another data structure — without cloning the entire list.

let steps = session.into_steps();
for step in steps { /* owned */ }
Source

pub fn iter_steps(&self) -> Iter<'_, ReActStep>

Return an iterator over the steps in this session.

Equivalent to session.steps.iter() but avoids exposing the raw field for callers who prefer the method-call style.

Source

pub fn has_at_least_steps(&self, n: usize) -> bool

Return true if the session has at least n steps.

More efficient than step_count() >= n because it uses steps.len() directly and is easy to read at the call site.

Source

pub fn all_observations_non_empty(&self) -> bool

Return true if every step in this session has a non-empty observation.

Returns true for an empty session (vacuously true).

Source

pub fn avg_combined_step_bytes(&self) -> f64

Return the average combined byte length (thought + action + observation) per step.

Returns 0.0 for an empty session.

Source

pub fn shortest_observation_step(&self) -> Option<&ReActStep>

Return a reference to the step with the shortest observation field.

When multiple steps share the minimum observation length the first is returned. Returns None for an empty session.

Source

pub fn unique_observation_count(&self) -> usize

Return the number of distinct observation strings across all steps.

Returns 0 for an empty session.

Source

pub fn avg_thought_word_count(&self) -> f64

Return the average number of whitespace-delimited words per thought.

Returns 0.0 for an empty session.

Source

pub fn observation_contains_any(&self, terms: &[&str]) -> bool

Return true if any step’s observation contains at least one of the provided terms (case-sensitive substring match).

Returns false for an empty session or an empty terms slice.

Source

pub fn step_at_index(&self, index: usize) -> Option<&ReActStep>

Return the step at index, or None if the index is out of bounds.

Source

pub fn thought_contains_all(&self, terms: &[&str]) -> bool

Return true if any step’s thought contains all of the provided terms as substrings (case-sensitive).

Returns false for an empty terms slice or an empty session.

Source

pub fn action_contains_any(&self, terms: &[&str]) -> bool

Return true if any step’s action contains at least one of the provided terms (case-sensitive substring match).

Returns false for an empty terms slice or an empty session.

Source

pub fn max_thought_chars(&self) -> usize

Return the maximum thought length in characters across all steps.

Returns 0 for an empty session.

Source

pub fn min_thought_chars(&self) -> usize

Return the minimum thought length in characters, considering only steps that have a non-empty thought.

Returns 0 if there are no non-empty thoughts.

Source

pub fn avg_action_chars(&self) -> f64

Return the average number of Unicode chars in the action field across all steps.

Returns 0.0 for an empty session.

Source

pub fn avg_observation_chars(&self) -> f64

Return the average number of Unicode chars in the observation field across all steps.

Returns 0.0 for an empty session.

Source

pub fn step_with_longest_action(&self) -> Option<&ReActStep>

Return a reference to the step whose action string is the longest (by Unicode char count), or None for an empty session.

When multiple steps tie, the first is returned.

Source

pub fn action_ends_with(&self, suffix: &str) -> bool

Return true if any step’s action ends with the given suffix.

Source

pub fn thought_ends_with(&self, suffix: &str) -> bool

Return true if any step’s thought ends with the given suffix.

Source

pub fn has_step_with_both(&self, thought_term: &str, action_term: &str) -> bool

Return true if any step’s thought contains thought_term AND that same step’s action contains action_term.

Source

pub fn step_count_with_observation_longer_than(&self, min_bytes: usize) -> usize

Return the number of steps whose observation byte length strictly exceeds min_bytes.

Returns 0 for an empty session.

Source

pub fn thought_word_counts(&self) -> Vec<usize>

Return a Vec of word counts for each step’s thought, in order.

Source

pub fn steps_sorted_by_thought_len(&self) -> Vec<&ReActStep>

Return steps sorted by thought byte length in ascending order.

Source

pub fn steps_with_thought_longer_than( &self, min_bytes: usize, ) -> Vec<&ReActStep>

Return all steps whose thought byte length strictly exceeds min_bytes.

Source

pub fn steps_with_action_containing(&self, substr: &str) -> Vec<&ReActStep>

Return all steps whose action contains substr as a substring.

Source

pub fn observation_max_chars(&self) -> usize

Return the maximum observation length in Unicode chars across all steps. Returns 0 for an empty session.

Source

pub fn observation_min_chars(&self) -> usize

Return the minimum observation length in Unicode chars, considering only steps with a non-empty observation. Returns 0 if no non-empty observations exist.

Source

pub fn action_word_counts(&self) -> Vec<usize>

Return a Vec of word counts for each step’s action, in order.

Source

pub fn thought_avg_chars(&self) -> f64

Return the average number of Unicode chars in the thought field across all steps. Returns 0.0 for an empty session.

Source

pub fn thought_byte_range(&self) -> (usize, usize)

Return (min_bytes, max_bytes) of the thought field across all steps.

Returns (0, 0) for an empty session.

Trait Implementations§

Source§

impl Clone for AgentSession

Source§

fn clone(&self) -> AgentSession

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AgentSession

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for AgentSession

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for AgentSession

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,