Skip to main content

AgentState

Struct AgentState 

Source
pub struct AgentState { /* private fields */ }
Expand description

Agent runtime state.

Manages all mutable state during agent execution. All fields are private to enforce encapsulation.

Implementations§

Source§

impl AgentState

Source

pub fn new() -> Self

Create a new empty state.

Source

pub fn add_message(&mut self, message: Message)

Add a message to history.

Source

pub fn messages(&self) -> &Vec<Message>

Get reference to message history.

Source

pub fn messages_mut(&mut self) -> &mut Vec<Message>

Get mutable reference to message history.

Source

pub fn set_messages(&mut self, messages: Vec<Message>)

Replace message history (used in compression).

This method validates and cleans orphaned tool results/tool uses before setting the message history to prevent API errors.

Source

pub fn track_usage(&self, usage: &Usage)

Track token usage from API response.

Source

pub fn total_input_tokens(&self) -> u64

Get total input tokens consumed.

Source

pub fn total_output_tokens(&self) -> u64

Get total output tokens generated.

Source

pub fn last_input_tokens(&self) -> u64

Get last input tokens (for compression decisions).

Source

pub fn set_total_input_tokens(&self, value: u64)

Set total input tokens (used after compression).

Source

pub fn set_total_output_tokens(&self, value: u64)

Set total output tokens.

Source

pub fn set_last_input_tokens(&self, value: u64)

Set last input tokens (used after compression).

Source

pub fn mark_tool_input_previewed(&mut self, tool_id: String)

Mark a tool input as previewed during streaming.

Source

pub fn was_tool_input_previewed(&self, tool_id: &str) -> bool

Check if a tool input was already previewed.

Source

pub fn remove_previewed_tool_input(&mut self, tool_id: &str) -> bool

Remove a tool input from previewed set (after processing).

Source

pub fn increment_todo_reminder(&mut self, todo_hash: String) -> usize

Increment todo reminder count for a todo item. Returns the new count.

Source

pub fn todo_reminder_count(&self, todo_hash: &str) -> usize

Get todo reminder count for a todo item.

Source

pub fn todo_reminder_count_map(&self) -> &HashMap<String, usize>

Get reference to the entire todo reminder count map.

Source

pub fn todo_reminder_count_map_mut(&mut self) -> &mut HashMap<String, usize>

Get mutable reference to the entire todo reminder count map.

Source

pub fn is_todo_reminder_limit_reached( &self, todo_hash: &str, max_reminders: usize, ) -> bool

Check if todo reminder limit reached.

Source

pub fn read_history(&self) -> &ReadHistoryTracker

Get reference to read history tracker.

Source

pub fn read_history_mut(&mut self) -> &mut ReadHistoryTracker

Get mutable reference to read history tracker.

Source

pub fn add_pending_input(&mut self, input: String)

Add a pending input to queue.

Source

pub fn has_pending_inputs(&self) -> bool

Check if there are pending inputs.

Source

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

Get reference to pending inputs vector.

Source

pub fn pending_inputs_vec_mut(&mut self) -> &mut Vec<String>

Get mutable reference to pending inputs vector.

Source

pub fn take_pending_inputs(&mut self) -> Vec<String>

Take all pending inputs (drains the queue).

Source

pub fn pending_input_count(&self) -> usize

Get count of pending inputs.

Source

pub fn message_count(&self) -> usize

Get message count.

Source

pub fn clear(&mut self)

Clear all state (reset to initial state).

Trait Implementations§

Source§

impl Default for AgentState

Source§

fn default() -> Self

Returns the “default value” for a type. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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