pub struct AgentLoopConfig {Show 28 fields
pub agent_name: Option<String>,
pub transfer_chain: Option<TransferChain>,
pub model: ModelSpec,
pub stream_options: StreamOptions,
pub retry_strategy: Box<dyn RetryStrategy>,
pub stream_fn: Arc<dyn StreamFn>,
pub tools: Vec<Arc<dyn AgentTool>>,
pub convert_to_llm: Box<dyn Fn(&AgentMessage) -> Option<LlmMessage> + Send + Sync>,
pub transform_context: Option<Arc<dyn ContextTransformer>>,
pub get_api_key: Option<Box<dyn Fn(&str) -> Pin<Box<dyn Future<Output = Option<String>> + Send>> + Send + Sync>>,
pub message_provider: Option<Arc<dyn MessageProvider>>,
pub pending_message_snapshot: Arc<PendingMessageSnapshot>,
pub loop_context_snapshot: Arc<LoopContextSnapshot>,
pub approve_tool: Option<Box<dyn Fn(ToolApprovalRequest) -> Pin<Box<dyn Future<Output = ToolApproval> + Send>> + Send + Sync>>,
pub approval_mode: ApprovalMode,
pub pre_turn_policies: Vec<Arc<dyn PreTurnPolicy>>,
pub pre_dispatch_policies: Vec<Arc<dyn PreDispatchPolicy>>,
pub post_turn_policies: Vec<Arc<dyn PostTurnPolicy>>,
pub post_loop_policies: Vec<Arc<dyn PostLoopPolicy>>,
pub async_transform_context: Option<Arc<dyn AsyncContextTransformer>>,
pub metrics_collector: Option<Arc<dyn MetricsCollector>>,
pub fallback: Option<ModelFallback>,
pub tool_execution_policy: ToolExecutionPolicy,
pub session_state: Arc<RwLock<SessionState>>,
pub credential_resolver: Option<Arc<dyn CredentialResolver>>,
pub cache_config: Option<CacheConfig>,
pub cache_state: Mutex<CacheState>,
pub dynamic_system_prompt: Option<Arc<dyn Fn() -> String + Send + Sync>>,
}Expand description
Configuration for the agent loop.
Carries the model spec, stream options, retry strategy, stream function, tools, and all the hooks that the loop calls at various points.
Fields§
§agent_name: Option<String>Optional agent name used for transfer chain safety enforcement.
When set, the loop pushes this name onto the TransferChain
at startup so circular transfers back to this agent are detected.
transfer_chain: Option<TransferChain>Optional transfer chain carried from a previous handoff.
When set, the loop resumes transfer safety checks from this chain.
model: ModelSpecModel specification passed through to StreamFn.
stream_options: StreamOptionsStream options passed through to StreamFn.
retry_strategy: Box<dyn RetryStrategy>Retry strategy applied to model calls.
stream_fn: Arc<dyn StreamFn>The pluggable streaming function that calls the LLM provider.
tools: Vec<Arc<dyn AgentTool>>Available tools for the agent to call.
convert_to_llm: Box<dyn Fn(&AgentMessage) -> Option<LlmMessage> + Send + Sync>Converts an AgentMessage to an LlmMessage for the provider.
Returns None to filter out custom or UI-only messages.
transform_context: Option<Arc<dyn ContextTransformer>>Optional hook called before convert_to_llm; used for context pruning,
token budget enforcement, or external context injection.
When the overflow signal is set, the transformer should prune more
aggressively.
get_api_key: Option<Box<dyn Fn(&str) -> Pin<Box<dyn Future<Output = Option<String>> + Send>> + Send + Sync>>Optional async callback for dynamic API key resolution.
message_provider: Option<Arc<dyn MessageProvider>>Optional provider polled for steering and follow-up messages.
MessageProvider::poll_steering is called after each tool execution batch.
MessageProvider::poll_follow_up is called when the agent would otherwise stop.
pending_message_snapshot: Arc<PendingMessageSnapshot>Shared snapshot of loop-local pending messages for pause checkpoints.
loop_context_snapshot: Arc<LoopContextSnapshot>Shared snapshot of the loop’s full context_messages for pause checkpoints.
Updated after each turn’s pending-message drain so that Agent::pause()
can reconstruct the complete message history even for messages that have
been moved out of the shared pending queue and into loop-local context.
approve_tool: Option<Box<dyn Fn(ToolApprovalRequest) -> Pin<Box<dyn Future<Output = ToolApproval> + Send>> + Send + Sync>>Optional async callback for approving/rejecting tool calls before execution.
When Some and approval_mode is Enabled, each tool call is sent through
this callback before dispatch. Rejected tools return an error result to the LLM.
approval_mode: ApprovalModeControls whether the approval gate is active. Defaults to Enabled.
pre_turn_policies: Vec<Arc<dyn PreTurnPolicy>>Pre-turn policies evaluated before each LLM call.
pre_dispatch_policies: Vec<Arc<dyn PreDispatchPolicy>>Pre-dispatch policies evaluated per tool call, before approval.
post_turn_policies: Vec<Arc<dyn PostTurnPolicy>>Post-turn policies evaluated after each completed turn.
post_loop_policies: Vec<Arc<dyn PostLoopPolicy>>Post-loop policies evaluated after the inner loop exits.
async_transform_context: Option<Arc<dyn AsyncContextTransformer>>Optional async context transformer (runs before the sync transformer).
Enables async operations like fetching summaries or RAG retrieval before context compaction.
metrics_collector: Option<Arc<dyn MetricsCollector>>Optional metrics collector invoked at the end of each turn with per-turn timing, token usage, and cost data.
fallback: Option<ModelFallback>Optional model fallback chain tried when the primary model exhausts its retry budget on a retryable error.
tool_execution_policy: ToolExecutionPolicyControls how tool calls within a turn are dispatched.
Defaults to ToolExecutionPolicy::Concurrent for backward
compatibility.
session_state: Arc<RwLock<SessionState>>Session key-value state store shared with tools and policies.
credential_resolver: Option<Arc<dyn CredentialResolver>>Optional credential resolver for tool authentication.
cache_config: Option<CacheConfig>Optional context caching configuration.
cache_state: Mutex<CacheState>Mutable cache state tracking turns since last write.
dynamic_system_prompt: Option<Arc<dyn Fn() -> String + Send + Sync>>Optional dynamic system prompt closure (called fresh each turn).
Its output is injected as a user-role message after the system prompt to avoid invalidating provider-side caches.