Skip to content

Commit 21f2d45

Browse files
humbertoyustaolegklimov
authored andcommitted
fix: filter out tools with array parameters for non-claude models
1 parent a83444f commit 21f2d45

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

refact-agent/engine/src/scratchpads/chat_passthrough.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl ScratchpadAbstract for ChatPassthrough {
195195
} else {
196196
let allow_experimental = gcx.read().await.cmdline.experimental;
197197
let tool_descriptions = tool_description_list_from_yaml(at_tools, Some(&turned_on), allow_experimental).await?;
198-
Some(tool_descriptions.into_iter().map(|x: crate::tools::tools_description::ToolDesc|x.into_openai_style()).collect::<Vec<_>>())
198+
Some(tool_descriptions.into_iter().filter(|x| x.is_supported_by(&self.post.model)).map(|x| x.into_openai_style()).collect::<Vec<_>>())
199199
}
200200
} else {
201201
None

refact-agent/engine/src/subchat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub async fn subchat_single(
295295
error!("Error loading compiled_in_tools: {:?}", e);
296296
vec![]
297297
});
298-
let tools = tools_desclist.into_iter().map(|x|x.into_openai_style()).collect::<Vec<_>>();
298+
let tools = tools_desclist.into_iter().filter(|x| x.is_supported_by(model_name)).map(|x|x.into_openai_style()).collect::<Vec<_>>();
299299
info!("tools_subset {:?}", tools_subset);
300300
info!("tools_turned_on_by_cmdline_set {:?}", tools_turned_on_by_cmdline_set);
301301
info!("tools_on_intersection {:?}", tools_on_intersection);

refact-agent/engine/src/tools/tools_description.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,13 @@ fn default_param_type() -> String {
565565
"string".to_string()
566566
}
567567

568+
/// TODO: Think a better way to know if we can send array type to the model
569+
///
570+
/// For now, anthropic models support it, gpt models don't, for other, we'll need to test
571+
pub fn model_supports_array_param_type(model_name: &str) -> bool {
572+
model_name.starts_with("claude")
573+
}
574+
568575
pub fn make_openai_tool_value(
569576
name: String,
570577
agentic: bool,
@@ -608,6 +615,18 @@ impl ToolDesc {
608615
self.parameters,
609616
)
610617
}
618+
619+
pub fn is_supported_by(&self, model: &str) -> bool {
620+
if !model_supports_array_param_type(model) {
621+
for param in &self.parameters {
622+
if param.param_type == "array" {
623+
tracing::error!("Tool {} has array parameter, but model {} does not support it", self.name, model);
624+
return false;
625+
}
626+
}
627+
}
628+
true
629+
}
611630
}
612631

613632
#[derive(Deserialize)]

0 commit comments

Comments
 (0)