WIP: Agent/AgentState split — core methods migrated

turn(), push_node(), assemble_prompt_tokens(), compact(),
restore_from_log(), load_startup_journal(), apply_tool_result()
all use separate context/state locks. ToolHandler signature
updated to Arc<Agent>.

Remaining: tool handlers, control.rs, memory.rs, digest.rs,
and all outer callers (mind, user, learn, oneshot, dmn).

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-08 15:39:03 -04:00
parent 7fe4584ba0
commit e73135a8d0
2 changed files with 71 additions and 144 deletions

View file

@ -29,7 +29,7 @@ fn default_timeout() -> u64 { 120 }
/// Async tool handler function.
/// Agent is None when called from contexts without an agent (MCP server, subconscious).
pub type ToolHandler = fn(
Option<std::sync::Arc<tokio::sync::Mutex<super::Agent>>>,
Option<std::sync::Arc<super::Agent>>,
serde_json::Value,
) -> Pin<Box<dyn Future<Output = anyhow::Result<String>> + Send>>;
@ -100,11 +100,10 @@ pub async fn dispatch(
pub async fn dispatch_with_agent(
name: &str,
args: &serde_json::Value,
agent: Option<std::sync::Arc<tokio::sync::Mutex<super::Agent>>>,
agent: Option<std::sync::Arc<super::Agent>>,
) -> String {
// Look up in agent's tools if available, otherwise global
let tool = if let Some(ref a) = agent {
let guard = a.lock().await;
let guard = a.state.lock().await;
guard.tools.iter().find(|t| t.name == name).copied()
} else {
None