1pub mod agent;
6pub mod config;
7pub mod errors;
8pub mod mcp;
9pub mod providers;
10pub mod strategies;
11pub mod tools;
12pub mod utils;
13
14#[cfg(test)]
15mod agent_tests;
16
17use anyhow::Result;
18use std::path::Path;
19
20pub use config::{AgentConfig, ModelConfig};
21pub use models::chat::{ApiResponse, ChatMessage, Choice};
22pub use models::tools::{
23    ToolCall,
24    ToolDefinition,
25    ToolFunction,
26    ToolInput,
27    ToolParameter,
28    ToolParameterType,
29    ToolParametersDefinition,
30};
31pub use strategies::{DelegationInput, DelegationOutput, Strategy};
32
33pub use async_trait::async_trait;
34
35#[async_trait]
38pub trait ToolProvider: Send + Sync {
39    fn get_tool_definitions(&self) -> Vec<ToolDefinition>;
40    async fn execute_tool(
41        &self,
42        tool_name: &str,
43        input: ToolInput,
44        working_dir: &Path,
45    ) -> Result<String>;
46}
47
48#[async_trait]
50pub trait UserInteraction: Send + Sync {
51    async fn ask(&self, prompt: String, options: Vec<String>) -> Result<String>;
52}
53
54#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
57pub struct AgentState {
58    pub messages: Vec<ChatMessage>,
59    pub pending_tool_calls: Vec<ToolCall>,
61}
62
63impl AgentState {
64    pub fn new_turn(history: Option<Vec<ChatMessage>>, current_user_input: String) -> Self {
66        let mut messages = history.unwrap_or_default(); if !current_user_input.is_empty() {
69            messages.push(ChatMessage {
70                role: "user".to_string(),
71                content: Some(current_user_input),
72                ..Default::default()
73            });
74        }
75        Self {
76            messages,
77            pending_tool_calls: Vec::new(),
78        }
79    }
80
81    pub fn add_message(&mut self, message: ChatMessage) {
85        self.messages.push(message);
86    }
87
88    pub fn set_tool_calls(&mut self, tool_calls: Vec<ToolCall>) {
89        self.pending_tool_calls = tool_calls;
90    }
91
92    pub fn add_tool_results(&mut self, results: Vec<ToolResult>) {
93        for result in results {
94            self.messages.push(ChatMessage {
95                role: "tool".to_string(),
96                content: Some(result.output),
97                tool_call_id: Some(result.tool_call_id),
98                ..Default::default()
99            });
100        }
101        self.pending_tool_calls.clear();
102    }
103}
104
105#[derive(Debug, Clone)]
107pub struct ToolResult {
108    pub tool_call_id: String,
109    pub output: String,
110    pub status: ToolExecutionStatus,
111}
112
113#[derive(Debug, Clone)]
114pub struct DelegationResult {
115    pub result: String,
116}
117
118#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
121pub struct AgentOutput {
122    pub applied_tool_results: Vec<ToolExecutionResult>,
123    pub final_state_description: Option<String>,
124}
125
126#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
127pub struct ToolExecutionResult {
128    pub tool_call_id: String,
129    pub tool_name: String,
130    pub input: serde_json::Value,
131    pub output: String,
132    pub status: ToolExecutionStatus,
133}
134
135#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq)]
136pub enum ToolExecutionStatus {
137    Success,
138    Failure,
139}
140
141pub mod models {
142    pub mod chat;
143    pub mod tools;
144}