Centralize tool registration and protect host tools (#36127)

## Why

External MCP, extension, and dynamic tools can collide with host-owned tool
names. In particular, a dynamic `tool_search` definition must not replace the
host implementation used to discover and route deferred tools.

## What changed

- Build each turn's tools through a single ordered `ToolRegistry` that retains
  the first runtime registered for a name.
- Treat duplicate external tools as skippable collisions while preserving
  strict duplicate checks for trusted host tools.
- Reserve host-owned code-mode and `tool_search` runtimes before producing the
  model-visible tool list.
- Base hosted web-search fallback behavior on the extension runtime that
  actually won registration.

## Testing

- Cover ordered registry mutation and duplicate handling.
- Verify a client-provided `tool_search` cannot shadow the host tool.
- Verify hosted web-search fallback follows the registered browser runtime.

GitOrigin-RevId: acebe360de8ec69ad7da2f684cc2542cbf18a984
This commit is contained in:
jif authored and copyberry committed 2026-07-30 10:07:04 +00:00
1 parent 5decb399ae
commit 89a0eed93c
10 files changed
+443 -356

No files matched your search

+1 -1
View File
@@ -129,7 +129,7 @@ fn extension_tool_test_registry() -> Arc<ExtensionRegistry<Config>> {
fn test_tool_router(
step_context: &StepContext,
mcp_tool_runtimes: Vec<Arc<dyn CoreToolRuntime>>,
extension_tool_executors: Vec<Arc<dyn ToolExecutor<ExtensionToolCall>>>,
extension_tool_executors: impl IntoIterator<Item = Arc<dyn ToolExecutor<ExtensionToolCall>>>,
dynamic_tools: &[DynamicToolSpec],
) -> ToolRouter {
let mut tool_runtimes = build_core_tool_runtimes(