Skip to main content

AgentLoopConfig

Struct AgentLoopConfig 

Source
#[non_exhaustive]
pub struct AgentLoopConfig {
Show 29 fields pub provider: Arc<dyn StreamProvider>, pub model: String, pub api_key: String, pub thinking_level: ThinkingLevel, pub max_tokens: Option<u32>, pub temperature: Option<f32>, pub model_config: Option<ModelConfig>, pub convert_to_llm: Option<ConvertToLlmFn>, pub transform_context: Option<TransformContextFn>, pub get_steering_messages: Option<GetMessagesFn>, pub get_follow_up_messages: Option<GetMessagesFn>, pub context_config: Option<ContextConfig>, pub compaction_strategy: Option<Arc<dyn CompactionStrategy>>, pub execution_limits: Option<ExecutionLimits>, pub cache_config: CacheConfig, pub tool_output_sink: Option<SharedState>, pub tool_execution: ToolExecutionStrategy, pub tool_middleware: Vec<Arc<dyn ToolMiddleware>>, pub output_schema: Option<OutputSchema>, pub retry_config: RetryConfig, pub before_turn: Option<BeforeTurnFn>, pub after_turn: Option<AfterTurnFn>, pub on_error: Option<OnErrorFn>, pub input_filters: Vec<Arc<dyn InputFilter>>, pub turn_delay: Option<Duration>, pub extensions: Vec<Arc<dyn Extension>>, pub tree_extensions: Vec<Arc<dyn Extension>>, pub max_stop_continues: usize, pub run_label: Option<String>, /* private fields */
}
Expand description

Configuration for the agent loop.

Build one with AgentLoopConfig::new, then set the fields you need: the struct is #[non_exhaustive], so new fields can be added in a minor release without breaking callers.

use std::sync::Arc;
use yoagent::agent_loop::AgentLoopConfig;
use yoagent::provider::MockProvider;

let mut config = AgentLoopConfig::new(Arc::new(MockProvider::text("hi")), "mock");
config.max_tokens = Some(1024);

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.
§provider: Arc<dyn StreamProvider>§model: String§api_key: String§thinking_level: ThinkingLevel§max_tokens: Option<u32>§temperature: Option<f32>§model_config: Option<ModelConfig>

Optional model configuration for multi-provider support. When set, passed through to StreamConfig so providers can use base_url, headers, compat flags, etc.

§convert_to_llm: Option<ConvertToLlmFn>

Convert AgentMessage[] → Message[] before each LLM call. Default: keep only LLM-compatible messages.

§transform_context: Option<TransformContextFn>

Transform context before convert_to_llm (for pruning, compaction).

§get_steering_messages: Option<GetMessagesFn>

Get steering messages (user interruptions mid-run).

§get_follow_up_messages: Option<GetMessagesFn>

Get follow-up messages (queued work after agent finishes).

§context_config: Option<ContextConfig>

Context window configuration (auto-compaction).

§compaction_strategy: Option<Arc<dyn CompactionStrategy>>

Custom compaction strategy. When set, replaces the default compact_messages() call. Invoked when context_config is Some.

§execution_limits: Option<ExecutionLimits>

Execution limits (max turns, tokens, duration).

§cache_config: CacheConfig

Prompt caching configuration.

§tool_output_sink: Option<SharedState>

Where to stash the full text of a truncated tool result, so the model can retrieve what head-tail truncation elided.

None (default) means truncation behaves exactly as before: the middle is gone and only the event stream, which the agent cannot read, still has it. Set it and the marker names a shared_state key instead.

The pointer lives in the transcript, so it is lost when lossy compaction drops that turn — the stash entry outlives it and keeps consuming the backend’s cap. Retrieval is best-effort by construction.

§tool_execution: ToolExecutionStrategy

Tool execution strategy (sequential, parallel, or batched).

§tool_middleware: Vec<Arc<dyn ToolMiddleware>>

Tool middleware chain — approve/deny/modify every tool call before it executes (see ToolMiddleware). Empty = allow all.

§output_schema: Option<OutputSchema>

Structured-output constraint, passed through to the provider (see OutputSchema). Usually set via Agent::prompt_structured.

§retry_config: RetryConfig

Retry configuration for transient provider errors.

§before_turn: Option<BeforeTurnFn>

Called before each LLM turn. Return false to abort the loop.

§after_turn: Option<AfterTurnFn>

Called after each LLM turn with the current messages and the turn’s usage.

§on_error: Option<OnErrorFn>

Called when the LLM returns a StopReason::Error.

§input_filters: Vec<Arc<dyn InputFilter>>

Input filters applied to user messages before the LLM call. Filters run in order; first Reject wins and discards any accumulated warnings. Warn messages accumulate and are appended to the user message. An AsyncFilter in the list is awaited (see InputFilter::as_async).

§turn_delay: Option<Duration>

Optional delay between turns. Useful for rate-limit-sensitive scenarios (e.g., OAuth tokens with low request-per-minute caps). Skipped on the first turn so the agent starts immediately.

§extensions: Vec<Arc<dyn Extension>>

Extensions for this run (see crate::extension), in dispatch order after tree_extensions.

§tree_extensions: Vec<Arc<dyn Extension>>

Extensions for this run and every run it delegates to, at any depth (host policy). They run before extensions.

§max_stop_continues: usize

How many times per run an extension’s on_stop may continue it.

§run_label: Option<String>

The host’s label for the run, passed to extensions as RunContext::label.

Implementations§

Source§

impl AgentLoopConfig

Source

pub fn new(provider: Arc<dyn StreamProvider>, model: impl Into<String>) -> Self

A configuration for model on provider, with every other field at its default: no API key, thinking off, no limits beyond the provider’s, no context management, no hooks, parallel tool execution and the default retry policy.

Source

pub fn delegated_from(&mut self, ctx: &ToolContext) -> &mut Self

Make this the configuration of a run delegated by the tool call ctx belongs to: the calling run’s tree extensions apply here (ahead of this run’s own, their tools not offered), at the delegation’s depth, under the calling run’s label. What a custom delegation tool calls before running its child; SubAgentTool does it itself.

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> 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> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSync for T
where T: Sync + ?Sized,

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

Source§

type Output = T

Should always be Self
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, !>

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