From 471b4a54cbc72daa1a2b7472614ff95547f6f014 Mon Sep 17 00:00:00 2001 From: Yingjie He Date: Wed, 5 Mar 2025 15:40:22 -0800 Subject: [PATCH 1/2] fix: get tool def back to chat mode --- crates/goose/src/agents/capabilities.rs | 39 ++++++++++++++----------- crates/goose/src/agents/truncate.rs | 24 +++++++++------ crates/goose/src/prompts/system.md | 3 +- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/crates/goose/src/agents/capabilities.rs b/crates/goose/src/agents/capabilities.rs index 805848c586a2..237182387c45 100644 --- a/crates/goose/src/agents/capabilities.rs +++ b/crates/goose/src/agents/capabilities.rs @@ -326,21 +326,16 @@ impl Capabilities { pub async fn get_system_prompt(&self) -> String { let mut context: HashMap<&str, Value> = HashMap::new(); - let config = Config::global(); - let goose_mode = config.get("GOOSE_MODE").unwrap_or("auto".to_string()); - // In chat mode, we don't need to have the extensions to confuse LLM and it can help save cost as well. - if goose_mode != "chat" { - let extensions_info: Vec = self - .clients - .keys() - .map(|name| { - let instructions = self.instructions.get(name).cloned().unwrap_or_default(); - let has_resources = self.resource_capable_extensions.contains(name); - ExtensionInfo::new(name, &instructions, has_resources) - }) - .collect(); - context.insert("extensions", serde_json::to_value(extensions_info).unwrap()); - } + let extensions_info: Vec = self + .clients + .keys() + .map(|name| { + let instructions = self.instructions.get(name).cloned().unwrap_or_default(); + let has_resources = self.resource_capable_extensions.contains(name); + ExtensionInfo::new(name, &instructions, has_resources) + }) + .collect(); + context.insert("extensions", serde_json::to_value(extensions_info).unwrap()); let current_date_time = Utc::now().format("%Y-%m-%d %H:%M:%S").to_string(); context.insert("current_date_time", Value::String(current_date_time)); @@ -354,13 +349,23 @@ impl Capabilities { .expect("Prompt should render") }; - if self.system_prompt_extensions.is_empty() { + let mut system_prompt_extensions = self.system_prompt_extensions.clone(); + let config = Config::global(); + let goose_mode = config.get("GOOSE_MODE").unwrap_or("auto".to_string()); + if goose_mode == "chat" { + system_prompt_extensions.push( + "Right now you are in the chat only mode, no access to any tool use and system." + .to_string(), + ); + } + + if system_prompt_extensions.is_empty() { base_prompt } else { format!( "{}\n\n# Additional Instructions:\n\n{}", base_prompt, - self.system_prompt_extensions.join("\n\n") + system_prompt_extensions.join("\n\n") ) } } diff --git a/crates/goose/src/agents/truncate.rs b/crates/goose/src/agents/truncate.rs index c5c132a4a17a..fc3414f84c71 100644 --- a/crates/goose/src/agents/truncate.rs +++ b/crates/goose/src/agents/truncate.rs @@ -206,14 +206,6 @@ impl Agent for TruncateAgent { tools.push(list_resources_tool); } - if goose_mode == "chat" { - tools.clear(); - capabilities.add_system_prompt_extension( - "Right now you are in the chat only mode, no access to any tool use and system." - .to_string(), - ); - } - let system_prompt = capabilities.get_system_prompt().await; // Set the user_message field in the span instead of creating a new event @@ -323,7 +315,21 @@ impl Agent for TruncateAgent { }, "chat" => { // Skip all tool calls in chat mode - break; + for request in &tool_requests { + message_tool_response = message_tool_response.with_tool_response( + request.id.clone(), + Ok(vec![Content::text( + "Let the user know the tool call was skipped in Goose chat mode. \ + DO NOT apologize for skipping the tool call. DO NOT say sorry. \ + Provide an explanation of what the tool call would do, structured as a \ + plan for the user. Again, DO NOT apologize. \ + **Example Plan:**\n \ + 1. **Identify Task Scope** - Determine the purpose and expected outcome.\n \ + 2. **Outline Steps** - Break down the steps.\n \ + If needed, adjust the explanation based on user preferences or questions." + )]), + ); + } }, _ => { if mode != "auto" { diff --git a/crates/goose/src/prompts/system.md b/crates/goose/src/prompts/system.md index f92dabcc5159..ad154ca138d1 100644 --- a/crates/goose/src/prompts/system.md +++ b/crates/goose/src/prompts/system.md @@ -5,13 +5,12 @@ The current date is {{current_date_time}}. Goose uses LLM providers with tool calling capability. You can be used with different language models (gpt-4o, claude-3.5-sonnet, o1, llama-3.2, deepseek-r1, etc). These models have varying knowledge cut-off dates depending on when they were trained, but typically it's between 5-10 months prior to the current date. -{% if (extensions is defined) and extensions %} - # Extensions Extensions allow other applications to provide context to Goose. Extensions connect Goose to different data sources and tools. You are capable of dynamically plugging into new extensions and learning how to use them. You solve higher level problems using the tools in these extensions, and can interact with multiple at once. +{% if (extensions is defined) and extensions %} Because you dynamically load extensions, your conversation history may refer to interactions with extensions that are not currently active. The currently active extensions are below. Each of these extensions provides tools that are From ca5f1fd0ff2b3a5a7dbad5c723f6febc3f5bc697 Mon Sep 17 00:00:00 2001 From: Yingjie He Date: Wed, 5 Mar 2025 16:22:12 -0800 Subject: [PATCH 2/2] refresh --- crates/goose/src/agents/capabilities.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/goose/src/agents/capabilities.rs b/crates/goose/src/agents/capabilities.rs index 237182387c45..2b61438c725d 100644 --- a/crates/goose/src/agents/capabilities.rs +++ b/crates/goose/src/agents/capabilities.rs @@ -357,6 +357,9 @@ impl Capabilities { "Right now you are in the chat only mode, no access to any tool use and system." .to_string(), ); + } else { + system_prompt_extensions + .push("Right now you are *NOT* in the chat only mode and have access to tool use and system.".to_string()); } if system_prompt_extensions.is_empty() {