Skip to main content

AgentConfig

Struct AgentConfig 

Source
pub struct AgentConfig {
    pub max_iterations: usize,
    pub model: String,
    pub system_prompt: String,
    pub max_memory_recalls: usize,
    pub max_memory_tokens: Option<usize>,
    pub loop_timeout: Option<Duration>,
    pub temperature: Option<f32>,
    pub max_tokens: Option<usize>,
    pub request_timeout: Option<Duration>,
    pub max_context_chars: Option<usize>,
    pub stop_sequences: Vec<String>,
}
Expand description

Configuration for the ReAct agent loop.

Fields§

§max_iterations: usize

Maximum number of Thought-Action-Observation cycles.

§model: String

Model identifier passed to the inference function.

§system_prompt: String

System prompt injected at the start of the conversation.

§max_memory_recalls: usize

Maximum number of episodic memories to inject into the prompt. Keeping this small prevents silent token-budget overruns. Default: 3.

§max_memory_tokens: Option<usize>

Maximum token budget for injected memories.

Token counting is delegated to the TokenEstimator configured on AgentRuntimeBuilder (default: 1 token ≈ 4 bytes). None means no limit.

§loop_timeout: Option<Duration>

Optional wall-clock timeout for the entire loop. If the loop runs longer than this duration, it returns Err(AgentRuntimeError::AgentLoop("loop timeout ...")).

§temperature: Option<f32>

Model sampling temperature.

§max_tokens: Option<usize>

Maximum output tokens.

§request_timeout: Option<Duration>

Per-inference timeout.

§max_context_chars: Option<usize>

Maximum number of characters allowed in the running context string.

When set, the oldest Thought/Action/Observation turns are trimmed from the beginning of the context (after the system prompt) to keep the total length below this limit. This prevents silent context-window overruns in long-running agents. None (default) means no limit.

§stop_sequences: Vec<String>

Stop sequences passed to the inference function.

The model stops generating when it produces any of these strings. An empty Vec (default) means no stop sequences.

Implementations§

Source§

impl AgentConfig

Source

pub fn new(max_iterations: usize, model: impl Into<String>) -> Self

Create a new config with sensible defaults.

Source

pub fn with_system_prompt(self, prompt: impl Into<String>) -> Self

Override the system prompt.

Source

pub fn with_max_memory_recalls(self, n: usize) -> Self

Set the maximum number of episodic memories injected per run.

Source

pub fn with_max_memory_tokens(self, n: usize) -> Self

Set a maximum token budget for injected memories (~4 chars/token heuristic).

Source

pub fn with_loop_timeout(self, d: Duration) -> Self

Set a wall-clock timeout for the entire ReAct loop.

If the loop has not reached FINAL_ANSWER within this duration, ReActLoop::run returns Err(AgentRuntimeError::AgentLoop(...)).

Source

pub fn with_loop_timeout_secs(self, secs: u64) -> Self

Set a wall-clock timeout for the entire ReAct loop using seconds.

Convenience wrapper around with_loop_timeout.

Source

pub fn with_loop_timeout_ms(self, ms: u64) -> Self

Set a wall-clock timeout for the entire ReAct loop using milliseconds.

Convenience wrapper around with_loop_timeout.

Source

pub fn with_max_iterations(self, n: usize) -> Self

Set the maximum number of ReAct iterations.

Source

pub fn max_iterations(&self) -> usize

Return the configured maximum number of ReAct iterations.

Source

pub fn with_temperature(self, t: f32) -> Self

Set the model sampling temperature.

Source

pub fn with_max_tokens(self, n: usize) -> Self

Set the maximum output tokens.

Source

pub fn with_request_timeout(self, d: Duration) -> Self

Set the per-inference timeout.

Source

pub fn with_request_timeout_secs(self, secs: u64) -> Self

Set the per-inference timeout using seconds.

Convenience wrapper around with_request_timeout.

Source

pub fn with_request_timeout_ms(self, ms: u64) -> Self

Set the per-inference timeout using milliseconds.

Convenience wrapper around with_request_timeout.

Source

pub fn with_max_context_chars(self, n: usize) -> Self

Set a maximum character limit for the running context string.

When the context exceeds this length the oldest Thought/Action/Observation turns are trimmed from the front (after the initial system prompt + user turn) so the context stays under the limit.

Source

pub fn with_model(self, model: impl Into<String>) -> Self

Change the model used for completions.

Source

pub fn clone_with_model(&self, model: impl Into<String>) -> Self

Clone this config with only the model field changed.

Useful when the same configuration is shared across multiple agents that differ only in the model used for inference.

Source

pub fn clone_with_system_prompt(&self, prompt: impl Into<String>) -> Self

Clone this config with only the system_prompt field changed.

Useful when the same configuration is shared across multiple agents that differ only in the system prompt used for their sessions.

Source

pub fn clone_with_max_iterations(&self, n: usize) -> Self

Clone this config with only the max_iterations field changed.

Useful when the same configuration is shared across multiple agents that differ only in the iteration budget — for example, a quick draft agent and a thorough research agent backed by the same model.

Source

pub fn with_stop_sequences(self, sequences: Vec<String>) -> Self

Set stop sequences for inference requests.

The model will stop generating when it produces any of these strings. Defaults to an empty list (no stop sequences).

Source

pub fn is_valid(&self) -> bool

Return true if this configuration is logically valid.

Specifically, max_iterations must be at least 1 and model must be a non-empty string.

Source

pub fn validate(&self) -> Result<(), AgentRuntimeError>

Validate the configuration, returning a structured error on failure.

Checks the same invariants as is_valid but returns Err(AgentRuntimeError::AgentLoop) with a descriptive message instead of false, making it more useful in ?-propagation chains.

Source

pub fn has_loop_timeout(&self) -> bool

Return true if a loop timeout has been configured.

Source

pub fn has_stop_sequences(&self) -> bool

Return true if at least one stop sequence has been configured.

Source

pub fn stop_sequence_count(&self) -> usize

Return the number of configured stop sequences.

Source

pub fn is_single_shot(&self) -> bool

Return true if the agent runs at most one iteration.

A single-shot agent executes exactly one Thought-Action-Observation cycle and then terminates regardless of whether a FINAL_ANSWER was produced.

Source

pub fn has_temperature(&self) -> bool

Return true if a sampling temperature has been configured.

Source

pub fn temperature(&self) -> Option<f32>

Return the configured sampling temperature, if any.

Source

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

Return the configured maximum output tokens, if any.

Source

pub fn has_request_timeout(&self) -> bool

Return true if a per-inference request timeout has been configured.

Source

pub fn request_timeout(&self) -> Option<Duration>

Return the configured per-inference request timeout, if any.

Source

pub fn has_max_context_chars(&self) -> bool

Return true if a maximum context character limit has been configured.

Source

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

Return the configured maximum context character limit, if any.

Source

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

Return the number of iterations still available after n have been completed.

Uses saturating subtraction so values beyond max_iterations return 0 rather than wrapping.

Source

pub fn system_prompt(&self) -> &str

Return the configured system prompt string.

Source

pub fn system_prompt_is_empty(&self) -> bool

Return true if the system prompt is empty or whitespace-only.

A default AgentConfig has an empty system prompt.

Source

pub fn model(&self) -> &str

Return the model name this config targets.

Source

pub fn loop_timeout_ms(&self) -> u64

Return the loop-level timeout in milliseconds, or 0 if no timeout is configured.

This is the loop_timeout field expressed as milliseconds. Useful for budget-calculation code that needs a uniform numeric representation of the timeout budget.

Source

pub fn total_timeout_ms(&self) -> u64

Return the total wall-clock budget for all iterations in milliseconds.

Computed as loop_timeout_ms + max_iterations * request_timeout_ms, where a missing timeout contributes 0. This is a rough upper bound — actual latency depends on model response times and tool execution.

Source

pub fn model_is(&self, name: &str) -> bool

Return true if the configured model name equals name (case-sensitive).

A convenience predicate for conditional logic that branches on the model being used, e.g. choosing different prompt strategies per model family.

Source

pub fn system_prompt_word_count(&self) -> usize

Return the number of whitespace-delimited words in system_prompt.

Returns 0 for an empty prompt.

Source

pub fn iteration_budget_remaining(&self, steps_done: usize) -> usize

Return the number of iterations still available after steps_done steps have been completed.

Saturates at 0 — never returns a negative-equivalent value even if steps_done exceeds max_iterations.

Source

pub fn is_minimal(&self) -> bool

Return true if this config is “minimal” — no system prompt and only one allowed iteration.

Useful as a quick sanity-check predicate in tests and diagnostics.

Source

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

Return true if the configured model name starts with prefix.

Useful for branching logic based on provider family without an exact string match (e.g. config.model_starts_with("claude") or config.model_starts_with("gpt")).

Source

pub fn exceeds_iteration_limit(&self, steps_done: usize) -> bool

Return true if steps_done meets or exceeds max_iterations.

Useful as a termination guard in agent loop implementations.

Source

pub fn token_budget_configured(&self) -> bool

Return true if a token budget is configured via either max_tokens or max_context_chars.

When false the agent will not enforce a token ceiling, which may cause silent overruns for very long conversations.

Source

pub fn max_tokens_or_default(&self, default: usize) -> usize

Return max_tokens if set, or default otherwise.

Convenience helper for callers that always need a concrete token limit and want to fall back to a safe default when none has been configured.

Source

pub fn effective_temperature(&self) -> f32

Return the configured temperature, or 1.0 if none has been set.

Provides a safe default for inference calls that always need a concrete value without requiring callers to unwrap an Option<f32>.

Source

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

Return true if the system prompt starts with the given prefix.

Useful for routing or classification logic based on prompt preambles.

Source

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

Return true if max_iterations is strictly greater than n.

Handy for guard conditions: e.g. config.max_iterations_above(1) checks that multi-step reasoning is allowed.

Source

pub fn stop_sequences_contain(&self, s: &str) -> bool

Return true if any configured stop sequence equals s.

Returns false when no stop sequences have been configured.

Source

pub fn system_prompt_byte_len(&self) -> usize

Return the byte length of the system prompt string.

Returns 0 when no system prompt has been configured (the default is an empty string).

Source

pub fn has_valid_temperature(&self) -> bool

Return true if a temperature has been configured and it falls within the valid range [0.0, 2.0] (inclusive).

Returns false when no temperature has been set.

Trait Implementations§

Source§

impl Clone for AgentConfig

Source§

fn clone(&self) -> AgentConfig

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 AgentConfig

Source§

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

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

impl<'de> Deserialize<'de> for AgentConfig

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 AgentConfig

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