Skip to main content
Give an agent two tools: find candidate sources and read a selected page. Context.dev handles web search and page extraction. Your agent chooses sources, manages its task budget, and answers from the evidence it actually retrieved. Construct built a web-search connector with Context.dev, and Scira added live web search. This recipe builds framework-independent TypeScript tools for a documentation assistant. If you want a ready-made tool connection, install the MCP server. Use the recipe below when you need application-specific source restrictions, budgets, or citation records.

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-side CONTEXT_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
Register 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 returned sources registry outside the model. Ask the model for claims that reference those source IDs:
Answer shape
Validate that every claim has at least one ID in the registry. Resolve those IDs to URLs in your renderer rather than accepting arbitrary model-written links. Membership alone does not prove that a source supports a claim: inspect supporting passages or run an evidence check before showing the answer. Tell the agent to treat retrieved Markdown as untrusted source text. Instructions inside a page cannot authorize new tools, reveal secrets, or change the user’s task. If no successful read supports an answer, return that the available evidence is insufficient.

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.