From d9e1c2c59fa1223710fae24258cc5d1a4c9ec3ca Mon Sep 17 00:00:00 2001 From: ProofOfConcept Date: Sat, 4 Apr 2026 16:23:04 -0400 Subject: [PATCH] tools: dispatch_with_agent uses agent's tool list When agent is provided, looks up the tool in agent.tools first. Falls back to global registry for agent-less dispatch (MCP server, subconscious agents). Co-Authored-By: Proof of Concept --- src/agent/tools/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/agent/tools/mod.rs b/src/agent/tools/mod.rs index 8894018..3be298f 100644 --- a/src/agent/tools/mod.rs +++ b/src/agent/tools/mod.rs @@ -166,11 +166,25 @@ pub async fn dispatch( } /// Dispatch a tool call with optional agent context. +/// If agent is provided, uses the agent's tool list. pub async fn dispatch_with_agent( name: &str, args: &serde_json::Value, agent: Option>>, ) -> String { + // Look up in agent's tools if available, otherwise global + if let Some(ref agent) = agent { + let agent_guard = agent.lock().await; + if let Some(tool) = agent_guard.tools.iter().find(|t| t.name == name) { + let handler = tool.handler; + drop(agent_guard); + return match handler(Some(agent.clone()), args.clone()).await { + Ok(s) => s, + Err(e) => format!("Error: {}", e), + }; + } + } + // Fallback to global registry for tool in tools() { if tool.name == name { return match (tool.handler)(agent, args.clone()).await {