Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions crates/chat-cli/src/cli/chat/cli/experiment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crossterm::{
};
use dialoguer::Select;

use crate::cli::chat::conversation::format_tool_spec;
use crate::cli::chat::{
ChatError,
ChatSession,
Expand Down Expand Up @@ -163,16 +162,13 @@ async fn select_experiment(os: &mut Os, session: &mut ChatSession) -> Result<Opt
.await
.map_err(|e| ChatError::Custom(format!("Failed to update experiment setting: {e}").into()))?;

// Reload tools to reflect the experiment change
let tools = session
// Reload built-in tools to reflect the experiment change while preserving MCP tools
session
.conversation
.tool_manager
.load_tools(os, &mut session.stderr)
.reload_builtin_tools(os, &mut session.stderr)
.await
.map_err(|e| ChatError::Custom(format!("Failed to update tool spec: {e}").into()))?;

session.conversation.tools = format_tool_spec(tools);

let status_text = if new_state { "enabled" } else { "disabled" };

queue!(
Expand Down
15 changes: 15 additions & 0 deletions crates/chat-cli/src/cli/chat/conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,21 @@ Return only the JSON configuration, no additional text.",
Ok(())
}

/// Reloads only built-in tools while preserving MCP tools
pub async fn reload_builtin_tools(&mut self, os: &mut Os, stderr: &mut impl Write) -> Result<(), ChatError> {
let builtin_tools = self
.tool_manager
.load_tools(os, stderr)
.await
.map_err(|e| ChatError::Custom(format!("Failed to reload built-in tools: {e}").into()))?;

// Remove existing built-in tools and add updated ones, preserving MCP tools
self.tools.retain(|origin, _| *origin != ToolOrigin::Native);
self.tools.extend(format_tool_spec(builtin_tools));

Ok(())
}

/// Swapping agent involves the following:
/// - Reinstantiate the context manager
/// - Swap agent on tool manager
Expand Down