Skip to content

feat(tools): Add web_search and fetch_url tools, wire into analyzer agent#8

Merged
ATMackay merged 3 commits into
mainfrom
feature/web-search-tools
May 24, 2026
Merged

feat(tools): Add web_search and fetch_url tools, wire into analyzer agent#8
ATMackay merged 3 commits into
mainfrom
feature/web-search-tools

Conversation

@ATMackay
Copy link
Copy Markdown
Owner

Summary

  • web_search — Calls the Brave Search API and returns structured results (title, URL, description). Reads the key from BRAVE_API_KEY env var. Defaults to 5 results, configurable via count. Brave's free tier covers 2,000 queries/month.
  • fetch_url — HTTP GET any URL and return plain text. HTML pages are parsed with golang.org/x/net/html — tags, <script>, <style>, and <head> elements are stripped to produce clean readable text. Caps output at 50 KB with a truncated flag.

Both tools follow the existing functiontool.New pattern (struct args → auto-inferred JSON schema via reflection). Registered in GetToolByEnum and wired into the analyzer agent as the natural integration point for research-heavy tasks.

The analyzer system prompt is updated to describe when and how to use each tool.

golang.org/x/net promoted from indirect → direct dependency (already in module graph via ADK).

Usage

export BRAVE_API_KEY=<your-key>

agent run analyzer \
  --task "Research the top Go HTTP router libraries in 2025 and write a comparison to analysis.md" \
  --work-dir .

The agent calls web_search for candidates, then fetch_url to read each README/docs page, and finally writes the comparison to disk.

Test plan

  • go build ./... — clean compile
  • go test -race ./... — all tests pass including new:
    • tools/web_search_test.go — missing API key error, empty query error, JSON parsing, constructor smoke test
    • tools/fetch_url_test.go — plain text passthrough, HTML tag/script stripping, 50 KB truncation, invalid HTML doesn't panic

🤖 Generated with Claude Code

ATMackay and others added 3 commits May 24, 2026 22:04
…gent

Adds two internet-facing tools to the tools package using the existing
functiontool.New pattern:

- web_search: Calls the Brave Search API (BRAVE_API_KEY env var) and
  returns the top N results as structured JSON (title, url, description).
  Defaults to 5 results, configurable via the count argument.

- fetch_url: Fetches any URL and returns its plain-text content. HTML
  pages are parsed with golang.org/x/net/html and tags/scripts are
  stripped to produce readable text. Caps output at 50 KB with a
  truncated flag when the limit is hit.

Both tools are registered in GetToolByEnum and wired into the analyzer
agent, which is the natural integration point for ad-hoc research tasks.
The analyzer system prompt is updated to describe when to use each tool.

golang.org/x/net promoted from indirect to direct dependency.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
{task} was used in the instruction string but never set in session state,
causing ADK's template injection to fail with "state key does not exist"
on every run. The task is already delivered as the user message so the
placeholder is redundant. References to {task} replaced with "the user
message" in the workflow description.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ATMackay ATMackay merged commit fb4d8f7 into main May 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant