Skip to main content

RunConfig

Struct RunConfig 

Source
#[non_exhaustive]
pub struct RunConfig { pub system_prompt: Option<SystemPrompt>, pub max_iterations: usize, pub max_tokens: u32, pub middlewares: Vec<Arc<dyn ChatMiddleware>>, pub run_id: Option<RunId>, pub timeout: Option<Duration>, pub cancellation: Option<CancellationToken>, }
Expand description

Per-run configuration consumed by the engine entry point.

The defaults shipped via RunConfig::default are tuned for short interactive turns (10 iterations, 4096 max output tokens, no timeout). Use struct-update syntax to override what you need: RunConfig { max_iterations: 20, ..Default::default() }. The struct is #[non_exhaustive], so external callers must always go through Default (or RunConfig::new) to construct it.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§system_prompt: Option<SystemPrompt>

System prompt prepended to the conversation. None lets the provider use its own default behaviour. Use SystemPrompt::Blocks to opt in to per-block cache breakpoints.

§max_iterations: usize

Maximum number of provider turns before the engine aborts the run with crate::FinishReason::Aborted. One iteration covers a chat_stream call plus the tool calls it triggers. The cap prevents runaway tool-use loops; pair with an crate::ChatMiddleware such as AntiLoop for content-aware loop detection.

§max_tokens: u32

Default max_tokens for every per-turn crate::ChatRequest the engine builds. User-supplied middlewares can override this per request via crate::ChatMiddleware::on_chat_request.

§middlewares: Vec<Arc<dyn ChatMiddleware>>

Middlewares the engine invokes in registration order. The façade prepends an internal middleware that injects per-request defaults; entries supplied here run after it and can override any field.

§run_id: Option<RunId>

Caller-supplied id for the run. When None, the engine mints a fresh UUID v4. Set this when an outer system needs to correlate the run with its own trace id.

§timeout: Option<Duration>

Wall-clock deadline for the entire run, including tool calls and any retry backoff inside RetryingModel. None disables the timeout. The engine checks this at await boundaries (HTTP setup, SSE chunks, tool execution, approval middleware) — synchronous work is not preempted. Sleeps inside RetryingModel’s backoff race against this deadline because they run under the engine’s select!, so retry attempts are interruptible without the decorator knowing about cancellation.

§cancellation: Option<CancellationToken>

External cancellation handle. Calling cancel() from another task aborts the in-flight run at the next await boundary, with the same persistence discipline as the timeout (partial tools_result preserved, on_run_finished fired). Pass parent.child_token() if you want to cancel this run without affecting siblings sharing the parent.

Implementations§

Source§

impl RunConfig

Source

pub fn new(max_iterations: usize) -> Self

Build a config with the given iteration cap and otherwise default values. Equivalent to RunConfig { max_iterations, ..Default::default() }; provided because capping iterations is the most common single-field override.

Trait Implementations§

Source§

impl Default for RunConfig

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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