Skip to content
Merged
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
15 changes: 13 additions & 2 deletions crates/goose/src/providers/formats/anthropic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use crate::model::ModelConfig;
use crate::providers::base::Usage;
use crate::providers::errors::ProviderError;
use anyhow::{anyhow, Result};
use rmcp::model::{object, CallToolRequestParam, ErrorCode, ErrorData, Role, Tool};
use rmcp::model::{object, CallToolRequestParam, ErrorCode, ErrorData, JsonObject, Role, Tool};
use rmcp::object as json_object;
use serde_json::{json, Value};
use std::collections::HashSet;
use std::sync::Arc;

// Constants for frequently used strings in Anthropic API format
const TYPE_FIELD: &str = "type";
Expand Down Expand Up @@ -168,6 +170,15 @@ pub fn format_messages(messages: &[Message]) -> Vec<Value> {
anthropic_messages
}

fn anthropic_flavored_input_schema(input_schema: Arc<JsonObject>) -> Arc<JsonObject> {
if input_schema.is_empty() {
return Arc::new(json_object!({
"type": "object",
}));
}
input_schema
}

/// Convert internal Tool format to Anthropic's API tool specification
pub fn format_tools(tools: &[Tool]) -> Vec<Value> {
let mut unique_tools = HashSet::new();
Expand All @@ -178,7 +189,7 @@ pub fn format_tools(tools: &[Tool]) -> Vec<Value> {
tool_specs.push(json!({
NAME_FIELD: tool.name,
"description": tool.description,
"input_schema": tool.input_schema
"input_schema": anthropic_flavored_input_schema(tool.input_schema.clone())
}));
}
}
Expand Down
Loading