diff --git a/src/agents/tools/web-search.ts b/src/agents/tools/web-search.ts index 7eada7a71c3..16a9ea23b27 100644 --- a/src/agents/tools/web-search.ts +++ b/src/agents/tools/web-search.ts @@ -1,20 +1,36 @@ import type { OpenClawConfig } from "../../config/types.openclaw.js"; import { resolveManifestContractOwnerPluginId } from "../../plugins/plugin-registry.js"; import type { RuntimeWebSearchMetadata } from "../../secrets/runtime-web-tools.types.js"; -import { - resolveWebSearchDefinition, - resolveWebSearchProviderId, - runWebSearch, -} from "../../web-search/runtime.js"; +import { resolveWebSearchProviderId, runWebSearch } from "../../web-search/runtime.js"; import type { AnyAgentTool } from "./common.js"; import { asToolParamsRecord, jsonResult } from "./common.js"; import { SEARCH_CACHE } from "./web-search-provider-common.js"; +const WebSearchSchema = { + type: "object", + properties: { + query: { type: "string", description: "Search query string." }, + count: { + type: "number", + description: "Number of results to return.", + minimum: 1, + }, + }, +} satisfies Record; + +function isWebSearchDisabled(config?: OpenClawConfig): boolean { + const search = config?.tools?.web?.search; + return Boolean(search && typeof search === "object" && search.enabled === false); +} + export function createWebSearchTool(options?: { config?: OpenClawConfig; sandboxed?: boolean; runtimeWebSearch?: RuntimeWebSearchMetadata; }): AnyAgentTool | null { + if (isWebSearchDisabled(options?.config)) { + return null; + } const runtimeProviderId = options?.runtimeWebSearch?.selectedProvider ?? options?.runtimeWebSearch?.providerConfigured; const preferRuntimeProviders = @@ -25,19 +41,13 @@ export function createWebSearchTool(options?: { origin: "bundled", config: options?.config, }); - const resolved = resolveWebSearchDefinition({ - ...options, - preferRuntimeProviders, - }); - if (!resolved) { - return null; - } return { label: "Web Search", name: "web_search", - description: resolved.definition.description, - parameters: resolved.definition.parameters, + description: + "Search the web. Returns provider-normalized results for current information lookup.", + parameters: WebSearchSchema, execute: async (_toolCallId, args) => { const result = await runWebSearch({ config: options?.config, diff --git a/src/agents/tools/web-tools.enabled-defaults.test.ts b/src/agents/tools/web-tools.enabled-defaults.test.ts index b0b6803a792..9d794af118e 100644 --- a/src/agents/tools/web-tools.enabled-defaults.test.ts +++ b/src/agents/tools/web-tools.enabled-defaults.test.ts @@ -111,7 +111,7 @@ describe("web tools defaults", () => { const result = await tool?.execute?.("call-runtime-provider", {}); - expect(tool?.description).toBe("custom runtime tool"); + expect(tool?.description).toContain("Search the web"); expect(result?.details).toMatchObject({ ok: true }); }); });