refactor: improve code formatting and structure across multiple files
This commit is contained in:
parent
b341fdb368
commit
dc5e14d7d2
6 changed files with 24 additions and 16 deletions
|
|
@ -286,7 +286,7 @@ impl Agent {
|
||||||
for msg in self.history.drain(..) {
|
for msg in self.history.drain(..) {
|
||||||
match &msg {
|
match &msg {
|
||||||
ConversationMessage::Chat(chat) if chat.role == "system" => {
|
ConversationMessage::Chat(chat) if chat.role == "system" => {
|
||||||
system_messages.push(msg)
|
system_messages.push(msg);
|
||||||
}
|
}
|
||||||
_ => other_messages.push(msg),
|
_ => other_messages.push(msg),
|
||||||
}
|
}
|
||||||
|
|
@ -655,7 +655,7 @@ mod tests {
|
||||||
let provider = Box::new(MockProvider {
|
let provider = Box::new(MockProvider {
|
||||||
responses: Mutex::new(vec![
|
responses: Mutex::new(vec![
|
||||||
crate::providers::ChatResponse {
|
crate::providers::ChatResponse {
|
||||||
text: Some("".into()),
|
text: Some(String::new()),
|
||||||
tool_calls: vec![crate::providers::ToolCall {
|
tool_calls: vec![crate::providers::ToolCall {
|
||||||
id: "tc1".into(),
|
id: "tc1".into(),
|
||||||
name: "echo".into(),
|
name: "echo".into(),
|
||||||
|
|
@ -690,12 +690,9 @@ mod tests {
|
||||||
|
|
||||||
let response = agent.turn("hi").await.unwrap();
|
let response = agent.turn("hi").await.unwrap();
|
||||||
assert_eq!(response, "done");
|
assert_eq!(response, "done");
|
||||||
assert!(matches!(
|
assert!(agent
|
||||||
agent
|
.history()
|
||||||
.history()
|
.iter()
|
||||||
.iter()
|
.any(|msg| matches!(msg, ConversationMessage::ToolResults(_))));
|
||||||
.find(|msg| matches!(msg, ConversationMessage::ToolResults(_))),
|
|
||||||
Some(_)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#[allow(clippy::module_inception)]
|
||||||
pub mod agent;
|
pub mod agent;
|
||||||
pub mod dispatcher;
|
pub mod dispatcher;
|
||||||
pub mod loop_;
|
pub mod loop_;
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,10 @@ enum NativeContentOut {
|
||||||
input: serde_json::Value,
|
input: serde_json::Value,
|
||||||
},
|
},
|
||||||
#[serde(rename = "tool_result")]
|
#[serde(rename = "tool_result")]
|
||||||
ToolResult { tool_use_id: String, content: String },
|
ToolResult {
|
||||||
|
tool_use_id: String,
|
||||||
|
content: String,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
|
|
|
||||||
|
|
@ -356,9 +356,11 @@ impl Provider for OpenRouterProvider {
|
||||||
model: &str,
|
model: &str,
|
||||||
temperature: f64,
|
temperature: f64,
|
||||||
) -> anyhow::Result<ProviderChatResponse> {
|
) -> anyhow::Result<ProviderChatResponse> {
|
||||||
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."
|
"OpenRouter API key not set. Run `zeroclaw onboard` or set OPENROUTER_API_KEY env var."
|
||||||
))?;
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
let tools = Self::convert_tools(request.tools);
|
let tools = Self::convert_tools(request.tools);
|
||||||
let native_request = NativeChatRequest {
|
let native_request = NativeChatRequest {
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,8 @@ pub trait Provider: Send + Sync {
|
||||||
model: &str,
|
model: &str,
|
||||||
temperature: f64,
|
temperature: f64,
|
||||||
) -> anyhow::Result<String> {
|
) -> anyhow::Result<String> {
|
||||||
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.
|
/// One-shot chat with optional system prompt.
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ pub fn all_tools(
|
||||||
browser_config: &crate::config::BrowserConfig,
|
browser_config: &crate::config::BrowserConfig,
|
||||||
http_config: &crate::config::HttpRequestConfig,
|
http_config: &crate::config::HttpRequestConfig,
|
||||||
workspace_dir: &std::path::Path,
|
workspace_dir: &std::path::Path,
|
||||||
agents: &HashMap<String, DelegateAgentConfig>,
|
agents: &HashMap<String, DelegateAgentConfig, S>,
|
||||||
fallback_api_key: Option<&str>,
|
fallback_api_key: Option<&str>,
|
||||||
config: &crate::config::Config,
|
config: &crate::config::Config,
|
||||||
) -> Vec<Box<dyn Tool>> {
|
) -> Vec<Box<dyn Tool>> {
|
||||||
|
|
@ -104,7 +104,7 @@ pub fn all_tools_with_runtime(
|
||||||
browser_config: &crate::config::BrowserConfig,
|
browser_config: &crate::config::BrowserConfig,
|
||||||
http_config: &crate::config::HttpRequestConfig,
|
http_config: &crate::config::HttpRequestConfig,
|
||||||
workspace_dir: &std::path::Path,
|
workspace_dir: &std::path::Path,
|
||||||
agents: &HashMap<String, DelegateAgentConfig>,
|
agents: &HashMap<String, DelegateAgentConfig, S>,
|
||||||
fallback_api_key: Option<&str>,
|
fallback_api_key: Option<&str>,
|
||||||
config: &crate::config::Config,
|
config: &crate::config::Config,
|
||||||
) -> Vec<Box<dyn Tool>> {
|
) -> Vec<Box<dyn Tool>> {
|
||||||
|
|
@ -170,8 +170,12 @@ pub fn all_tools_with_runtime(
|
||||||
|
|
||||||
// Add delegation tool when agents are configured
|
// Add delegation tool when agents are configured
|
||||||
if !agents.is_empty() {
|
if !agents.is_empty() {
|
||||||
|
let delegate_agents: HashMap<String, DelegateAgentConfig> = agents
|
||||||
|
.iter()
|
||||||
|
.map(|(name, cfg)| (name.clone(), cfg.clone()))
|
||||||
|
.collect();
|
||||||
tools.push(Box::new(DelegateTool::new(
|
tools.push(Box::new(DelegateTool::new(
|
||||||
agents.clone(),
|
delegate_agents,
|
||||||
fallback_api_key.map(String::from),
|
fallback_api_key.map(String::from),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue