Skip to main content

walrus_core/agent/
config.rs

1//! Agent configuration.
2//!
3//! [`AgentConfig`] is a serializable struct holding all agent parameters.
4//! Used by [`super::AgentBuilder`] to construct an [`super::Agent`].
5
6use crate::model::ToolChoice;
7use compact_str::CompactString;
8use serde::{Deserialize, Serialize};
9use smallvec::SmallVec;
10
11/// Default maximum iterations for agent execution.
12const DEFAULT_MAX_ITERATIONS: usize = 16;
13
14/// Serializable agent configuration.
15///
16/// Contains all parameters for an agent: identity, system prompt, model,
17/// iteration limits, and tool/skill metadata. The Runtime uses `tools` and
18/// `skill_tags` to construct the appropriate Dispatcher for this agent.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct AgentConfig {
21    /// Agent identifier.
22    pub name: CompactString,
23    /// Human-readable description.
24    pub description: CompactString,
25    /// System prompt sent before each LLM request.
26    pub system_prompt: String,
27    /// Model to use from the registry. None = registry's active/default.
28    pub model: Option<CompactString>,
29    /// Maximum iterations before stopping.
30    pub max_iterations: usize,
31    /// Controls which tool the model calls.
32    pub tool_choice: ToolChoice,
33    /// Names of tools this agent can use (resolved by Runtime into a Dispatcher).
34    pub tools: SmallVec<[CompactString; 8]>,
35    /// Skill tags for matching agent capabilities.
36    pub skill_tags: SmallVec<[CompactString; 4]>,
37}
38
39impl Default for AgentConfig {
40    fn default() -> Self {
41        Self {
42            name: CompactString::default(),
43            description: CompactString::default(),
44            system_prompt: String::new(),
45            model: None,
46            max_iterations: DEFAULT_MAX_ITERATIONS,
47            tool_choice: ToolChoice::Auto,
48            tools: SmallVec::new(),
49            skill_tags: SmallVec::new(),
50        }
51    }
52}
53
54impl AgentConfig {
55    /// Create a new config with the given name and defaults for everything else.
56    pub fn new(name: impl Into<CompactString>) -> Self {
57        Self {
58            name: name.into(),
59            ..Default::default()
60        }
61    }
62
63    /// Set the system prompt.
64    pub fn system_prompt(mut self, prompt: impl Into<String>) -> Self {
65        self.system_prompt = prompt.into();
66        self
67    }
68
69    /// Set the description.
70    pub fn description(mut self, desc: impl Into<CompactString>) -> Self {
71        self.description = desc.into();
72        self
73    }
74
75    /// Add a tool by name.
76    pub fn tool(mut self, name: impl Into<CompactString>) -> Self {
77        self.tools.push(name.into());
78        self
79    }
80
81    /// Add a skill tag.
82    pub fn skill_tag(mut self, tag: impl Into<CompactString>) -> Self {
83        self.skill_tags.push(tag.into());
84        self
85    }
86
87    /// Set the model to use from the registry.
88    pub fn model(mut self, name: impl Into<CompactString>) -> Self {
89        self.model = Some(name.into());
90        self
91    }
92}