diff --git a/src/agent/agent.rs b/src/agent/agent.rs index 8f9331e..ce150d0 100644 --- a/src/agent/agent.rs +++ b/src/agent/agent.rs @@ -286,7 +286,7 @@ impl Agent { for msg in self.history.drain(..) { match &msg { ConversationMessage::Chat(chat) if chat.role == "system" => { - system_messages.push(msg) + system_messages.push(msg); } _ => other_messages.push(msg), } @@ -655,7 +655,7 @@ mod tests { let provider = Box::new(MockProvider { responses: Mutex::new(vec![ crate::providers::ChatResponse { - text: Some("".into()), + text: Some(String::new()), tool_calls: vec![crate::providers::ToolCall { id: "tc1".into(), name: "echo".into(), @@ -690,12 +690,9 @@ mod tests { let response = agent.turn("hi").await.unwrap(); assert_eq!(response, "done"); - assert!(matches!( - agent - .history() - .iter() - .find(|msg| matches!(msg, ConversationMessage::ToolResults(_))), - Some(_) - )); + assert!(agent + .history() + .iter() + .any(|msg| matches!(msg, ConversationMessage::ToolResults(_)))); } } diff --git a/src/agent/mod.rs b/src/agent/mod.rs index 63bf3f8..89406ef 100644 --- a/src/agent/mod.rs +++ b/src/agent/mod.rs @@ -1,3 +1,4 @@ +#[allow(clippy::module_inception)] pub mod agent; pub mod dispatcher; pub mod loop_; diff --git a/src/providers/anthropic.rs b/src/providers/anthropic.rs index 56efeb8..fb940e9 100644 --- a/src/providers/anthropic.rs +++ b/src/providers/anthropic.rs @@ -72,7 +72,10 @@ enum NativeContentOut { input: serde_json::Value, }, #[serde(rename = "tool_result")] - ToolResult { tool_use_id: String, content: String }, + ToolResult { + tool_use_id: String, + content: String, + }, } #[derive(Debug, Serialize)] diff --git a/src/providers/openrouter.rs b/src/providers/openrouter.rs index 5363651..3a02e2d 100644 --- a/src/providers/openrouter.rs +++ b/src/providers/openrouter.rs @@ -356,9 +356,11 @@ impl Provider for OpenRouterProvider { model: &str, temperature: f64, ) -> anyhow::Result { - let api_key = self.api_key.as_ref().ok_or_else(|| anyhow::anyhow!( + let api_key = self.api_key.as_ref().ok_or_else(|| { + anyhow::anyhow!( "OpenRouter API key not set. Run `zeroclaw onboard` or set OPENROUTER_API_KEY env var." - ))?; + ) + })?; let tools = Self::convert_tools(request.tools); let native_request = NativeChatRequest { diff --git a/src/providers/traits.rs b/src/providers/traits.rs index fdbd5cc..2117e57 100644 --- a/src/providers/traits.rs +++ b/src/providers/traits.rs @@ -108,7 +108,8 @@ pub trait Provider: Send + Sync { model: &str, temperature: f64, ) -> anyhow::Result { - self.chat_with_system(None, message, model, temperature).await + self.chat_with_system(None, message, model, temperature) + .await } /// One-shot chat with optional system prompt. diff --git a/src/tools/mod.rs b/src/tools/mod.rs index 0a7a2bf..67c05a3 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -74,7 +74,7 @@ pub fn all_tools( browser_config: &crate::config::BrowserConfig, http_config: &crate::config::HttpRequestConfig, workspace_dir: &std::path::Path, - agents: &HashMap, + agents: &HashMap, fallback_api_key: Option<&str>, config: &crate::config::Config, ) -> Vec> { @@ -104,7 +104,7 @@ pub fn all_tools_with_runtime( browser_config: &crate::config::BrowserConfig, http_config: &crate::config::HttpRequestConfig, workspace_dir: &std::path::Path, - agents: &HashMap, + agents: &HashMap, fallback_api_key: Option<&str>, config: &crate::config::Config, ) -> Vec> { @@ -170,8 +170,12 @@ pub fn all_tools_with_runtime( // Add delegation tool when agents are configured if !agents.is_empty() { + let delegate_agents: HashMap = agents + .iter() + .map(|(name, cfg)| (name.clone(), cfg.clone())) + .collect(); tools.push(Box::new(DelegateTool::new( - agents.clone(), + delegate_agents, fallback_api_key.map(String::from), ))); }