Skip to main content

oxi_agent/agent_loop/
config.rs

1//! Agent loop configuration types
2
3/// Configuration for an [`crate::AgentLoop`] instance.
4#[derive(Clone)]
5pub struct AgentLoopConfig {
6    /// Model identifier in `provider/model` format.
7    pub model_id: String,
8    /// Optional system prompt prepended to every request.
9    pub system_prompt: Option<String>,
10    /// Sampling temperature (0.0 – 2.0).
11    pub temperature: f32,
12    /// Maximum tokens the model may generate per request.
13    pub max_tokens: u32,
14    /// Maximum number of assistant turns before the loop stops.
15    pub max_iterations: usize,
16    /// Whether tool calls run in parallel or sequentially.
17    pub tool_execution: ToolExecutionMode,
18    /// Compaction strategy for managing context window usage.
19    pub compaction_strategy: oxi_ai::CompactionStrategy,
20    /// Approximate context window size in tokens.
21    pub context_window: usize,
22    /// Optional instruction injected into the compaction prompt.
23    pub compaction_instruction: Option<String>,
24    /// Optional session identifier for logging and tracing.
25    pub session_id: Option<String>,
26    /// Optional transport override (e.g. "sse", "stdio").
27    pub transport: Option<String>,
28    /// Whether to trigger compaction before the first turn.
29    pub compact_on_start: bool,
30    /// Optional cap on retry back-off delay (milliseconds).
31    pub max_retry_delay_ms: Option<u64>,
32    /// Enable automatic retry on retryable assistant errors.
33    pub auto_retry_enabled: bool,
34    /// Maximum number of auto-retry attempts.
35    pub auto_retry_max_attempts: usize,
36    /// Base delay in milliseconds for auto-retry exponential back-off.
37    pub auto_retry_base_delay_ms: u64,
38    /// API key override for the provider.
39    ///
40    /// When set, this is injected into [`oxi_ai::StreamOptions`] so the
41    /// provider uses it instead of an environment variable.
42    pub api_key: Option<String>,
43    /// Working directory for file tools. Defaults to current directory if None.
44    pub workspace_dir: Option<std::path::PathBuf>,
45}
46
47// Re-export ToolExecutionMode from crate::config to avoid duplicate definitions.
48pub use crate::config::ToolExecutionMode;
49
50use crate::AgentToolResult;
51use anyhow::{Error, Result};
52use serde_json::Value;
53use std::future::Future;
54use std::pin::Pin;
55use std::sync::Arc;
56
57/// Hook invoked before each tool call; may return an override result.
58pub type BeforeToolCallHook = Arc<
59    dyn Fn(
60            &str,
61            &Value,
62        ) -> Pin<Box<dyn Future<Output = Result<Option<AgentToolResult>, Error>> + Send>>
63        + Send
64        + Sync,
65>;
66
67/// Hook invoked after each tool call; may return a modified result.
68pub type AfterToolCallHook = Arc<
69    dyn Fn(
70            &str,
71            &AgentToolResult,
72        ) -> Pin<Box<dyn Future<Output = Result<Option<AgentToolResult>, Error>> + Send>>
73        + Send
74        + Sync,
75>;
76
77// MAX_RETRIES and BACKOFF_BASE_SECS are now defined in crate::stream_retry
78// and re-exported from crate::agent_loop::retry.
79pub use crate::stream_retry::{BACKOFF_BASE_SECS, MAX_RETRIES};