feat(tools): Add web_search and fetch_url tools, wire into analyzer agent#8
Merged
Conversation
…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>
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
web_search— Calls the Brave Search API and returns structured results (title, URL, description). Reads the key fromBRAVE_API_KEYenv var. Defaults to 5 results, configurable viacount. Brave's free tier covers 2,000 queries/month.fetch_url— HTTP GET any URL and return plain text. HTML pages are parsed withgolang.org/x/net/html— tags,<script>,<style>, and<head>elements are stripped to produce clean readable text. Caps output at 50 KB with atruncatedflag.Both tools follow the existing
functiontool.Newpattern (struct args → auto-inferred JSON schema via reflection). Registered inGetToolByEnumand 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/netpromoted from indirect → direct dependency (already in module graph via ADK).Usage
The agent calls
web_searchfor candidates, thenfetch_urlto read each README/docs page, and finally writes the comparison to disk.Test plan
go build ./...— clean compilego test -race ./...— all tests pass including new:tools/web_search_test.go— missing API key error, empty query error, JSON parsing, constructor smoke testtools/fetch_url_test.go— plain text passthrough, HTML tag/script stripping, 50 KB truncation, invalid HTML doesn't panic🤖 Generated with Claude Code