Skip to content

Commit 7278289

Browse files
kensavekennvene-aws
andcommitted
[fix] Reloads only the built-in tools only for /experiment (#3012)
* Makes sure only built in tools are reloaded. Co-authored-by: Kenneth S. <[email protected]>
1 parent 041b86c commit 7278289

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

crates/chat-cli/src/cli/chat/cli/experiment.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crossterm::{
1212
};
1313
use dialoguer::Select;
1414

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

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

174-
session.conversation.tools = format_tool_spec(tools);
175-
176172
let status_text = if new_state { "enabled" } else { "disabled" };
177173

178174
queue!(

crates/chat-cli/src/cli/chat/conversation.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,21 @@ Return only the JSON configuration, no additional text.",
912912
Ok(())
913913
}
914914

915+
/// Reloads only built-in tools while preserving MCP tools
916+
pub async fn reload_builtin_tools(&mut self, os: &mut Os, stderr: &mut impl Write) -> Result<(), ChatError> {
917+
let builtin_tools = self
918+
.tool_manager
919+
.load_tools(os, stderr)
920+
.await
921+
.map_err(|e| ChatError::Custom(format!("Failed to reload built-in tools: {e}").into()))?;
922+
923+
// Remove existing built-in tools and add updated ones, preserving MCP tools
924+
self.tools.retain(|origin, _| *origin != ToolOrigin::Native);
925+
self.tools.extend(format_tool_spec(builtin_tools));
926+
927+
Ok(())
928+
}
929+
915930
/// Swapping agent involves the following:
916931
/// - Reinstantiate the context manager
917932
/// - Swap agent on tool manager

0 commit comments

Comments
 (0)