Separate discovery from evidence
When the user supplies a known URL, call
read directly. When searching, prefer official or otherwise relevant domains. Search accepts numResults from 10 to 100; returning only a few candidates to the model does not change how many results the API requested.
Search can also scrape results with markdownOptions.enabled: true. Check each result’s markdown.code: only SUCCESS with nonempty markdown.markdown is usable evidence. A search result with TIMEOUT, WEBSITE_ACCESS_ERROR, or NOT_REQUESTED is still a candidate, not a successfully read source. Separate reads give this example tighter control over its page budget.
Implement bounded tools
Use Node.js with a server-sideCONTEXT_DEV_API_KEY from the Quickstart. The following application adapter uses HTTPS directly so the task limits and error states are visible. Pass your model’s tokenizer as countTokens, and create a new instance for each user task.
agent-web-tools.ts
search(query) and read(url) using your agent framework’s tool interface. Keep the hostname policy in application configuration; page content must not expand it. This example permits exact hostnames, so include docs.example.com separately from example.com when both are intended sources.
The six-thousand-token limit applies to retained evidence. Budget the question, instructions, tool metadata, and answer separately. Pass a source ID instead of repeatedly appending an already-read source to the model’s conversation. The adapter bounds API requests; your agent runner must also enforce a turn limit and overall model deadline.
The Markdown API can use cached content. For a task that requires a fresh read, add maxAgeMs: "0" to its query parameters and account for the extra latency. Record retrieval time without presenting it as the page’s publication time.
Require resolvable citations
Keep the returnedsources registry outside the model. Ask the model for claims that reference those source IDs:
Answer shape
Exercise failures before connecting a model
Use a question about a current API and a small official-documentation allowlist. Check these cases against the adapter and the answer renderer:Website RAG
Build a persistent index when the same corpus serves many questions.
Research with PDFs
Preserve document evidence and avoid invented page citations.