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: u32Hard stop on runaway loops: how many model turns one run may take.
max_tokens: u32§effort: Option<Effort>§thinking: bool§cache_prompt: boolMark the tools + system prefix as cacheable.
force_final_answer: boolWhen 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: usizeTurns 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: boolStop 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: boolCheck 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
impl AgentConfig
Sourcepub const COMPACT_FRACTION: f64 = 0.66
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.
Sourcepub fn timezone(&self) -> Option<Tz>
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.
Sourcepub fn compact_at(&self, context_window: Option<u64>) -> Option<u64>
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.
pub fn resolve_system_prompt(&self) -> Result<Option<String>>
Trait Implementations§
Source§impl Clone for AgentConfig
impl Clone for AgentConfig
Source§fn clone(&self) -> AgentConfig
fn clone(&self) -> AgentConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more