Skip to content

Commit

Permalink
fix: apply cache control correctly to tools (block#1071)
Browse files Browse the repository at this point in the history
  • Loading branch information
yingjiehe-xyz authored Feb 5, 2025
1 parent 180dff9 commit 40ac1cd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/goose/src/providers/openrouter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,23 @@ fn update_request_for_anthropic(original_payload: &Value) -> Value {
}
}
}

if let Some(tools_spec) = payload
.as_object_mut()
.and_then(|obj| obj.get_mut("tools"))
.and_then(|tools| tools.as_array_mut())
{
// Add "cache_control" to the last tool spec, if any. This means that all tool definitions,
// will be cached as a single prefix.
if let Some(last_tool) = tools_spec.last_mut() {
if let Some(function) = last_tool.get_mut("function") {
function
.as_object_mut()
.unwrap()
.insert("cache_control".to_string(), json!({ "type": "ephemeral" }));
}
}
}
payload
}

Expand Down

0 comments on commit 40ac1cd

Please sign in to comment.