Network Search Tool
web_search is a public network search tool sample provided by the platform. It calls the Tencent Cloud Web Search (WSA) API at the underlying layer and is suitable for LLMs to use when they need to discover information, query data, or obtain the latest content. Developers can also integrate third-party search services or customize search tools based on their business scenarios.Prerequisites for Enabling
Configure the environment variable
WSA_API_KEY: write it to the project .env file in the dev environment, and to the console environment variables in the production environment. If it is missing, the system will prompt web_search requires the WSA_API_KEY environment variable....The root account needs to activate the Web Search (WSA) service in the Tencent Cloud console and refer to the WSA API documentation.
This environment variable is optional during deployment. After deployment succeeds, you can still add it in the project settings of the console.
Parameters
Field | Type | Required | Default Value | Description |
query | string | Yes | — | The search keyword, which cannot be an empty string. |
maxResults | integer ≥ 1 | No | 5 | The maximum number of deduplicated results returned (deduplicated by href). |
site | string | No | — | Site search: limit the results to a single domain, for example, "zhihu.com" or "cloud.tencent.com".Omitting this parameter indicates a web-wide search. |
Return Values
Returns
SearchResult[] — a deduplicated result array (deduplicated by href, with a length less than or equal to maxResults). Fields for each item:Field | Type | Description |
title | string | Result title (trimmed) |
href | string | Target URL (WSA directly returns the real accessible address, no need to follow redirects) |
snippet | string | Snippet, corresponding to the content / passage in WSA |
site | string | Source site name (may be empty for some small sites) |
date | string | Content publication date (may be empty) |
TS Sample
// Search the entire webconst webSearch = context.tools.get('web_search')const results = await webSearch.execute({query: 'What are the latest AI technologies?'})// results: [{ title, href, snippet, site, date }, ...]
Python Sample
# Search the entire webweb_search = context.tools.get('web_search')results = await web_search['execute']({'query': 'What are the latest AI technologies?'})
Third-Party Search Service
If you do not want to use Tencent Cloud WSA, you can integrate third-party search services (such as Exa, Tavily, and so on).
Recommended Integration Method: Custom Tool + Disabling the Built-in web_search
Package third-party calls into an object that matches the tool form adapted to the framework. Then, when mounting it to the Agent, filter out the built-in
web_search to prevent the LLM from seeing two tools with the same purpose simultaneously.TS example (Exa + OpenAI Agents)
import Exa from 'exa-js'import { tool } from '@openai/agents'import { z } from 'zod'const exa = new Exa(process.env.EXA_API_KEY!)// 1) Package third-party calls as native framework toolsconst exaSearch = tool({name: 'web_search',description: 'Search the public web. Returns title / url / snippet for top results.',parameters: z.object({query: z.string().describe('Search keywords'),maxResults: z.number().int().min(1).default(5),}),execute: async ({ query, maxResults }) => {const { results } = await exa.search(query, {numResults: maxResults,contents: { highlights: true },})return results.map((r) => ({title: r.title ?? '',href: r.url,snippet: r.highlights?.[0] ?? r.text?.slice(0, 200) ?? '',site: new URL(r.url).hostname,date: r.publishedDate ?? '',}))},})// 2) Filter out the built-in web_search during mounting to avoid conflicts with custom tools.const tools = [...context.tools.all().filter((t) => t.name !== 'web_search'),exaSearch,]