Skip to main content

AgentState

Struct AgentState 

Source
pub struct AgentState {
    pub system_prompt: RwLock<String>,
    pub tools: RwLock<Vec<AgentTool>>,
    pub messages: RwLock<Vec<AgentMessage>>,
    pub is_streaming: AtomicBool,
    pub stream_message: RwLock<Option<AgentMessage>>,
    pub pending_tool_calls: RwLock<HashSet<String>>,
    pub error: RwLock<Option<String>>,
    pub max_messages: AtomicUsize,
}
Expand description

Agent state — pure runtime state without configuration.

Configuration values (model, thinking_level) live in [AgentConfig] (the single source of truth). This struct only holds conversational and streaming runtime state.

Fields§

§system_prompt: RwLock<String>

System prompt.

§tools: RwLock<Vec<AgentTool>>

Available tools.

§messages: RwLock<Vec<AgentMessage>>

Conversation messages.

§is_streaming: AtomicBool

Whether currently streaming.

§stream_message: RwLock<Option<AgentMessage>>

Current streaming message.

§pending_tool_calls: RwLock<HashSet<String>>

Pending tool call IDs.

§error: RwLock<Option<String>>

Last error.

§max_messages: AtomicUsize

Maximum number of messages in conversation history. 0 = unlimited. When exceeded, oldest messages are drained.

Implementations§

Source§

impl AgentState

Source

pub fn new() -> Self

Create a new agent state with default values.

Source

pub fn set_system_prompt(&self, prompt: impl Into<String>)

Set the system prompt.

Source

pub fn set_tools(&self, tools: Vec<AgentTool>)

Set the tools.

Source

pub fn add_message(&self, message: AgentMessage)

Add a message, enforcing the max_messages limit. When the limit is exceeded, oldest messages are drained (FIFO).

Source

pub fn set_max_messages(&self, max: usize)

Set the maximum number of messages in conversation history. 0 = unlimited.

Source

pub fn get_max_messages(&self) -> usize

Get the current max_messages limit (0 = unlimited).

Source

pub fn replace_messages(&self, messages: Vec<AgentMessage>)

Replace all messages.

Source

pub fn clear_messages(&self)

Clear all messages.

Source

pub fn reset(&self)

Reset the runtime state (messages, streaming, errors).

Does NOT reset model or thinking_level (those live in AgentConfig).

Source

pub fn is_streaming(&self) -> bool

Check if currently streaming.

Source

pub fn set_streaming(&self, value: bool)

Set streaming state.

Source

pub fn message_count(&self) -> usize

Get message count.

Trait Implementations§

Source§

impl Clone for AgentState

NOTE: This Clone implementation acquires each lock independently, so the resulting clone is NOT a single atomic snapshot. For a consistent point-in-time snapshot, use [Agent::snapshot()].

Source§

fn clone(&self) -> Self

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 AgentState

Source§

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

Formats the value using the given formatter. Read more
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<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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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: 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: 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> Same for T

Source§

type Output = T

Should always be Self
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