Add ranked tool discovery to JavaScript code mode (#51209)

## What changed

- Add the default-disabled `code_mode_tool_search` feature to expose `await tools.tool_search({query: "...", limit: 8})` in code mode when the model supports tool search.
- Return BM25-ranked deferred tools as `{tools: [{name, description}]}`, including callable names and TypeScript declarations for use in later code cells.
- Filter results through the current step's nested-tool policy before applying the limit, preserving namespace restrictions, normalized identities, description prefixes, and schema budgets.
- Add ranked-search guidance while retaining `ALL_TOOLS` catalog discovery and description overrides.

## Testing

Add coverage for feature and model-capability gating, namespace restrictions, argument validation, schema budgets, and discovery followed by deferred MCP and dynamic tool calls. Extend the scenario snapshot to cover search, invocation, yielding, and completion through `wait`.

GitOrigin-RevId: 092a29dd5f0773c518f53a001b9cafb917422f13
This commit is contained in:
Alex Zamoshchin
2026-10-06 00:36:25 +00:00
committed by copyberry
parent 5ad6891696
commit 4d15794336
23 changed files with 1125 additions and 248 deletions
+32 -1
View File
@@ -223,7 +223,38 @@ fn code_mode_tool_definitions_for_spec(
}
})
.collect(),
ToolSpec::ToolSearch { .. } | ToolSpec::WebSearch { .. } => Vec::new(),
ToolSpec::ToolSearch { parameters, .. } => {
let name = spec.name().to_string();
vec![CodeModeToolDefinition {
tool_name: ToolName::plain(name.clone()),
name,
description: codex_code_mode::TOOL_SEARCH_GUIDANCE.to_string(),
kind: CodeModeToolKind::Function,
input_schema: serde_json::to_value(parameters).ok(),
input_schema_max_bytes: Some(effective_input_schema_max_bytes(
parameters.mcp_input_schema_max_bytes,
code_mode_input_schema_max_bytes,
)),
output_schema: Some(serde_json::json!({
"type": "object",
"properties": {
"tools": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"description": { "type": "string" }
},
"required": ["name", "description"]
}
}
},
"required": ["tools"]
})),
}]
}
ToolSpec::WebSearch { .. } => Vec::new(),
}
}