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

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