Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

agent: Check built-in tools schema compatibility in tests (#28691)

Bennet Bo Fennera0511941958a
diff --git a/crates/assistant_tools/src/assistant_tools.rs b/crates/assistant_tools/src/assistant_tools.rs
index c0fd4f81c53..bede5866efd 100644
--- a/crates/assistant_tools/src/assistant_tools.rs
+++ b/crates/assistant_tools/src/assistant_tools.rs
@@ -76,3 +76,37 @@ pub fn init(http_client: Arc<HttpClientWithUrl>, cx: &mut App) {
registry.register_tool(ThinkingTool);
registry.register_tool(FetchTool::new(http_client));
}
+
+#[cfg(test)]
+mod tests {
+ use http_client::FakeHttpClient;
+
+ use super::*;
+
+ #[gpui::test]
+ fn test_tool_schema_compatibility(cx: &mut App) {
+ crate::init(
+ Arc::new(http_client::HttpClientWithUrl::new(
+ FakeHttpClient::with_200_response(),
+ "https://zed.dev",
+ None,
+ )),
+ cx,
+ );
+
+ for tool in ToolRegistry::global(cx).tools() {
+ let schema =
+ tool.input_schema(language_model::LanguageModelToolSchemaFormat::JsonSchemaSubset);
+ assert!(schema.is_object());
+ if schema.as_object().unwrap().contains_key("$schema") {
+ let error_message = format!(
+ "Tool schema for `{}` is not compatible with `language_model::LanguageModelToolSchemaFormat::JsonSchemaSubset` (Gemini Models).\n\
+ Are you using `schema::json_schema_for<T>(format)` to generate the schema?",
+ tool.name()
+ );
+
+ panic!("{}", error_message)
+ }
+ }
+ }
+}