Skip to content
Open
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
93 changes: 90 additions & 3 deletions crates/goose/src/providers/formats/databricks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,24 @@ fn format_messages(messages: &[Message], image_format: &ImageFormat) -> Vec<Data
})
.unwrap_or_else(|| "{}".to_string());

converted.tool_calls.get_or_insert_default().push(json!({
let tool_calls = converted.tool_calls.get_or_insert_default();
let mut tool_call_json = json!({
"id": request.id,
"type": "function",
"function": {"name": sanitized_name, "arguments": arguments_str}
}));
"function": {
"name": sanitized_name,
"arguments": arguments_str,
}
});

// Include all metadata fields in the tool call (e.g., thoughtSignature, extra_content)
if let Some(metadata) = &request.metadata {
for (key, value) in metadata {
tool_call_json[key] = value.clone();
}
}

tool_calls.push(tool_call_json);
}
Err(e) => {
content_array
Expand Down Expand Up @@ -1347,6 +1360,39 @@ mod tests {
Ok(())
}

#[test]
fn test_format_messages_with_thought_signature_metadata() -> anyhow::Result<()> {
// Test that thoughtSignature in metadata is included in formatted tool calls
let mut metadata = serde_json::Map::new();
metadata.insert(
"thoughtSignature".to_string(),
json!("sig_abc123_test_signature"),
);

let message = Message::assistant().with_tool_request_with_metadata(
"tool1",
Ok(CallToolRequestParam {
name: "test_tool".into(),
arguments: Some(object!({"param": "value"})),
}),
Some(&metadata),
None,
);

let spec = format_messages(&[message], &ImageFormat::OpenAi);
let as_value = serde_json::to_value(spec)?;
let spec_array = as_value.as_array().unwrap();

assert_eq!(spec_array.len(), 1);
let tool_call = &spec_array[0]["tool_calls"][0];
assert_eq!(tool_call["id"], "tool1");
assert_eq!(tool_call["function"]["name"], "test_tool");
// Verify thoughtSignature is included at top level of tool_call
assert_eq!(tool_call["thoughtSignature"], "sig_abc123_test_signature");

Ok(())
}

#[test]
fn test_create_request_claude_has_cache_control() -> anyhow::Result<()> {
let model_config = ModelConfig {
Expand Down Expand Up @@ -1440,4 +1486,45 @@ mod tests {

Ok(())
}

#[test]
fn test_format_messages_with_multiple_metadata_fields() -> anyhow::Result<()> {
// Test that multiple metadata fields are all preserved
let mut metadata = serde_json::Map::new();
metadata.insert("thoughtSignature".to_string(), json!("sig_top_level"));
metadata.insert(
"extra_content".to_string(),
json!({
"google": {
"thought_signature": "sig_nested"
}
}),
);
metadata.insert("custom_field".to_string(), json!("custom_value"));

let message = Message::assistant().with_tool_request_with_metadata(
"tool1",
Ok(CallToolRequestParam {
name: "test_tool".into(),
arguments: None,
}),
Some(&metadata),
None,
);

let spec = format_messages(&[message], &ImageFormat::OpenAi);
let as_value = serde_json::to_value(spec)?;
let spec_array = as_value.as_array().unwrap();

let tool_call = &spec_array[0]["tool_calls"][0];
// All metadata fields should be present
assert_eq!(tool_call["thoughtSignature"], "sig_top_level");
assert_eq!(
tool_call["extra_content"]["google"]["thought_signature"],
"sig_nested"
);
assert_eq!(tool_call["custom_field"], "custom_value");

Ok(())
}
}
Loading