@lgrammel/exa-search-tool
v0.1.1
Published
AI SDK 7 tools for Exa web search and page content retrieval.
Readme
@lgrammel/exa-search-tool
AI SDK 7 tools for searching the web and fetching page content through Exa. The package calls Exa with fetch directly and requires an Exa API key.
Install
bun add @lgrammel/exa-search-tool aiUsage
import { openai } from "@ai-sdk/openai";
import { webFetch, webSearch } from "@lgrammel/exa-search-tool";
import { ToolLoopAgent } from "ai";
const exaApiKey = process.env.EXA_API_KEY;
if (!exaApiKey) {
throw new Error("EXA_API_KEY must be set.");
}
const agent = new ToolLoopAgent({
model: openai("gpt-5.5"),
instructions:
"Use web search when current or external information is needed. Fetch pages before relying on their details, and cite the URLs you used.",
tools: {
webSearch,
webFetch,
},
toolsContext: {
webSearch: {
apiKey: exaApiKey,
searchResultLimit: 5,
},
webFetch: {
apiKey: exaApiKey,
fetchMaxCharacters: 80 * 1024,
},
},
});
const result = await agent.generate({
prompt: "What did Anthropic announce most recently?",
});
console.log(result.text);Tools
webSearch: searches the web with Exa. Input is{ query }. Output isresultswithtitle,url, optionalid,publishedDate,author,highlights,image, andfavicon.webFetch: fetches clean page text for a URL. Input is{ url }. Output istitle,url, optional metadata,content, andtruncated.
Configuration lives in toolsContext and is validated by each tool's contextSchema, so the model cannot choose API keys, result counts, domains, freshness, or content size.
Context
apiKey: Exa API key used as thex-api-keyrequest header.baseUrl: Exa API base URL. Defaults tohttps://api.exa.ai.maxAgeHours: maximum accepted age of cached Exa content in hours. Use0to always live crawl and-1to always use cache.searchResultLimit: fixed number of search results returned to the agent. Defaults to5and is capped at10.searchType: Exa search type. Defaults toauto.highlightMaxCharacters: maximum highlight characters per result. Defaults to1000and is capped at4000.includeDomains: domains to restrict search results to.excludeDomains: domains to exclude from search results.fetchMaxCharacters: maximum page text characters returned. Defaults to81920and is capped at524288.textVerbosity: Exa text verbosity. Defaults tocompact.includeHtmlTags: include HTML tags in returned page text. Defaults tofalse.includeSections: semantic page sections to include when Exa live crawls the page.excludeSections: semantic page sections to exclude when Exa live crawls the page.
