feat(experimental): AI Search context provider with search_context tool#1219
Draft
mattzcarey wants to merge 2 commits intomainfrom
Draft
feat(experimental): AI Search context provider with search_context tool#1219mattzcarey wants to merge 2 commits intomainfrom
mattzcarey wants to merge 2 commits intomainfrom
Conversation
Add searchable context blocks backed by Cloudflare AI Search: - Add optional `search()` to `ContextProvider` interface - Auto-wire `search_context` tool when any block has a search provider - Render searchable blocks in system prompt with [searchable] tag - `AiSearchContextProvider` using `ai_search_namespaces` binding - Lazy instance creation on first use - `set()` uploads content via `items.upload()` - `search()` queries AI Search and returns matching chunks - Configurable: maxResults, hybridSearch, embeddingModel, etc. - New `session-context` example app demonstrating the integration
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds searchable context blocks backed by Cloudflare AI Search using the new
ai_search_namespacesbinding.Deploy notes
Successfully deployed the example to
agents-session-context-example.mattzcarey.workers.dev(Matt account) by manually patching the vite build output — the@cloudflare/vite-plugindoes not yet pass throughai_search_namespacesto the deploy config, so it gets stripped duringvite build. Workaround: aftervite build, patchdist/agents_session_context_example/wrangler.jsonto re-add theai_search_namespacesfield, thenwrangler deploy -cthat config directly.Was not able to save data quickly — needs further investigation.
Changes
SDK (
packages/agents)ContextProvidergets optionalsearch?(query: string): Promise<string>search_contexttool auto-wired inContextBlocks.tools()when any block has a search provider[searchable — use search_context tool]tagAiSearchContextProvider— new provider usingai_search_namespaceswrangler binding:binding.create()set()uploads content viainstance.items.upload()search()queries AI Search, returns matching text chunksmaxResults,hybridSearch,embeddingModel, etc.AiSearchBindingtype exported for env.d.ts typingExample (
experimental/session-context)Minimal chat app demonstrating:
soul(readonly system prompt)memory(writable, AI saves facts viaupdate_context)knowledge(searchable via AI Search, AI queries viasearch_context)Wrangler config
{ "ai_search_namespaces": [ { "binding": "KNOWLEDGE", "namespace": "knowledge-base" } ] }Usage
Test plan
search_contexttool (existing behavior unchanged)search_contexttool appears with correct schemaprovider.search()and returns tagged resultsset()uploads content for indexing