#[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
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: CacheConfigPrompt 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: ToolExecutionStrategyTool 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: RetryConfigRetry 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: usizeHow 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
impl AgentLoopConfig
Sourcepub fn new(provider: Arc<dyn StreamProvider>, model: impl Into<String>) -> Self
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.
Sourcepub fn delegated_from(&mut self, ctx: &ToolContext) -> &mut Self
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.