openclaw/extensions/brave
Ben.Li 2ee6577337
fix(brave): honor requested LLM-context result counts (#154602)
Related: #154420

## What Problem This Solves

Fixes Brave LLM-context searches returning more results than requested and reusing the same cached response for different result counts.

## User Impact

The existing `count` and configured result limit now apply to LLM-context results as well as ordinary web results. Repeating a search with the same count still uses the cache; changing the count does not reuse an incompatible result set. No configuration, permission, or storage migration is required.

## Why This Change Was Made

The Brave response owner now resolves the count once, includes it in LLM-context cache identity, and limits results before wrapping and caching them. It does not send a new parameter to Brave's LLM Context API. The existing web-mode regression also covers LLM-context count limits and cache separation, rather than maintaining a second copy of the fixture.

## Evidence

Exercised the source-built Gateway's authenticated `/tools/invoke` endpoint and its registered `web_search` tool against a real loopback HTTP server configured through Brave's documented `webSearch.baseUrl` proxy option. The server returned three distinct results using the Brave response formats; no fetch, tool, or cache callback was mocked.

| Same-query calls | Before | After |
| --- | --- | --- |
| Requested counts | 1, 1, 2, 2 | 1, 1, 2, 2 |
| Delivered LLM-context result counts | 3, 3, 3, 3 | 1, 1, 2, 2 |
| Upstream request or cache replay | request, cache, cache, cache | request, cache, request, cache |

Twelve scenarios per completed run also checked ordinary web mode, changed country and query/date filters, ordered result contents, publication dates, untrusted-content wrapping, and agreement between model-facing content and structured results. The LLM-context HTTP requests contained no unsupported `count` parameter. Both Gateway process groups and all owned children/listeners settled.

The expanded regression failed before the fix (`count: 3` instead of `1`), while its web-mode control passed. After the fix, 45 focused tests in the Brave provider and configuration-merge suites passed (1.36 seconds total runner time). Scoped type-aware lint, formatting, and both source-size ratchets passed. The runtime was rebuilt and the complete registered-tool scenario passed again.

The prepared commit preserves the contributor's original commit and has the identical source tree as the tested candidate (`1562ad2816c297541bda5b62d61fe78dd5b4e5c2`, tree `4ddcbe94fc9fe806f317543675fc8d716457722c`).

Limits: this is controlled Brave-compatible HTTP proof of OpenClaw's supported proxy path, not a live Brave account/service request. An earlier candidate attempt stopped before tool invocation because its build omitted external first-party plugin artifacts; those artifacts were rebuilt through their canonical owner before the successful run. No paid model or search request was made.

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
2026-09-21 15:42:24 +05:30
..
assets feat: give every plugin a compact chat activity icon (#147333) 2026-09-13 13:49:51 -07:00
src fix(brave): honor requested LLM-context result counts (#154602) 2026-09-21 15:42:24 +05:30
index.ts
openclaw.plugin.json feat: group bundled plugin settings by authored manifest metadata (#149331) 2026-09-16 22:03:41 -07:00
package.json chore(release): close out 2026.9.5 on main (#151823) 2026-09-19 01:37:16 -07:00
README.md
tsconfig.json
web-search-contract-api.ts refactor(web): use canonical provider contracts (#130334) 2026-08-26 13:36:15 -07:00
web-search-provider.ts
web-search-shared.ts

@openclaw/brave-plugin

Official Brave Search provider plugin for OpenClaw.

This plugin registers Brave as a web_search provider. It supports normal Brave web search and Brave LLM Context API mode.

Install

openclaw plugins install @openclaw/brave-plugin

Restart the Gateway after installing or updating the plugin.

Configure

Store a Brave Search API key in plugin config or expose BRAVE_API_KEY to the Gateway:

openclaw config set plugins.entries.brave.enabled true
openclaw config set tools.web.search.provider brave

Provider-specific options live under plugins.entries.brave.config.webSearch.*.

Docs

Full setup, config examples, search modes, and tool parameters:

Package

  • Plugin id: brave
  • Package: @openclaw/brave-plugin
  • Minimum OpenClaw host: 2026.4.10