walrus_core/agent/
builder.rs1use crate::{
4 agent::{Agent, CompactHook, config::AgentConfig, tool::ToolSender},
5 model::{Model, Tool},
6};
7use std::sync::Arc;
8
9pub struct AgentBuilder<M: Model> {
14 config: AgentConfig,
15 model: M,
16 tools: Vec<Tool>,
17 tool_tx: Option<ToolSender>,
18 compact_hook: Option<Arc<dyn CompactHook>>,
19}
20
21impl<M: Model> AgentBuilder<M> {
22 pub fn new(model: M) -> Self {
24 Self {
25 config: AgentConfig::default(),
26 model,
27 tools: Vec::new(),
28 tool_tx: None,
29 compact_hook: None,
30 }
31 }
32
33 pub fn config(mut self, config: AgentConfig) -> Self {
35 self.config = config;
36 self
37 }
38
39 pub fn tools(mut self, tools: Vec<Tool>) -> Self {
41 self.tools = tools;
42 self
43 }
44
45 pub fn tool_tx(mut self, tx: ToolSender) -> Self {
47 self.tool_tx = Some(tx);
48 self
49 }
50
51 pub fn compact_hook(mut self, hook: Arc<dyn CompactHook>) -> Self {
53 self.compact_hook = Some(hook);
54 self
55 }
56
57 pub fn build(self) -> Agent<M> {
59 Agent {
60 config: self.config,
61 model: self.model,
62 tools: self.tools,
63 tool_tx: self.tool_tx,
64 compact_hook: self.compact_hook,
65 }
66 }
67}