feat: strip ALL tools from intercepted requests by default

Tools are only needed by the Antigravity webview for tool-call UI.
Our proxy doesn't need them — the model generates text responses fine
without tool definitions. Stripping all 20 tools saves ~15KB per request.
This commit is contained in:
Nikketryhard
2026-02-14 18:53:38 -06:00
parent 89a8422291
commit 1a7c81e5f9

View File

@@ -7,21 +7,10 @@
use serde_json::Value; use serde_json::Value;
use tracing::info; use tracing::info;
/// Tools to KEEP — essential coding tools. Everything else gets stripped. /// Whether to strip ALL tool definitions (default: true).
const KEEP_TOOLS: &[&str] = &[ /// The model generates responses fine without them — tools are only
"view_file", /// needed by the Antigravity webview, not by our proxy.
"write_to_file", const STRIP_ALL_TOOLS: bool = true;
"replace_file_content",
"multi_replace_file_content",
"run_command",
"command_status",
"send_command_input",
"grep_search",
"find_by_name",
"list_dir",
"view_file_outline",
"view_code_item",
];
/// System instruction sections to STRIP (matched by XML tag name). /// System instruction sections to STRIP (matched by XML tag name).
/// These are verbose instructional manuals that add tokens but don't /// These are verbose instructional manuals that add tokens but don't
@@ -124,24 +113,17 @@ pub fn modify_request(body: &[u8]) -> Option<Vec<u8>> {
} }
} }
// ── 3. Strip non-essential tools ───────────────────────────────────── // ── 3. Strip tool definitions ────────────────────────────────────────
if let Some(tools) = json if STRIP_ALL_TOOLS {
.pointer_mut("/request/tools") if let Some(tools) = json
.and_then(|v| v.as_array_mut()) .pointer_mut("/request/tools")
{ .and_then(|v| v.as_array_mut())
let before = tools.len(); {
let count = tools.len();
tools.retain(|tool| { if count > 0 {
if let Some(name) = tool["functionDeclarations"][0]["name"].as_str() { tools.clear();
KEEP_TOOLS.contains(&name) changes.push(format!("strip all {count} tools"));
} else {
true // keep unknown structure
} }
});
let removed = before - tools.len();
if removed > 0 {
changes.push(format!("strip {removed}/{before} tools (keep {})", KEEP_TOOLS.len()));
} }
} }
@@ -255,7 +237,7 @@ mod tests {
} }
#[test] #[test]
fn test_modify_strips_tools() { fn test_modify_strips_all_tools() {
let body = serde_json::json!({ let body = serde_json::json!({
"project": "test", "project": "test",
"requestId": "test/1", "requestId": "test/1",
@@ -265,7 +247,6 @@ mod tests {
{"functionDeclarations": [{"name": "view_file", "description": "view", "parameters": {}}]}, {"functionDeclarations": [{"name": "view_file", "description": "view", "parameters": {}}]},
{"functionDeclarations": [{"name": "browser_subagent", "description": "browse", "parameters": {}}]}, {"functionDeclarations": [{"name": "browser_subagent", "description": "browse", "parameters": {}}]},
{"functionDeclarations": [{"name": "grep_search", "description": "grep", "parameters": {}}]}, {"functionDeclarations": [{"name": "grep_search", "description": "grep", "parameters": {}}]},
{"functionDeclarations": [{"name": "generate_image", "description": "img", "parameters": {}}]},
], ],
"generationConfig": {} "generationConfig": {}
}, },
@@ -276,17 +257,8 @@ mod tests {
let modified = modify_request(&bytes).unwrap(); let modified = modify_request(&bytes).unwrap();
let result: Value = serde_json::from_slice(&modified).unwrap(); let result: Value = serde_json::from_slice(&modified).unwrap();
let tool_names: Vec<&str> = result["request"]["tools"] let tools = result["request"]["tools"].as_array().unwrap();
.as_array() assert!(tools.is_empty(), "all tools should be stripped");
.unwrap()
.iter()
.map(|t| t["functionDeclarations"][0]["name"].as_str().unwrap())
.collect();
assert!(tool_names.contains(&"view_file"));
assert!(tool_names.contains(&"grep_search"));
assert!(!tool_names.contains(&"browser_subagent"));
assert!(!tool_names.contains(&"generate_image"));
} }
#[test] #[test]