Declare each tool's plan requirement and explain plan mismatches in errors - #322
Open
kbennett2000 wants to merge 2 commits into
Open
Declare each tool's plan requirement and explain plan mismatches in errors#322kbennett2000 wants to merge 2 commits into
kbennett2000 wants to merge 2 commits into
Conversation
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.
Declare each tool's plan requirement and explain plan mismatches in errors
Stacked on the batch-amplification PR — it reuses the
BraveApiErrortypeadded there. Happy to rebase this standalone if you'd rather take them in the
other order, or land them together.
The problem
Brave sells access as plans, and a subscription token is scoped to the plan it
was issued under. A key that works for
/web/searchis not guaranteed to workfor
/summarizer/search. But this server takes exactly one key and points it atnine endpoints spanning at least two plans.
When that mismatch happens, the server today gives the caller nothing to work
with.
brave_summarizercatches the failure and returns:The real 403 — including Brave's own
SUBSCRIPTION_TOKEN_INVALIDbody — isdiscarded. It is the only tool in the server that swallows its error, and it is
also the tool most likely to hit a plan mismatch, because it needs a different
plan from the seven search tools that share its key.
This matters more than it used to. The consumer of that error is now a model.
A model can act on "this endpoint needs the Answers plan." It cannot act on
"unable to retrieve."
Changes
src/plans.ts(new) — one place that knows which endpoint needs which plan.An
ENDPOINT_PLANSmap plus helpers to render it as prose. Tool descriptionsand error messages both read from this map, so they can't drift apart.
src/BraveAPI/index.ts— auth failures say which plan is required.On 401/403/422,
issueRequestappends the plan requirement to the error beforethrowing. This happens once at the API boundary, so all nine endpoints get it
without touching the seven tools that have no error handling of their own.
BraveApiErroralso now carriesendpointandrequiredPlanfor callers thatwant to branch on it rather than read prose.
Every tool description now states its plan. Previously two of eight
mentioned a plan at all (
brave_local_searchandbrave_summarizer), and thetwo newest —
brave_llm_contextandbrave_place_search— said nothing. Noweach description ends with a generated line:
An agent reading the tool list can now see the requirement before it spends a
request finding out.
brave_summarizerstops discarding the failure. It still returns itsfriendly message, with the underlying reason appended when the cause was a
Brave API error.
What an agent sees now
Two things I need you to check
1. The plan assignments are my best read of your own docs, not authoritative.
I took the plan names from the
SKILL.mdbanners inbrave/brave-search-skillsand the plan notes already in this repo. Please correct any of these:
web,images,videos,newsllmContextskills/llm-context/SKILL.mdlocalPois,localDescriptionslocaldescriptionplaceSearch/local/path — least confidentsummarizerskills/answers/SKILL.mdThey're one edit each in
ENDPOINT_PLANS.2. The naming is inconsistent across Brave's own surfaces. This repo calls
it a "Pro AI subscription";
brave-search-skillscalls it the "Answers" plan.I went with Answers and noted the alias, but you'll know which is current.
Tests
src/plans.test.tsplus additions to the summarizer tests. Includes a guardthat fails if a new endpoint is added without a plan assignment, and one that
asserts every registered tool states a plan requirement.
73/73 pass;
tsc --noEmitandprettier --checkclean.Related
brave-search-cli#27andbrave-search-skills#27are the same root cause inthe other two repos: one key slot, several plans. This PR doesn't fix the
single-key limitation — it makes the resulting failure legible. Multi-key
support would be the larger change, and it should probably be designed across
all three repos at once rather than here alone.