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 {