Skip to content

Agent tools

Instead of ask(), you can let your own agent decide when to search. asTool() (TypeScript) and as_tool() (Python) turn a document or collection into a search tool. The agent sends a query; the tool returns passages with source, chunk, page, section, score and text.

asTool() returns a Vercel AI SDK tool:

import { anthropic } from "@ai-sdk/anthropic";
import { generateText, stepCountIs } from "ai";
const { text } = await generateText({
model: anthropic("claude-sonnet-5-5"),
tools: {
searchPolicies: doc.asTool({ description: "Search the company policies.", topK: 5 }),
},
stopWhen: stepCountIs(3),
prompt: "Can I return an opened item?",
});
Option Default Meaning
description A generic description What the model reads to decide when to call the tool. Name your documents here
topK The document’s topK Passages per call
mode The document’s retrieval mode vector, keyword or hybrid

The tool’s name is the key you give it in tools.

  • ask(): one retrieval, one answer. Simple and predictable.
  • A tool: the agent can search several times, rephrase, or combine your documents with other tools.
  • An MCP client (Claude Code, Cursor): use the MCP server instead; it offers the same search.