feat(tools): add Brave LLM Context API mode for web_search#16312
Closed
RoccoFortuna wants to merge 3 commits intoopenclaw:mainfrom
Closed
feat(tools): add Brave LLM Context API mode for web_search#16312RoccoFortuna wants to merge 3 commits intoopenclaw:mainfrom
RoccoFortuna wants to merge 3 commits intoopenclaw:mainfrom
Conversation
Add support for Brave's /res/v1/llm/context endpoint as a configurable mode within the existing Brave web search provider. The LLM Context API returns pre-extracted, relevance-scored web content (full text snippets, tables, code blocks) optimized for LLM consumption. Configuration: - tools.web.search.brave.mode: "llm-context" (default: "web") - tools.web.search.brave.llmContext.maxTokens (1024-32768) - tools.web.search.brave.llmContext.maxUrls (1-50) - tools.web.search.brave.llmContext.thresholdMode (strict/balanced/lenient/disabled) - tools.web.search.brave.llmContext.maxSnippets (1-100) - tools.web.search.brave.llmContext.maxTokensPerUrl (512-8192) - tools.web.search.brave.llmContext.maxSnippetsPerUrl (1-100) Uses the same API key as standard Brave search. Freshness param is rejected in llm-context mode (unsupported by the endpoint). Closes openclaw#14992
142b2fc to
4077f1e
Compare
bfc1ccb to
f92900f
Compare
17 tasks
This comment was marked as spam.
This comment was marked as spam.
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
/res/v1/llm/context) that returns pre-extracted, relevance-scored web content optimized for LLM consumption, but OpenClaw only supports the standard web search endpoint.brave.modeandbrave.llmContextconfig, a newrunBraveLlmContextSearch()function, and llm-context branches inrunWebSearch()/createWebSearchTool().braveconfig block = existing behavior, zero breaking changes.AI-assisted (Claude Code). Fully tested locally (unit, integration, and live API). I understand what the code does.
This is my first PR on the repo - any feedback on code style, structure, or approach is very welcome. Happy to iterate!
Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
tools.web.search.brave.mode("web"|"llm-context") andtools.web.search.brave.llmContext.*(maxTokens, maxUrls, thresholdMode, maxSnippets, maxTokensPerUrl, maxSnippetsPerUrl).freshnessparameter returns an error when used in llm-context mode (unsupported by the endpoint).content(joined snippets) instead ofdescription, plusmode,sourceCountfields.Security Impact (required)
NoNo- reuses existingBRAVE_API_KEY/tools.web.search.apiKeyYes- new GET requests tohttps://api.search.brave.com/res/v1/llm/contextNo- sameweb_searchtool, same parametersNoX-Subscription-Token), and all response content is wrapped withwrapWebContent()(matching the existing security pattern for titles and snippet content).Repro + Verification
Environment
tools.web.search.provider: "brave"withbrave.mode: "llm-context"Steps
tools.web.search.brave.mode: "llm-context"in configweb_searchtool with a querymode: "llm-context",contentfields with joined snippetsExpected
Actual
Evidence
Live API tested with Brave Search subscription key:
Human Verification (required)
Compatibility / Migration
YesYes- new optional config keys undertools.web.search.brave.*No- no config = existing behavior unchangedFailure Recovery (if this breaks)
tools.web.search.braveconfig block, or setbrave.mode: "web"to revert to standard Brave web search.Risks and Mitigations
Configuration