perf(toolshim): compact tool schema JSON (#10409)

This commit is contained in:
Dex Hunter
2026-07-31 12:05:34 +01:00
committed by GitHub
parent 78f062c8ad
commit 950575bcd3
+20 -1
View File
@@ -878,7 +878,7 @@ pub fn format_tool_info(tools: &[Tool]) -> String {
tool_info.push_str(&format!(
"Tool Name: {}\nSchema: {}\nDescription: {:?}\n\n",
tool.name,
serde_json::to_string_pretty(&tool.input_schema).unwrap_or_default(),
serde_json::to_string(&tool.input_schema).unwrap_or_default(),
tool.description
));
}
@@ -1061,6 +1061,25 @@ mod tests {
}
}
#[test]
fn formats_tool_schemas_as_compact_lossless_json() {
let schema = object(
json!({"type": "object", "properties": {"query": {"type": "string", "description": "café 工"}, "options": {"type": "object", "properties": {}}}}),
);
let tool = Tool::new("search".to_string(), "Search records".to_string(), schema);
let output = format_tool_info(std::slice::from_ref(&tool));
let description = format!("\nDescription: {:?}\n\n", tool.description);
let schema = output
.strip_prefix("Tool Name: search\nSchema: ")
.and_then(|value| value.strip_suffix(&description))
.unwrap();
assert!(!schema.contains('\n'));
let parsed: Value = serde_json::from_str(schema).unwrap();
assert_eq!(parsed, serde_json::to_value(&tool.input_schema).unwrap());
}
#[test]
fn parses_toolshim_backend_values() {
assert_eq!(