crabtalk_core/agent/
builder.rs1use crate::{
4 agent::{Agent, config::AgentConfig, tool::ToolDispatcher},
5 model::Model,
6};
7use crabllm_core::{Provider, Tool};
8use std::sync::Arc;
9
10pub struct AgentBuilder<P: Provider + 'static> {
15 config: AgentConfig,
16 model: Model<P>,
17 tools: Vec<Tool>,
18 dispatcher: Option<Arc<dyn ToolDispatcher>>,
19}
20
21impl<P: Provider + 'static> AgentBuilder<P> {
22 pub fn new(model: Model<P>) -> Self {
24 Self {
25 config: AgentConfig::default(),
26 model,
27 tools: Vec::new(),
28 dispatcher: None,
29 }
30 }
31
32 pub fn config(mut self, config: AgentConfig) -> Self {
34 self.config = config;
35 self
36 }
37
38 pub fn tools(mut self, tools: Vec<Tool>) -> Self {
40 self.tools = tools;
41 self
42 }
43
44 pub fn dispatcher(mut self, dispatcher: Arc<dyn ToolDispatcher>) -> Self {
46 self.dispatcher = Some(dispatcher);
47 self
48 }
49
50 pub fn build(self) -> Agent<P> {
52 Agent {
53 config: self.config,
54 model: self.model,
55 tools: self.tools,
56 dispatcher: self.dispatcher,
57 }
58 }
59}