Skip to main content

AgentConfig

Struct AgentConfig 

Source
pub struct AgentConfig {
    pub max_iterations: usize,
    pub max_retries: u32,
    pub retry_delay_ms: u64,
    pub max_tool_result_size: usize,
    pub max_todo_reminders: usize,
    pub iteration_warning_threshold: usize,
    pub compression: CompressionConfig,
    pub max_tokens: u32,
    pub context_size_override: Option<u32>,
    pub think: bool,
}
Expand description

Agent runtime configuration.

Controls iteration limits, retry behavior, size thresholds, and compression settings. All defaults match the original hardcoded values for backward compatibility.

Fields§

§max_iterations: usize

Maximum number of iterations in the main loop.

Default: 200

Why this value?

  • Sufficient for most common tasks (file edits, code review, simple builds)
  • Prevents infinite loops and runaway operations
  • Balances task completion with resource efficiency

What happens when limit is reached?

  • Agent stops execution gracefully
  • User receives detailed warning message
  • Can continue, break down task, or resume

Examples:

  • Simple task (edit file): ~5-10 iterations
  • Medium task (refactor module): ~15-30 iterations
  • Complex task (build system): ~40-50 iterations (may hit limit)
§max_retries: u32

Maximum retry attempts for API calls.

Default: 5

Why this value?

  • Handles transient network failures
  • Balances resilience with response time
  • Most failures resolve within 2-3 retries
§retry_delay_ms: u64

Delay between retry attempts (milliseconds).

Default: 1000ms

Why this value?

  • Gives API server time to recover
  • Not too long to frustrate users
  • Often used with exponential backoff
§max_tool_result_size: usize

Maximum size for tool execution results (bytes).

Default: 50,000 (50KB)

Why this value?

  • Prevents oversized responses from breaking API calls
  • Fits within typical context window limits
  • Most tool results are <10KB

Truncation behavior:

  • Results larger than this are truncated
  • Truncation message added: “⚠️ Output truncated (X bytes total)”
  • User can request specific portions if needed
§max_todo_reminders: usize

Maximum number of todo reminders per todo item.

Default: 2

Why this value?

  • Prevents infinite loops when model doesn’t update todo status
  • Gives model multiple chances to notice pending work
  • After limit, stops reminding (assumes model won’t update)
§iteration_warning_threshold: usize

Iteration count threshold for warning user.

Default: max_iterations - 10 (190)

Why this value?

  • Warns user 10 iterations before limit
  • Gives time to decide: continue, break down task, or cancel
  • Prevents surprising cutoff at exactly max_iterations
§compression: CompressionConfig

Context compression configuration.

Controls when and how to compress long conversations. See CompressionConfig for details.

§max_tokens: u32

Maximum tokens for API responses.

Default: 4096 (from QUICK_ACTION_MAX_TOKENS)

§context_size_override: Option<u32>

Override for context window size.

Default: None (use provider’s default)

§think: bool

Enable thinking mode for extended reasoning.

Default: false

Implementations§

Source§

impl AgentConfig

Source

pub fn new( max_tokens: u32, context_size_override: Option<u32>, think: bool, compression: CompressionConfig, ) -> Self

Create a new config with all settings.

Source

pub fn with_max_iterations(max_iterations: usize) -> Self

Create a new config with custom max_iterations.

Automatically adjusts iteration_warning_threshold to max_iterations - 10.

Source

pub fn with_compression(compression: CompressionConfig) -> Self

Create a new config with custom compression settings.

Source

pub fn simple_task() -> Self

Create a config optimized for simple tasks.

Use for: file edits, quick queries, simple tool calls. Characteristics: lower iteration limit, smaller result size.

Source

pub fn complex_task() -> Self

Create a config optimized for complex tasks.

Use for: refactoring, build systems, multi-file changes. Characteristics: higher iteration limit, larger result size.

Source

pub fn max_tokens(&self) -> u32

Get max tokens for API responses.

Source

pub fn context_size_override(&self) -> Option<u32>

Get context size override.

Source

pub fn think(&self) -> bool

Get thinking mode flag.

Source

pub fn compression_config(&self) -> &CompressionConfig

Get compression config.

Source

pub fn compression_config_mut(&mut self) -> &mut CompressionConfig

Get mutable compression config.

Trait Implementations§

Source§

impl Clone for AgentConfig

Source§

fn clone(&self) -> AgentConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 Default for AgentConfig

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> 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> 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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