Skip to content

Commit 8f6cfd2

Browse files
author
kiran-garre
committed
fix: Fix /experiment to properly update tool spec
1 parent ccf1dbb commit 8f6cfd2

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

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

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

15+
use crate::cli::chat::conversation::format_tool_spec;
1516
use crate::cli::chat::{
1617
ChatError,
1718
ChatSession,
@@ -140,11 +141,14 @@ async fn select_experiment(os: &mut Os, session: &mut ChatSession) -> Result<Opt
140141
.map_err(|e| ChatError::Custom(format!("Failed to update experiment setting: {e}").into()))?;
141142

142143
// Reload tools to reflect the experiment change
143-
let _ = session
144+
let tools = session
144145
.conversation
145146
.tool_manager
146147
.load_tools(os, &mut session.stderr)
147-
.await;
148+
.await
149+
.map_err(|e| ChatError::Custom(format!("Failed to update tool spec: {e}").into()))?;
150+
151+
session.conversation.tools = format_tool_spec(tools);
148152

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

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,7 @@ impl ConversationState {
188188
history: VecDeque::new(),
189189
valid_history_range: Default::default(),
190190
transcript: VecDeque::with_capacity(MAX_CONVERSATION_STATE_HISTORY_LEN),
191-
tools: tool_config
192-
.into_values()
193-
.fold(HashMap::<ToolOrigin, Vec<Tool>>::new(), |mut acc, v| {
194-
let tool = Tool::ToolSpecification(ToolSpecification {
195-
name: v.name,
196-
description: v.description,
197-
input_schema: v.input_schema.into(),
198-
});
199-
acc.entry(v.tool_origin)
200-
.and_modify(|tools| tools.push(tool.clone()))
201-
.or_insert(vec![tool]);
202-
acc
203-
}),
191+
tools: format_tool_spec(tool_config),
204192
context_manager,
205193
tool_manager,
206194
context_message_length: None,
@@ -854,6 +842,22 @@ Return only the JSON configuration, no additional text.",
854842
}
855843
}
856844

845+
pub fn format_tool_spec(tool_spec: HashMap<String, ToolSpec>) -> HashMap<ToolOrigin, Vec<Tool>> {
846+
tool_spec
847+
.into_values()
848+
.fold(HashMap::<ToolOrigin, Vec<Tool>>::new(), |mut acc, v| {
849+
let tool = Tool::ToolSpecification(ToolSpecification {
850+
name: v.name,
851+
description: v.description,
852+
input_schema: v.input_schema.into(),
853+
});
854+
acc.entry(v.tool_origin)
855+
.and_modify(|tools| tools.push(tool.clone()))
856+
.or_insert(vec![tool]);
857+
acc
858+
})
859+
}
860+
857861
/// Represents a conversation state that can be converted into a [FigConversationState] (the type
858862
/// used by the API client). Represents borrowed data, and reflects an exact [FigConversationState]
859863
/// that can be generated from [ConversationState] at any point in time.

0 commit comments

Comments
 (0)