<WebSearch>

<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

PropTypeDefaultWhat it does
namestringweb_searchThe tool’s name
descriptionstringcurrent facts the model does not knowWhen the model should search
resultsnumber5Results per search, 1 to 10. Fewer is quicker to answer from; each search is billed once, whatever the count
maxCallsPerConversationnumberno limitThe most searches in one conversation, as on <Tool>
providerSearchProviderkugelaudio.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):

MemberTypeWhat it is
idstringNames the search in the developer log and in curb check
keystring, optionalThe 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

VersionChanges
Unreleased<WebSearch> introduced