WIP: Output tool via Arc<Mutex<Subconscious>>, ToolHandler to Arc<dyn Fn>
- ToolHandler changed to Arc<dyn Fn(...)> (supports closures) - Subconscious wrapped in Arc<Mutex<>> on Mind - init_output_tool() pushes output tool closure capturing the Arc - Output removed from static memory_tools() - Most tool handlers wrapped in Arc::new() but some have paren issues Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
d167b11283
commit
12798eeae2
15 changed files with 74 additions and 51 deletions
|
|
@ -389,6 +389,33 @@ impl Subconscious {
|
|||
Self { agents, state: std::collections::BTreeMap::new(), state_path: None }
|
||||
}
|
||||
|
||||
/// Late-init: push the output tool onto each agent's tool list.
|
||||
/// Called after Subconscious is wrapped in Arc<Mutex<>> so the
|
||||
/// closure can capture a reference back.
|
||||
pub fn init_output_tool(&mut self, self_arc: std::sync::Arc<tokio::sync::Mutex<Self>>) {
|
||||
for agent in &mut self.agents {
|
||||
let sub = self_arc.clone();
|
||||
agent.auto.tools.push(crate::agent::tools::Tool {
|
||||
name: "output",
|
||||
description: "Produce a named output value for passing between steps.",
|
||||
parameters_json: r#"{"type":"object","properties":{"key":{"type":"string","description":"Output name"},"value":{"type":"string","description":"Output value"}},"required":["key","value"]}"#,
|
||||
handler: std::sync::Arc::new(move |_agent, v| {
|
||||
let sub = sub.clone();
|
||||
Box::pin(async move {
|
||||
let key = v["key"].as_str()
|
||||
.ok_or_else(|| anyhow::anyhow!("output requires 'key'"))?;
|
||||
let value = v["value"].as_str()
|
||||
.ok_or_else(|| anyhow::anyhow!("output requires 'value'"))?;
|
||||
let mut s = sub.lock().await;
|
||||
s.state.insert(key.to_string(), value.to_string());
|
||||
s.save_state();
|
||||
Ok(format!("{}: {}", key, value))
|
||||
})
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the state file path and load any existing state from disk.
|
||||
pub fn set_state_path(&mut self, path: std::path::PathBuf) {
|
||||
if let Ok(data) = std::fs::read_to_string(&path) {
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@ pub struct Mind {
|
|||
pub agent: Arc<Agent>,
|
||||
pub shared: Arc<SharedMindState>,
|
||||
pub config: SessionConfig,
|
||||
subconscious: tokio::sync::Mutex<Subconscious>,
|
||||
subconscious: Arc<tokio::sync::Mutex<Subconscious>>,
|
||||
turn_tx: mpsc::Sender<(Result<TurnResult>, StreamTarget)>,
|
||||
turn_watch: tokio::sync::watch::Sender<bool>,
|
||||
bg_tx: mpsc::UnboundedSender<BgEvent>,
|
||||
|
|
@ -287,9 +287,11 @@ impl Mind {
|
|||
sup.load_config();
|
||||
sup.ensure_running();
|
||||
|
||||
let subconscious = Arc::new(tokio::sync::Mutex::new(Subconscious::new()));
|
||||
subconscious.lock().await.init_output_tool(subconscious.clone());
|
||||
|
||||
Self { agent, shared, config,
|
||||
subconscious: tokio::sync::Mutex::new(Subconscious::new()),
|
||||
turn_tx, turn_watch, bg_tx,
|
||||
subconscious, turn_tx, turn_watch, bg_tx,
|
||||
bg_rx: std::sync::Mutex::new(Some(bg_rx)), _supervisor: sup }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue