Web Search Harness
The WebSearch harness exposes web search as model-callable tools. The public setup path is Tavily.
Use this harness when an agent needs to search the public web during a run and return source URLs, snippets, or Tavily answer results.
Package And Namespace
Reference the WebSearch harness package or project, then import:
using HPD.Agent;
using HPD.Agent.ToolHarness.WebSearch;The WebSearch provider methods are AgentConfig methods. They put a configured WebSearchTools instance and its WebSearchContext on the web search harness reference as process-local parts of the definition, so every agent the runtime builds from the definition searches with the same connectors. A definition carrying them cannot be written to the agent store.
Add Tavily Search
Configure Tavily on the agent's definition:
var researcher = new AgentConfig()
.WithInstructions("Use web search when current facts or source links matter.")
.WithOpenAI(model: "gpt-4.1-mini")
.WithTavilyWebSearch(tavily => tavily
.WithMaxResults(5));
await using var runtime = await new AgentRuntimeBuilder()
.AddAgent("researcher", researcher)
.BuildAsync();WithTavilyWebSearch(...) creates a Tavily connector, creates a WebSearchTools harness with the matching WebSearchContext, and adds that configured harness to the definition. WithDefaultWebSearchProvider(name) chooses the default provider among the providers already configured on the definition; naming one that is not configured throws ArgumentException.
API Key Secret
The Tavily key is a secret of the runtime, never a value on the definition. By default the connector resolves:
Tavily:ApiKeyName another secret with WithApiKeySecret(...):
researcher.WithTavilyWebSearch(tavily => tavily
.WithApiKeySecret("Search:TavilyKey"));When the runtime builds the agent, it binds the connector to the runtime's secret resolution, so the key comes from any source the runtime reads: appsettings.json, user secrets, the Tavily__ApiKey environment variable through configuration, or a resolver added with AgentRuntimeBuilder.AddSecretResolver(...). The key is resolved when a search runs. If it is missing, the search fails with an InvalidOperationException whose message includes:
The Tavily API key secret 'Tavily:ApiKey' was not found in the runtime's secrets.Tavily Options
The Tavily options builder supports common search controls:
.WithTavilyWebSearch(tavily => tavily
.WithSearchDepth(TavilySearchDepth.Basic)
.WithMaxResults(5)
.WithTimeRange("week")
.WithTopic("general")
.IncludeAnswers()
.IncludeRawContent(false)
.IncludeImages(false))WithMaxResults(...) accepts values from 1 through 20. WithTimeRange(...) accepts day, week, month, or year. WithTopic(...) accepts Tavily topic values such as general and news.
Tools Exposed
With Tavily configured, the harness can expose:
WebSearch: general web search.NewsSearch: recent news search.AnswerSearch: Tavily answer search with cited sources.
The harness also contains functions for video, shopping, and enhanced multi-provider search, but those require providers that are not part of the Tavily setup path.
Boundaries
Brave and Bing builder types exist in the WebSearch harness source, but their connector implementations are not a public setup path here. Document and ship Tavily first.
Tavily registration can be validated without making a live search call. A real search run requires the Tavily API key secret and network access.