Skip to main content

saya_agent/loop_runner/
output.rs

1use crate::{AgentEvent, ProviderError, ToolMetadata};
2use thiserror::Error;
3
4#[derive(Debug, Clone, Copy)]
5pub struct AgentLimits {
6    pub max_turns: usize,
7    pub max_tool_calls: usize,
8}
9impl Default for AgentLimits {
10    fn default() -> Self {
11        Self {
12            max_turns: 12,
13            max_tool_calls: 24,
14        }
15    }
16}
17// `events` holds `AgentEvent`, which carries a `serde_json::Value` and is
18// therefore `PartialEq` but not `Eq`.
19#[derive(Debug, Clone, PartialEq)]
20pub struct AgentOutput {
21    pub answer: String,
22    pub events: Vec<AgentEvent>,
23    pub used_bounded_sql_query: bool,
24    pub tool_metadata: Vec<ToolMetadata>,
25}
26#[derive(Debug, Error)]
27pub enum AgentError {
28    #[error("{0}")]
29    Provider(#[from] ProviderError),
30    #[error("agent limit reached: {0}")]
31    Limit(&'static str),
32    #[error("provider returned an unsupported tool call")]
33    InvalidToolCall,
34    #[error("conversation history is invalid")]
35    InvalidHistory,
36    #[error("conversation context exceeds the safe limit")]
37    ContextLimit,
38    #[error("request cancelled")]
39    Cancelled,
40}