1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//! Profile and tool configuration for mob meerkats.
//!
//! A `Profile` defines the template for spawning a meerkat: which model to use,
//! which skills to load, tool configuration, and communication settings.
use crate::backend::MobBackendKind;
use crate::runtime_mode::MobRuntimeMode;
use serde::{Deserialize, Serialize};
/// Tool configuration for a meerkat profile.
///
/// Controls which tool categories are enabled for meerkats spawned
/// from this profile.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct ToolConfig {
/// Enable built-in tools (file read, etc.).
#[serde(default)]
pub builtins: bool,
/// Enable shell execution tool.
#[serde(default)]
pub shell: bool,
/// Enable comms tools (peer messaging).
#[serde(default)]
pub comms: bool,
/// Enable memory/semantic search tools.
#[serde(default)]
pub memory: bool,
/// Enable mob management tools (spawn, retire, wire, unwire, list).
#[serde(default)]
pub mob: bool,
/// Enable shared task list tools (create, list, update, get).
#[serde(default)]
pub mob_tasks: bool,
/// MCP server names this profile connects to.
#[serde(default)]
pub mcp: Vec<String>,
/// Named Rust tool bundles wired by the mob runtime.
///
/// String names referencing `Arc<dyn AgentToolDispatcher>` instances
/// registered at mob construction time. Not serializable — must be
/// re-registered on resume.
#[serde(default)]
pub rust_bundles: Vec<String>,
}
/// Profile template for spawning meerkats.
///
/// Each profile defines the model, skills, tool configuration, and
/// communication properties for a class of meerkat agents.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Profile {
/// LLM model name (e.g. "claude-opus-4-6").
pub model: String,
/// Skill references to load for this profile.
#[serde(default)]
pub skills: Vec<String>,
/// Tool configuration.
#[serde(default)]
pub tools: ToolConfig,
/// Human-readable description of this meerkat's role, visible to peers.
#[serde(default)]
pub peer_description: String,
/// Whether this meerkat can receive turns from external callers.
#[serde(default)]
pub external_addressable: bool,
/// Optional backend override for this profile.
///
/// If unset, runtime uses `definition.backend.default`.
#[serde(default)]
pub backend: Option<MobBackendKind>,
/// Runtime mode for members spawned from this profile.
///
/// Defaults to autonomous keep-alive behavior when omitted.
#[serde(default)]
pub runtime_mode: MobRuntimeMode,
/// Maximum peer-count threshold for inline peer lifecycle context injection.
///
/// - `None`: use runtime default
/// - `0`: never inline peer lifecycle notifications
/// - `-1`: always inline peer lifecycle notifications
/// - `>0`: inline only when post-drain peer count is <= threshold
/// - `<-1`: invalid
#[serde(default)]
pub max_inline_peer_notifications: Option<i32>,
/// Optional JSON Schema for structured output extraction.
///
/// When set, the agent session is configured with an [`OutputSchema`] that
/// forces the LLM to respond with validated JSON conforming to this schema.
/// The value should be a valid JSON Schema object (root must be an object).
///
/// **Note:** Validation is deferred to spawn time (`build_session_config`)
/// where `MeerkatSchema::new()` rejects invalid schemas. This is intentional:
/// `Profile` is a serializable template that may be persisted or transmitted
/// before any agent is spawned, and `MeerkatSchema` does not currently
/// implement `Eq` or validate on deserialization.
#[serde(default)]
pub output_schema: Option<serde_json::Value>,
/// Optional provider-specific parameters passed to the LLM adapter.
///
/// This maps directly to `AgentBuildConfig.provider_params` and is useful
/// for model/provider knobs such as Gemini `thinking_budget` or OpenAI
/// `reasoning_effort`.
#[serde(default)]
pub provider_params: Option<serde_json::Value>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_tool_config_serde_roundtrip() {
let config = ToolConfig {
builtins: true,
shell: false,
comms: true,
memory: false,
mob: true,
mob_tasks: true,
mcp: vec!["server-a".to_string(), "server-b".to_string()],
rust_bundles: vec!["custom-tools".to_string()],
};
let json = serde_json::to_string(&config).unwrap();
let parsed: ToolConfig = serde_json::from_str(&json).unwrap();
assert_eq!(parsed, config);
}
#[test]
fn test_tool_config_toml_roundtrip() {
let config = ToolConfig {
builtins: true,
shell: true,
comms: false,
memory: false,
mob: false,
mob_tasks: false,
mcp: vec!["mcp-server".to_string()],
rust_bundles: Vec::new(),
};
let toml_str = toml::to_string(&config).unwrap();
let parsed: ToolConfig = toml::from_str(&toml_str).unwrap();
assert_eq!(parsed, config);
}
#[test]
fn test_profile_serde_roundtrip() {
let profile = Profile {
model: "claude-opus-4-6".to_string(),
skills: vec!["orchestrator-skill".to_string()],
tools: ToolConfig {
builtins: true,
shell: false,
comms: true,
memory: false,
mob: true,
mob_tasks: true,
mcp: vec![],
rust_bundles: vec![],
},
peer_description: "Orchestrates worker agents".to_string(),
external_addressable: true,
backend: None,
runtime_mode: MobRuntimeMode::AutonomousHost,
max_inline_peer_notifications: None,
output_schema: None,
provider_params: None,
};
let json = serde_json::to_string(&profile).unwrap();
let parsed: Profile = serde_json::from_str(&json).unwrap();
assert_eq!(parsed, profile);
}
#[test]
fn test_profile_toml_roundtrip() {
let profile = Profile {
model: "gpt-5.2".to_string(),
skills: vec!["worker-skill".to_string()],
tools: ToolConfig {
builtins: false,
shell: true,
comms: true,
memory: false,
mob: false,
mob_tasks: true,
mcp: vec!["code-server".to_string()],
rust_bundles: vec!["custom".to_string()],
},
peer_description: "Writes code".to_string(),
external_addressable: false,
backend: Some(MobBackendKind::External),
runtime_mode: MobRuntimeMode::TurnDriven,
max_inline_peer_notifications: Some(20),
output_schema: None,
provider_params: None,
};
let toml_str = toml::to_string(&profile).unwrap();
let parsed: Profile = toml::from_str(&toml_str).unwrap();
assert_eq!(parsed, profile);
}
#[test]
fn test_tool_config_defaults() {
let config = ToolConfig::default();
assert!(!config.builtins);
assert!(!config.shell);
assert!(!config.comms);
assert!(!config.memory);
assert!(!config.mob);
assert!(!config.mob_tasks);
assert!(config.mcp.is_empty());
assert!(config.rust_bundles.is_empty());
}
#[test]
fn test_profile_default_fields_from_toml() {
let toml_str = r#"
model = "claude-sonnet-4-5"
"#;
let profile: Profile = toml::from_str(toml_str).unwrap();
assert_eq!(profile.model, "claude-sonnet-4-5");
assert!(profile.skills.is_empty());
assert_eq!(profile.tools, ToolConfig::default());
assert_eq!(profile.peer_description, "");
assert!(!profile.external_addressable);
assert_eq!(profile.backend, None);
assert_eq!(profile.runtime_mode, MobRuntimeMode::AutonomousHost);
assert_eq!(profile.max_inline_peer_notifications, None);
assert_eq!(profile.provider_params, None);
}
#[test]
fn test_profile_toml_parses_zero_inline_threshold() {
let toml_str = r#"
model = "claude-sonnet-4-5"
max_inline_peer_notifications = 0
"#;
let profile: Profile = toml::from_str(toml_str).unwrap();
assert_eq!(profile.max_inline_peer_notifications, Some(0));
}
#[test]
fn test_profile_toml_parses_always_inline_threshold() {
let toml_str = r#"
model = "claude-sonnet-4-5"
max_inline_peer_notifications = -1
"#;
let profile: Profile = toml::from_str(toml_str).unwrap();
assert_eq!(profile.max_inline_peer_notifications, Some(-1));
}
#[test]
fn test_profile_toml_parses_provider_params() {
let toml_str = r#"
model = "gemini-3-pro-preview"
provider_params = { thinking_budget = 8192, top_k = 20 }
"#;
let profile: Profile = toml::from_str(toml_str).unwrap();
assert_eq!(
profile.provider_params,
Some(serde_json::json!({"thinking_budget": 8192, "top_k": 20}))
);
}
}