<WebSearch>
A ready tool the model calls to search the web. By default it searches through KugelAudio’s AI
gateway on the project’s KUGELAUDIO_API_KEY (kugelaudio.search());
the gateway searches with its own keys, so the project needs no search key. provider takes a
search of your own instead. Off unless rendered: the model searches only where <WebSearch /> is,
in the agent or in one skill.
import { WebSearch } from "curb";
function WebSearch(props: WebSearchProps): ReactNode;
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
name | string | web_search | The tool’s name |
description | string | current facts the model does not know | When the model should search |
results | number | 5 | Results per search, 1 to 10. Fewer is quicker to answer from; each search is billed once, whatever the count |
maxCallsPerConversation | number | no limit | The most searches in one conversation, as on <Tool> |
provider | SearchProvider | kugelaudio.search() | Where the search runs (below) |
The model sends one query. It gets back { query, results: [{ title, url, snippet }] }.
When a search fails
A search that gets no answer within 10 seconds, that the gateway refuses (no credit, a rate limit, an organization it does not serve), or whose provider throws, returns a failed result that tells the model to answer from what it knows. The call goes on, and the developer log says why, without the key. An empty query is refused before anything is searched, so the model sends it again. This holds for every provider.
A search of your own
provider takes any object with these members (SearchProvider, from curb or curb/providers):
| Member | Type | What it is |
|---|---|---|
id | string | Names the search in the developer log and in curb check |
key | string, optional | The environment variable it reads its key from. curb check lists it, curb dev does not start without it, and <WebSearch> does not call search while it is unset |
search | (query, { count, signal }) => Promise<{ title, url, snippet }[]> | At most count results. Stop when signal aborts: it does when the 10 seconds are up |
<WebSearch> keeps the query schema, the time limit, maxCallsPerConversation and the failure
handling above, and keeps at most results results that have a url.
import { WebSearch, type SearchProvider } from "curb";
const intranet: SearchProvider = {
id: "intranet",
key: "INTRANET_SEARCH_TOKEN",
async search(query, { count, signal }) {
const response = await fetch(`https://intranet.example.com/search?q=${encodeURIComponent(query)}&limit=${count}`, {
headers: { Authorization: `Bearer ${process.env.INTRANET_SEARCH_TOKEN}` },
signal,
});
if (!response.ok) throw new Error(`intranet search answered ${response.status}`);
const { hits } = (await response.json()) as { hits: { name: string; link: string; summary: string }[] };
return hits.map((hit) => ({ title: hit.name, url: hit.link, snippet: hit.summary }));
},
};
<WebSearch provider={intranet} description="Search the company intranet for policies and opening hours." />
Example
<Agent llm={kugelaudio.llm({ model: "auto" })}>
<WebSearch description="Look up current public information the caller asks about." results={3} maxCallsPerConversation={5} />
</Agent>
Version history
| Version | Changes |
|---|---|
| Unreleased | <WebSearch> introduced |