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
47 changes: 34 additions & 13 deletions crates/goose/src/providers/formats/databricks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::conversation::message::{Message, MessageContent};
use crate::model::ModelConfig;
use crate::providers::formats::google as gemini_schema;
use crate::providers::utils::{
convert_image, detect_image_path, is_valid_function_name, load_image_file, safely_parse_json,
sanitize_function_name, ImageFormat,
Expand Down Expand Up @@ -232,19 +231,35 @@ pub fn format_tools(tools: &[Tool], model_name: &str) -> anyhow::Result<Vec<Valu
return Err(anyhow!("Duplicate tool name: {}", tool.name));
}

let parameters = if is_gemini {
gemini_schema::process_map(tool.input_schema.as_ref(), None)
let has_properties = tool
.input_schema
.get("properties")
.and_then(|v| v.as_object())
.is_some_and(|p| !p.is_empty());

let function_def = if is_gemini {
let mut def = json!({
"name": tool.name,
"description": tool.description,
});
if has_properties {
def["parametersJsonSchema"] = json!(tool.input_schema);
}
def
} else {
json!(tool.input_schema)
let mut def = json!({
"name": tool.name,
"description": tool.description,
});
if has_properties {
def["parameters"] = json!(tool.input_schema);
}
def
};

result.push(json!({
"type": "function",
"function": {
"name": tool.name,
"description": tool.description,
"parameters": parameters,
}
"function": function_def,
}));
}

Expand Down Expand Up @@ -718,12 +733,18 @@ mod tests {
);

let spec = format_tools(std::slice::from_ref(&tool), "gemini-2-5-flash")?;
assert!(spec[0]["function"]["parameters"].get("$schema").is_none());
assert_eq!(spec[0]["function"]["parameters"]["type"], "object");
assert!(spec[0]["function"].get("parametersJsonSchema").is_some());
assert_eq!(
spec[0]["function"]["parametersJsonSchema"]["type"],
"object"
);

let spec = format_tools(&[tool], "databricks-gemini-3-pro")?;
assert!(spec[0]["function"]["parameters"].get("$schema").is_none());
assert_eq!(spec[0]["function"]["parameters"]["type"], "object");
assert!(spec[0]["function"].get("parametersJsonSchema").is_some());
assert_eq!(
spec[0]["function"]["parametersJsonSchema"]["type"],
"object"
);

Ok(())
}
Expand Down
Loading