From 80869457bc069d84a07bfc0dce0914a38317e1b6 Mon Sep 17 00:00:00 2001 From: Salman Mohammed Date: Tue, 14 Jan 2025 15:27:54 -0500 Subject: [PATCH] fix: goose failure on first msg without adding system (#591) --- crates/goose/src/agents/capabilities.rs | 4 ++-- crates/goose/src/agents/default.rs | 17 ++++++++++------- crates/goose/src/prompts/system.md | 7 ++++++- crates/mcp-client/src/client.rs | 3 +++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/crates/goose/src/agents/capabilities.rs b/crates/goose/src/agents/capabilities.rs index 94a47cd11c..203e864fd2 100644 --- a/crates/goose/src/agents/capabilities.rs +++ b/crates/goose/src/agents/capabilities.rs @@ -93,7 +93,7 @@ impl Capabilities { SystemConfig::Sse { ref uri, ref envs } => { let transport = SseTransport::new(uri, envs.get_env()); let handle = transport.start().await?; - let service = McpService::with_timeout(handle, Duration::from_secs(10)); + let service = McpService::with_timeout(handle, Duration::from_secs(100)); Box::new(McpClient::new(service)) } SystemConfig::Stdio { @@ -103,7 +103,7 @@ impl Capabilities { } => { let transport = StdioTransport::new(cmd, args.to_vec(), envs.get_env()); let handle = transport.start().await?; - let service = McpService::with_timeout(handle, Duration::from_secs(10)); + let service = McpService::with_timeout(handle, Duration::from_secs(100)); Box::new(McpClient::new(service)) } }; diff --git a/crates/goose/src/agents/default.rs b/crates/goose/src/agents/default.rs index 1ecabeabdd..a73f5d9d3b 100644 --- a/crates/goose/src/agents/default.rs +++ b/crates/goose/src/agents/default.rs @@ -107,15 +107,18 @@ impl DefaultAgent { new_messages.push(msg.clone()); } - // Finally add the status messages - let message_use = - Message::assistant().with_tool_request("000", Ok(ToolCall::new("status", json!({})))); + // Finally add the status messages if status_str is not empty + // The status_str is empty for the first message when no systems are added + if !status_str.is_empty() { + let message_use = Message::assistant() + .with_tool_request("000", Ok(ToolCall::new("status", json!({})))); - let message_result = - Message::user().with_tool_response("000", Ok(vec![Content::text(status_str)])); + let message_result = + Message::user().with_tool_response("000", Ok(vec![Content::text(status_str)])); - new_messages.push(message_use); - new_messages.push(message_result); + new_messages.push(message_use); + new_messages.push(message_result); + } Ok(new_messages) } diff --git a/crates/goose/src/prompts/system.md b/crates/goose/src/prompts/system.md index 85385ed117..c902b96e01 100644 --- a/crates/goose/src/prompts/system.md +++ b/crates/goose/src/prompts/system.md @@ -2,8 +2,9 @@ You are a general purpose AI agent called Goose. You are capable of dynamically plugging into new systems and learning how to use them. You solve higher level problems using the tools in these systems, and can -interact with multiple at once. +interact with multiple at once. +{% if (systems is defined) and systems %} Because you dynamically load systems, your conversation history may refer to interactions with sytems that are not currently active. The currently active systems are below. Each of these systems provides tools that are @@ -18,3 +19,7 @@ in your tool specification. {% if system.instructions %}### Instructions {{system.instructions}}{% endif %} {% endfor %} + +{% else %} +No systems are defined. You should let the user know that they should add systems. +{% endif %} diff --git a/crates/mcp-client/src/client.rs b/crates/mcp-client/src/client.rs index 1eef8290ca..b50f6642d8 100644 --- a/crates/mcp-client/src/client.rs +++ b/crates/mcp-client/src/client.rs @@ -298,6 +298,9 @@ where } let params = serde_json::json!({ "name": name, "arguments": arguments }); + + // TODO ERROR: check that if there is an error, we send back is_error: true with msg + // https://modelcontextprotocol.io/docs/concepts/tools#error-handling-2 self.send_request("tools/call", params).await } }