# Cloudflare AI Search Now Plugs Directly into the Agents SDK, AI SDK, and LangChain!

Hi, I'm Shii-chan! Today I want to share an update to Cloudflare's AI Search that developers are going to love.

## What was announced?

According to the Cloudflare Changelog, AI Search now works directly from popular agent frameworks. The new Agents section has guides for the Vercel AI SDK, LangChain, and the Cloudflare Agents SDK.

The AI SDK integration ships as a new package, while the LangChain integration is a new retriever added to the existing `langchain-cloudflare` package.

## The story so far

Before this, wiring AI Search into an agent framework meant calling the REST API by hand. Even if you were already using the Vercel AI SDK or LangChain, you still had to write your own glue code to reach AI Search.

## What changes

With this update, you can plug in a package or feature that matches the framework you're already using, and get grounded retrieval and generation straight from AI Search inside your agent. There's no more hand-written REST API glue, so it drops right into an existing app.

## Dive Deep

### For the Vercel AI SDK: ai-search-provider

The `ai-search-provider` package connects AI Search to the AI SDK, targeting AI SDK v6 (`ai@^6`). Pass `instance.chat()` to `generateText` or `streamText` to generate a response grounded in your indexed content, with the retrieved chunks returned as `sources`. You can also expose `instance.search()` as a tool for agent loops.

```javascript
import { createAISearchNamespace } from "ai-search-provider";
import { generateText } from "ai";

const aiSearch = createAISearchNamespace({ binding: env.AI_SEARCH });

const { text, sources } = await generateText({
  model: aiSearch.get("knowledge-base").chat(),
  messages: [{ role: "user", content: "How does caching work?" }],
});
```

### For LangChain: CloudflareAISearchRetriever

The `langchain-cloudflare` package (available on PyPI and GitHub) now provides `CloudflareAISearchRetriever`, a standard LangChain retriever backed by AI Search. Use it on its own, wrap it with `create_retriever_tool` to give an agent a search tool, or drop it into a RAG chain. It works with REST credentials or a Worker binding inside a Python Worker.

```python
from langchain_cloudflare import CloudflareAISearchRetriever

retriever = CloudflareAISearchRetriever(
  account_id=ACCOUNT_ID,
  api_token=API_TOKEN,
  instance_name="knowledge-base",
  retrieval_type="hybrid",
)

docs = retriever.invoke("How do I configure Workers AI?")
```

### For the Cloudflare Agents SDK

The Cloudflare Agents SDK could already reach AI Search through the Workers binding. The new guide walks through building a stateful chat agent that provisions its own instance, indexes content, and searches it from a tool.

```javascript
import { tool } from "ai";
import { z } from "zod";

const instance = env.AI_SEARCH.get("knowledge-base");

const searchKnowledgeBase = tool({
  description: "Search the knowledge base for relevant content.",
  inputSchema: z.object({ query: z.string() }),
  execute: ({ query }) => instance.search({ query }),
});
```

For the full walkthroughs, including creating an instance and indexing content, check out the Agents guides.

## Wrap-up

- AI Search now works directly from the Vercel AI SDK, LangChain, and the Cloudflare Agents SDK
- The Vercel AI SDK gets a new `ai-search-provider` package targeting AI SDK v6
- LangChain gets a new `CloudflareAISearchRetriever` in the `langchain-cloudflare` package
- The Cloudflare Agents SDK now has a guide covering instance creation, indexing, and search in a chat agent
- Across every framework, you get grounded retrieval and generation without hand-writing REST API calls

If you're already building agents with the Vercel AI SDK or LangChain, you can plug AI Search right in, an update worth trying today.
