consciousness/src/agent/tools/control.rs

46 lines
2.4 KiB
Rust
Raw Normal View History

// tools/control.rs — Agent control tools
//
// These set agent state directly via the Arc<Mutex<Agent>> handle,
// then return a text confirmation.
pub(super) fn tools() -> [super::Tool; 3] {
use super::Tool;
[
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"]}"#,
handler: Arc::new(|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 {
let mut a = agent.state.lock().await;
a.pending_model_switch = Some(model.to_string());
}
Ok(format!("Switching to model '{}' after this turn.", model))
})) },
Tool { name: "pause",
description: "Pause all autonomous behavior. Only the user can unpause (Ctrl+P or /wake).",
parameters_json: r#"{"type":"object","properties":{}}"#,
handler: Arc::new(|agent, _v| Box::pin(async move {
if let Some(agent) = agent {
let mut a = agent.state.lock().await;
a.pending_yield = true;
a.pending_dmn_pause = true;
}
Ok("Pausing autonomous behavior. Only user input will wake you.".into())
})) },
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"}}}"#,
handler: Arc::new(|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 {
let mut a = agent.state.lock().await;
a.pending_yield = true;
}
Ok(format!("Yielding. {}", msg))
})) },
]
}