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: AtomicBoolWhether 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: AtomicUsizeMaximum number of messages in conversation history. 0 = unlimited. When exceeded, oldest messages are drained.
Implementations§
Source§impl AgentState
impl AgentState
Sourcepub fn set_system_prompt(&self, prompt: impl Into<String>)
pub fn set_system_prompt(&self, prompt: impl Into<String>)
Set the system prompt.
Sourcepub fn add_message(&self, message: AgentMessage)
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).
Sourcepub fn set_max_messages(&self, max: usize)
pub fn set_max_messages(&self, max: usize)
Set the maximum number of messages in conversation history. 0 = unlimited.
Sourcepub fn get_max_messages(&self) -> usize
pub fn get_max_messages(&self) -> usize
Get the current max_messages limit (0 = unlimited).
Sourcepub fn replace_messages(&self, messages: Vec<AgentMessage>)
pub fn replace_messages(&self, messages: Vec<AgentMessage>)
Replace all messages.
Sourcepub fn clear_messages(&self)
pub fn clear_messages(&self)
Clear all messages.
Sourcepub fn reset(&self)
pub fn reset(&self)
Reset the runtime state (messages, streaming, errors).
Does NOT reset model or thinking_level (those live in AgentConfig).
Sourcepub fn is_streaming(&self) -> bool
pub fn is_streaming(&self) -> bool
Check if currently streaming.
Sourcepub fn set_streaming(&self, value: bool)
pub fn set_streaming(&self, value: bool)
Set streaming state.
Sourcepub fn message_count(&self) -> usize
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()].
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()].