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};
9
10/// Default maximum iterations for agent execution.
11const DEFAULT_MAX_ITERATIONS: usize = 16;
12
13/// Serializable agent configuration.
14///
15/// Contains all parameters for an agent: identity, system prompt, model,
16/// and iteration limits. All registered tools are available to every agent.
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct AgentConfig {
19    /// Agent identifier.
20    pub name: CompactString,
21    /// Human-readable description.
22    pub description: CompactString,
23    /// System prompt sent before each LLM request.
24    pub system_prompt: String,
25    /// Model to use from the registry. None = registry's active/default.
26    pub model: Option<CompactString>,
27    /// Maximum iterations before stopping.
28    pub max_iterations: usize,
29    /// Controls which tool the model calls.
30    pub tool_choice: ToolChoice,
31}
32
33impl Default for AgentConfig {
34    fn default() -> Self {
35        Self {
36            name: CompactString::default(),
37            description: CompactString::default(),
38            system_prompt: String::new(),
39            model: None,
40            max_iterations: DEFAULT_MAX_ITERATIONS,
41            tool_choice: ToolChoice::Auto,
42        }
43    }
44}
45
46impl AgentConfig {
47    /// Create a new config with the given name and defaults for everything else.
48    pub fn new(name: impl Into<CompactString>) -> Self {
49        Self {
50            name: name.into(),
51            ..Default::default()
52        }
53    }
54
55    /// Set the system prompt.
56    pub fn system_prompt(mut self, prompt: impl Into<String>) -> Self {
57        self.system_prompt = prompt.into();
58        self
59    }
60
61    /// Set the description.
62    pub fn description(mut self, desc: impl Into<CompactString>) -> Self {
63        self.description = desc.into();
64        self
65    }
66
67    /// Set the model to use from the registry.
68    pub fn model(mut self, name: impl Into<CompactString>) -> Self {
69        self.model = Some(name.into());
70        self
71    }
72}