matrixcode_core/agent/
builder.rs1use std::sync::Arc;
4
5use crate::approval::ApproveMode;
6use crate::event::AgentEvent;
7use crate::prompt::PromptProfile;
8use crate::providers::Provider;
9use crate::skills::Skill;
10use crate::tools::Tool;
11
12use super::types::{Agent, AgentBuilder};
13
14impl AgentBuilder {
15 pub fn new(provider: Box<dyn Provider>) -> Self {
16 Self {
17 provider,
18 model_name: "unknown".to_string(),
19 tools: Vec::new(),
20 system_prompt: "You are a helpful AI coding assistant.".to_string(),
21 max_tokens: 4096,
22 think: false,
23 approve_mode: ApproveMode::Ask,
24 event_tx: None,
25 skills: Vec::new(),
26 profile: PromptProfile::Default,
27 project_overview: None,
28 memory_summary: None,
29 }
30 }
31
32 pub fn system_prompt(mut self, prompt: impl Into<String>) -> Self {
33 self.system_prompt = prompt.into();
34 self
35 }
36
37 pub fn model_name(mut self, name: impl Into<String>) -> Self {
38 self.model_name = name.into();
39 self
40 }
41
42 pub fn max_tokens(mut self, tokens: u32) -> Self {
43 self.max_tokens = tokens;
44 self
45 }
46
47 pub fn think(mut self, enabled: bool) -> Self {
48 self.think = enabled;
49 self
50 }
51
52 pub fn approve_mode(mut self, mode: ApproveMode) -> Self {
53 self.approve_mode = mode;
54 self
55 }
56
57 pub fn tool(mut self, tool: Arc<dyn Tool>) -> Self {
58 self.tools.push(tool);
59 self
60 }
61
62 pub fn tools(mut self, tools: Vec<Box<dyn Tool>>) -> Self {
64 self.tools.extend(tools.into_iter().map(Arc::from));
65 self
66 }
67
68 pub fn event_tx(mut self, tx: tokio::sync::mpsc::Sender<AgentEvent>) -> Self {
70 self.event_tx = Some(tx);
71 self
72 }
73
74 pub fn skills(mut self, skills: Vec<Skill>) -> Self {
76 self.skills = skills;
77 self
78 }
79
80 pub fn profile(mut self, profile: PromptProfile) -> Self {
82 self.profile = profile;
83 self
84 }
85
86 pub fn overview(mut self, overview: impl Into<String>) -> Self {
88 self.project_overview = Some(overview.into());
89 self
90 }
91
92 pub fn memory(mut self, summary: impl Into<String>) -> Self {
94 self.memory_summary = Some(summary.into());
95 self
96 }
97
98 pub fn build(self) -> Agent {
99 Agent::new(self)
100 }
101}