Path: redb-route/redb.Route.Llm.Tools/TavilyWebSearchTool.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Llm.Tools/TavilyWebSearchTool.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Llm.Abstractions.Tools;
using redb.Route.Llm.Extensions;
namespace redb.Route.Llm.Tools;
///
/// Standalone RouteBuilder wrapper that mounts
/// behind a tool route. Prefer
/// the DSL extension .TavilyWebSearch(opts) on any existing route —
/// this shim is only useful when you want a self-contained RouteBuilder
/// to hand to context.AddRoutes(...).
///
public sealed class TavilyWebSearchTool : RouteBuilder
{
private const string InputSchema = """
{
"type": "object",
"properties": {
"query": { "type": "string", "description": "Web search query." },
"max_results": { "type": "integer", "description": "Override default max results (1-20)." }
},
"required": ["query"],
"additionalProperties": false
}
""";
private readonly TavilyWebSearchOptions _options;
/// Creates the tool with the given options. is required.
public TavilyWebSearchTool(TavilyWebSearchOptions options)
{
_options = options ?? throw new ArgumentNullException(nameof(options));
if (string.IsNullOrWhiteSpace(_options.ApiKey))
throw new ArgumentException("TavilyWebSearchOptions.ApiKey is required.", nameof(options));
}
///
protected override void Configure() =>
From(_options.EndpointUri)
.AsLlmTool(_options.ToolName)
.Description("Searches the web via Tavily. Returns a JSON object with an optional 'answer' " +
"summary and a 'results' array of {title, url, content}.")
.Input(InputSchema)
.SideEffect(ToolSideEffect.External)
.Cost(ToolCostClass.Expensive)
.Then()
.TavilyWebSearch(_options);
}