feat: remove tools from chat mode (#1533)

This commit is contained in:
Yingjie He
2025-03-05 12:36:49 -08:00
committed by GitHub
parent 89fc871e9c
commit 09cae6e83d
3 changed files with 28 additions and 28 deletions
+16 -11
View File
@@ -11,6 +11,7 @@ use tokio::sync::Mutex;
use tracing::{debug, instrument};
use super::extension::{ExtensionConfig, ExtensionError, ExtensionInfo, ExtensionResult};
use crate::config::Config;
use crate::prompt_template;
use crate::providers::base::{Provider, ProviderUsage};
use mcp_client::client::{ClientCapabilities, ClientInfo, McpClient, McpClientTrait};
@@ -325,19 +326,23 @@ impl Capabilities {
pub async fn get_system_prompt(&self) -> String {
let mut context: HashMap<&str, Value> = HashMap::new();
let extensions_info: Vec<ExtensionInfo> = 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();
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<ExtensionInfo> = 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("extensions", serde_json::to_value(extensions_info).unwrap());
context.insert("current_date_time", Value::String(current_date_time));
// Conditionally load the override prompt or the global system prompt
+9 -15
View File
@@ -206,6 +206,14 @@ 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
@@ -315,21 +323,7 @@ impl Agent for TruncateAgent {
},
"chat" => {
// Skip all tool calls in chat mode
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."
)]),
);
}
break;
},
_ => {
if mode != "auto" {