Add brave-answer skill: synthesized cited answers via Brave Answers API - #31
Open
hui-zheng wants to merge 1 commit into
Open
Add brave-answer skill: synthesized cited answers via Brave Answers API#31hui-zheng wants to merge 1 commit into
hui-zheng wants to merge 1 commit into
Conversation
hui-zheng
marked this pull request as ready for review
May 5, 2026 01:27
hui-zheng
force-pushed
the
add-brave-answer-skill
branch
from
May 5, 2026 01:28
46365d8 to
7ea2ad5
Compare
Author
|
Out of draft. Changes since the initial draft (force-pushed as a single squashed commit):
Live smoke test ran clean against the real Answers endpoint. |
Companion to brave-search: returns one prose answer with API-vouched
citations in a single round-trip, instead of a list of results to stitch
together by hand. Wraps POST /res/v1/chat/completions with stream:true
and enable_citations:true, parses streamed <citation> tags into a
numbered references block.
Research mode (--research) is multi-search deep mode: significantly
slower and more expensive, and the API does not return per-claim
citations in this mode (the answer is wrapped in <answer>{...}</answer>
JSON instead). The parser handles both shapes; enable_citations is
omitted in research mode (the API rejects it as a 422).
Requires the Brave Search API "Answers" plan ($5/mo free credits) and
BRAVE_ANSWER_API_KEY env var. Native fetch only, no runtime npm deps;
package.json + lockfile mirror brave-search install ritual for
consistency.
Code style mirrors brave-search/search.js: indexOf+splice arg parsing,
factored fetchBraveAnswer() and parseAnswer(), top-level try/catch
with `Error: ...` formatting, country=US / language=en defaults.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
hui-zheng
force-pushed
the
add-brave-answer-skill
branch
from
May 5, 2026 02:18
7ea2ad5 to
f6e33c0
Compare
Author
|
Caught a real bug while smoke-testing
Tested both modes against the live API:
Force-push is one squashed commit on top of upstream/main. |
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
brave-answer, wrapping the Brave Answers API for one-shot synthesized answers with numbered citations. Companion tobrave-search.Closes #30
Files
brave-answer/SKILL.md— frontmatter, setup, usage, common mistakesbrave-answer/answer.js— streaming SSE client, citation parser, numbered references outputbrave-answer/package.json—"type": "module", no runtime dependenciesREADME.md— skill row, requirements line, Claude Code symlink lines (user + project)API specifics
POST https://api.search.brave.com/res/v1/chat/completionsx-subscription-tokenheaderstream: trueper docs)<citation>{json}</citation>→[N]markers + a--- Sources ---block<enum_item>and<usage>tags silentlyFlags
--research— multi-search deep mode (slow, can take minutes)--country <code>/--language <code>— locale (defaults:US/en, matchingbrave-searchconvention)--raw— debug; prints raw API content with tagsConscious deviations from brave-search
A couple of intentional small departures, flagged so they don't read as oversights:
descriptionis longer than brave-search's one-liner — leans into trigger keywords ("what is X", "summarize Y", current-events Q&A) so the skill router picks it over brave-search when the user wants a synthesized answer. Happy to tighten if you'd prefer a shorter description.SKILL.mdhas aCommon Mistakessection that brave-search doesn't — covers the BRAVE_ANSWER_API_KEY-vs-BRAVE_API_KEY trap and--researchruntime gotcha, both of which agents tripped on during testing.Code style, arg parsing, error handling, install ritual, country defaults, env-var pattern, README integration all mirror brave-search.
Sample output
Test plan
🤖 Generated with Claude Code