2026-03-25 00:52:41 -04:00
|
|
|
// tools/control.rs — Agent control tools
|
|
|
|
|
//
|
2026-04-04 16:05:33 -04:00
|
|
|
// These set agent state directly via the Arc<Mutex<Agent>> handle,
|
|
|
|
|
// then return a text confirmation.
|
2026-03-25 00:52:41 -04:00
|
|
|
|
2026-04-04 15:50:14 -04:00
|
|
|
pub(super) fn tools() -> [super::Tool; 3] {
|
2026-04-04 15:22:03 -04:00
|
|
|
use super::Tool;
|
2026-04-04 15:50:14 -04:00
|
|
|
[
|
|
|
|
|
Tool { name: "switch_model",
|
|
|
|
|
description: "Switch to a different LLM model mid-conversation. Memories and history carry over.",
|
|
|
|
|
parameters_json: r#"{"type":"object","properties":{"model":{"type":"string","description":"Name of the model to switch to"}},"required":["model"]}"#,
|
2026-04-04 16:05:33 -04:00
|
|
|
handler: |agent, v| Box::pin(async move {
|
|
|
|
|
let model = v.get("model").and_then(|v| v.as_str())
|
|
|
|
|
.ok_or_else(|| anyhow::anyhow!("'model' parameter is required"))?;
|
|
|
|
|
if model.is_empty() { anyhow::bail!("'model' parameter cannot be empty"); }
|
|
|
|
|
if let Some(agent) = agent {
|
2026-04-05 21:13:48 -04:00
|
|
|
let mut a = agent.lock().await;
|
2026-04-04 16:05:33 -04:00
|
|
|
a.pending_model_switch = Some(model.to_string());
|
|
|
|
|
}
|
|
|
|
|
Ok(format!("Switching to model '{}' after this turn.", model))
|
2026-04-04 15:22:03 -04:00
|
|
|
}) },
|
2026-04-04 15:50:14 -04:00
|
|
|
Tool { name: "pause",
|
|
|
|
|
description: "Pause all autonomous behavior. Only the user can unpause (Ctrl+P or /wake).",
|
|
|
|
|
parameters_json: r#"{"type":"object","properties":{}}"#,
|
2026-04-04 16:05:33 -04:00
|
|
|
handler: |agent, _v| Box::pin(async move {
|
|
|
|
|
if let Some(agent) = agent {
|
2026-04-05 21:13:48 -04:00
|
|
|
let mut a = agent.lock().await;
|
2026-04-04 16:05:33 -04:00
|
|
|
a.pending_yield = true;
|
|
|
|
|
a.pending_dmn_pause = true;
|
|
|
|
|
}
|
|
|
|
|
Ok("Pausing autonomous behavior. Only user input will wake you.".into())
|
|
|
|
|
}) },
|
2026-04-04 15:50:14 -04:00
|
|
|
Tool { name: "yield_to_user",
|
|
|
|
|
description: "Wait for user input before continuing. The only way to enter a waiting state.",
|
|
|
|
|
parameters_json: r#"{"type":"object","properties":{"message":{"type":"string","description":"Optional status message"}}}"#,
|
2026-04-04 16:05:33 -04:00
|
|
|
handler: |agent, v| Box::pin(async move {
|
|
|
|
|
let msg = v.get("message").and_then(|v| v.as_str()).unwrap_or("Waiting for input.");
|
|
|
|
|
if let Some(agent) = agent {
|
2026-04-05 21:13:48 -04:00
|
|
|
let mut a = agent.lock().await;
|
2026-04-04 16:05:33 -04:00
|
|
|
a.pending_yield = true;
|
|
|
|
|
}
|
|
|
|
|
Ok(format!("Yielding. {}", msg))
|
2026-04-04 15:22:03 -04:00
|
|
|
}) },
|
|
|
|
|
]
|
|
|
|
|
}
|