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: usizeMaximum number of Thought-Action-Observation cycles.
model: StringModel identifier passed to the inference function.
system_prompt: StringSystem prompt injected at the start of the conversation.
max_memory_recalls: usizeMaximum 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
impl AgentConfig
Sourcepub fn new(max_iterations: usize, model: impl Into<String>) -> Self
pub fn new(max_iterations: usize, model: impl Into<String>) -> Self
Create a new config with sensible defaults.
Sourcepub fn with_system_prompt(self, prompt: impl Into<String>) -> Self
pub fn with_system_prompt(self, prompt: impl Into<String>) -> Self
Override the system prompt.
Sourcepub fn with_max_memory_recalls(self, n: usize) -> Self
pub fn with_max_memory_recalls(self, n: usize) -> Self
Set the maximum number of episodic memories injected per run.
Sourcepub fn with_max_memory_tokens(self, n: usize) -> Self
pub fn with_max_memory_tokens(self, n: usize) -> Self
Set a maximum token budget for injected memories (~4 chars/token heuristic).
Sourcepub fn with_loop_timeout(self, d: Duration) -> Self
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(...)).
Sourcepub fn with_loop_timeout_secs(self, secs: u64) -> Self
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.
Sourcepub fn with_loop_timeout_ms(self, ms: u64) -> Self
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.
Sourcepub fn with_max_iterations(self, n: usize) -> Self
pub fn with_max_iterations(self, n: usize) -> Self
Set the maximum number of ReAct iterations.
Sourcepub fn max_iterations(&self) -> usize
pub fn max_iterations(&self) -> usize
Return the configured maximum number of ReAct iterations.
Sourcepub fn with_temperature(self, t: f32) -> Self
pub fn with_temperature(self, t: f32) -> Self
Set the model sampling temperature.
Sourcepub fn with_max_tokens(self, n: usize) -> Self
pub fn with_max_tokens(self, n: usize) -> Self
Set the maximum output tokens.
Sourcepub fn with_request_timeout(self, d: Duration) -> Self
pub fn with_request_timeout(self, d: Duration) -> Self
Set the per-inference timeout.
Sourcepub fn with_request_timeout_secs(self, secs: u64) -> Self
pub fn with_request_timeout_secs(self, secs: u64) -> Self
Set the per-inference timeout using seconds.
Convenience wrapper around with_request_timeout.
Sourcepub fn with_request_timeout_ms(self, ms: u64) -> Self
pub fn with_request_timeout_ms(self, ms: u64) -> Self
Set the per-inference timeout using milliseconds.
Convenience wrapper around with_request_timeout.
Sourcepub fn with_max_context_chars(self, n: usize) -> Self
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.
Sourcepub fn with_model(self, model: impl Into<String>) -> Self
pub fn with_model(self, model: impl Into<String>) -> Self
Change the model used for completions.
Sourcepub fn clone_with_model(&self, model: impl Into<String>) -> Self
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.
Sourcepub fn clone_with_system_prompt(&self, prompt: impl Into<String>) -> Self
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.
Sourcepub fn clone_with_max_iterations(&self, n: usize) -> Self
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.
Sourcepub fn with_stop_sequences(self, sequences: Vec<String>) -> Self
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).
Sourcepub fn is_valid(&self) -> bool
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.
Sourcepub fn validate(&self) -> Result<(), AgentRuntimeError>
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.
Sourcepub fn has_loop_timeout(&self) -> bool
pub fn has_loop_timeout(&self) -> bool
Return true if a loop timeout has been configured.
Sourcepub fn has_stop_sequences(&self) -> bool
pub fn has_stop_sequences(&self) -> bool
Return true if at least one stop sequence has been configured.
Sourcepub fn stop_sequence_count(&self) -> usize
pub fn stop_sequence_count(&self) -> usize
Return the number of configured stop sequences.
Sourcepub fn is_single_shot(&self) -> bool
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.
Sourcepub fn has_temperature(&self) -> bool
pub fn has_temperature(&self) -> bool
Return true if a sampling temperature has been configured.
Sourcepub fn temperature(&self) -> Option<f32>
pub fn temperature(&self) -> Option<f32>
Return the configured sampling temperature, if any.
Sourcepub fn max_tokens(&self) -> Option<usize>
pub fn max_tokens(&self) -> Option<usize>
Return the configured maximum output tokens, if any.
Sourcepub fn has_request_timeout(&self) -> bool
pub fn has_request_timeout(&self) -> bool
Return true if a per-inference request timeout has been configured.
Sourcepub fn request_timeout(&self) -> Option<Duration>
pub fn request_timeout(&self) -> Option<Duration>
Return the configured per-inference request timeout, if any.
Sourcepub fn has_max_context_chars(&self) -> bool
pub fn has_max_context_chars(&self) -> bool
Return true if a maximum context character limit has been configured.
Sourcepub fn max_context_chars(&self) -> Option<usize>
pub fn max_context_chars(&self) -> Option<usize>
Return the configured maximum context character limit, if any.
Sourcepub fn remaining_iterations_after(&self, n: usize) -> usize
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.
Sourcepub fn system_prompt(&self) -> &str
pub fn system_prompt(&self) -> &str
Return the configured system prompt string.
Sourcepub fn system_prompt_is_empty(&self) -> bool
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.
Sourcepub fn loop_timeout_ms(&self) -> u64
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.
Sourcepub fn total_timeout_ms(&self) -> u64
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.
Sourcepub fn model_is(&self, name: &str) -> bool
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.
Sourcepub fn system_prompt_word_count(&self) -> usize
pub fn system_prompt_word_count(&self) -> usize
Return the number of whitespace-delimited words in system_prompt.
Returns 0 for an empty prompt.
Sourcepub fn iteration_budget_remaining(&self, steps_done: usize) -> usize
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.
Sourcepub fn is_minimal(&self) -> bool
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.
Sourcepub fn model_starts_with(&self, prefix: &str) -> bool
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")).
Sourcepub fn exceeds_iteration_limit(&self, steps_done: usize) -> bool
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.
Sourcepub fn token_budget_configured(&self) -> bool
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.
Sourcepub fn max_tokens_or_default(&self, default: usize) -> usize
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.
Sourcepub fn effective_temperature(&self) -> f32
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>.
Sourcepub fn system_prompt_starts_with(&self, prefix: &str) -> bool
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.
Sourcepub fn max_iterations_above(&self, n: usize) -> bool
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.
Sourcepub fn stop_sequences_contain(&self, s: &str) -> bool
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.
Sourcepub fn system_prompt_byte_len(&self) -> usize
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).
Sourcepub fn has_valid_temperature(&self) -> bool
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
impl Clone for AgentConfig
Source§fn clone(&self) -> AgentConfig
fn clone(&self) -> AgentConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more