1use std::collections::VecDeque;
4use std::sync::{Arc, Mutex};
5
6use crate::message::AgentMessage;
7use crate::tool::Tool;
8use opi_ai::provider::Provider;
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}
55
56impl Default for AgentLoopConfig {
57 fn default() -> Self {
58 Self {
59 max_turns: 50,
60 max_tokens: None,
61 temperature: None,
62 }
63 }
64}
65
66pub struct AgentLoopTurnUpdate {
68 pub extra_messages: Vec<AgentMessage>,
69}