1use std::collections::VecDeque;
4use std::sync::{Arc, Mutex};
5
6use crate::message::AgentMessage;
7use crate::tool::Tool;
8use opi_ai::provider::{Provider, ThinkingConfig};
9
10#[derive(Debug, thiserror::Error)]
12pub enum AgentError {
13 #[error("provider error: {0}")]
14 Provider(String),
15 #[error("authentication failed: {0}")]
16 AuthFailed(String),
17 #[error("tool error: {0}")]
18 Tool(String),
19 #[error("hook error: {0}")]
20 Hook(String),
21 #[error("cancelled")]
22 Cancelled,
23 #[error("max turns exceeded ({0})")]
24 MaxTurnsExceeded(u32),
25}
26
27pub struct AgentLoopContext {
29 pub provider: Box<dyn Provider>,
31 pub tools: Vec<Box<dyn Tool>>,
33 pub messages: Vec<AgentMessage>,
35 pub model: String,
37 pub system: Option<String>,
39 pub steering_queue: Option<Arc<Mutex<VecDeque<String>>>>,
41 pub follow_up_queue: Option<Arc<Mutex<VecDeque<String>>>>,
43}
44
45#[derive(Debug, Clone)]
47pub struct AgentLoopConfig {
48 pub max_turns: u32,
50 pub max_tokens: Option<u64>,
52 pub temperature: Option<f64>,
54 pub retry: Option<opi_ai::retry::RetryConfig>,
56 pub thinking: Option<ThinkingConfig>,
58}
59
60impl Default for AgentLoopConfig {
61 fn default() -> Self {
62 Self {
63 max_turns: 50,
64 max_tokens: None,
65 temperature: None,
66 retry: None,
67 thinking: None,
68 }
69 }
70}
71
72pub struct AgentLoopTurnUpdate {
74 pub extra_messages: Vec<AgentMessage>,
75}