autoagents_core/agent/
base.rs

1use super::executor::AgentExecutor;
2use async_trait::async_trait;
3use autoagents_llm::{LLMProvider, ToolT};
4use serde::Serialize;
5use std::sync::Arc;
6
7/// Base agent type that uses an executor strategy
8#[derive(Clone)]
9pub struct BaseAgent<E: AgentExecutor> {
10    pub name: String,
11    pub description: String,
12    pub executor: E,
13    pub tools: Vec<Arc<Box<dyn ToolT>>>,
14    pub(crate) llm: Arc<dyn LLMProvider>,
15}
16
17impl<E: AgentExecutor> BaseAgent<E> {
18    pub fn new(
19        name: String,
20        description: String,
21        executor: E,
22        tools: Vec<Arc<Box<dyn ToolT>>>,
23        llm: Arc<dyn LLMProvider>,
24    ) -> Self {
25        Self {
26            name,
27            description,
28            executor,
29            tools,
30            llm,
31        }
32    }
33
34    /// Add a tool to this agent
35    pub fn with_tool(mut self, tool: Arc<Box<dyn ToolT>>) -> Self {
36        self.tools.push(tool);
37        self
38    }
39
40    /// Add multiple tools to this agent
41    pub fn with_tools(mut self, tools: Vec<Arc<Box<dyn ToolT>>>) -> Self {
42        self.tools.extend(tools);
43        self
44    }
45}
46
47#[async_trait]
48pub trait AgentDeriveT: Send + Sync {
49    type Output: Serialize + Send + Sync;
50    fn description(&self) -> &'static str;
51    fn name(&self) -> &'static str;
52    fn tools(&self) -> Vec<Box<dyn ToolT>>;
53}