Skip to main content

AgentConfig

Struct AgentConfig 

Source
pub struct AgentConfig {
Show 15 fields pub system_prompt: Option<String>, pub system_prompt_file: Option<PathBuf>, pub max_turns: u32, pub max_tokens: u32, pub effort: Option<Effort>, pub thinking: bool, pub cache_prompt: bool, pub force_final_answer: bool, pub max_output_tokens: Option<u64>, pub max_cost_usd: Option<f64>, pub compact_at_tokens: Option<u64>, pub timezone: Option<String>, pub compact_keep_recent: usize, pub loop_guard: bool, pub compact_validate: bool,
}

Fields§

§system_prompt: Option<String>§system_prompt_file: Option<PathBuf>

Read the system prompt from a file. Wins over system_prompt.

§max_turns: u32

Hard stop on runaway loops: how many model turns one run may take.

§max_tokens: u32§effort: Option<Effort>§thinking: bool§cache_prompt: bool

Mark the tools + system prefix as cacheable.

§force_final_answer: bool

When the turn budget runs out, spend one more turn with the tools removed so the model has to answer with what it has. Without this a model that never stops searching returns nothing at all.

§max_output_tokens: Option<u64>

Stop once this many output tokens have been generated in one run. max_turns bounds the number of round trips; this bounds their size, which is what actually runs up a bill.

§max_cost_usd: Option<f64>

Stop once one run has cost this much. Requires prices on the provider.

§compact_at_tokens: Option<u64>

Summarise the middle of the conversation once the prompt passes this many tokens.

Measured against what the provider reported for the last turn rather than an estimate, so it tracks the real prompt including cached tokens. Unset by default: compaction is lossy, and silently paraphrasing someone’s conversation because it got long is a decision they should make. Set it to roughly two thirds of the model’s context window — or set context_window on the provider and let AgentConfig::compact_at work it out.

§timezone: Option<String>

IANA timezone name for the user, e.g. America/New_York. Unset means the machine’s. See AgentConfig::timezone.

§compact_keep_recent: usize

Turns kept verbatim after a compaction. The recent ones are where the work is; a summary of the last two turns is worse than the turns.

§loop_guard: bool

Stop a run that repeats an identical tool call, with an identical result, right after a compaction (StopCause::Loop).

On by default — the asymmetry is deliberate. A general repeated-call detector would need a measurement to justify watching all of ordinary work; this one exists to escape the specific loop that burns unbounded tokens at the largest prompts a run will ever send, and a no-config user should get that protection. Identical arguments with a changing result is polling and never trips it.

§compact_validate: bool

Check each summary against the transcript it replaces before installing it, and regenerate once with the omissions named.

Summaries fail by omission — they preserve what is true and drop task-critical specifics — and the producer cannot see its own gaps. A separate grounded comparison can: it reads both texts side by side, which is a different task from generating either. Measured elsewhere (Slipstream) at +6.4–8.8 points on SWE-bench Verified for under 1% latency, with ~90% of catches being omissions. Costs one extra request per compaction, two when a regeneration is needed.

Implementations§

Source§

impl AgentConfig

Source

pub const COMPACT_FRACTION: f64 = 0.66

Fraction of a known context window at which to start compacting.

Two thirds, because the threshold is checked between turns against what the last one reported: the next turn still has to fit the model’s reply, and a burst of parallel tool results can add several thousand tokens before anything gets to look again. Leaving a third of the window is what makes the reactive check safe.

Source

pub fn timezone(&self) -> Option<Tz>

The user’s IANA timezone (America/New_York), when it is not the machine’s.

A server runs in UTC and the model has no clock, so without this every “what’s on Thursday” is answered in the wrong zone — and wrongly in a way that looks right, since the times are internally consistent. An IANA name rather than an offset, because an offset is wrong twice a year.

Source

pub fn compact_at(&self, context_window: Option<u64>) -> Option<u64>

Where compaction kicks in for a run: the explicit setting if there is one, otherwise derived from the provider’s context window.

Deriving it is what turns compaction from something you must remember to configure into something that just works — and the failure it prevents is total, not gradual: one turn over the window and the server refuses the request outright.

Source

pub fn resolve_system_prompt(&self) -> Result<Option<String>>

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
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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: Sized + 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: Sized + 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> 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 = !

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