Bundle: redb-route / redb.Route.Llm.Tools (redb.Route.Llm.Tools.txt), 21 files Snapshot: 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 Index: https://redbase.app/src/dev-2026-12-06/redb-route/_index.txt ==== Path: redb-route/redb.Route.Llm.Tools/HttpFetchDsl.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/HttpFetchDsl.cs ---- using System.Text; using redb.Route.Abstractions; using redb.Route.Core; namespace redb.Route.Llm.Tools; /// /// DSL extension that wires an HTTP-GET fetcher into a route step. Reads /// {"url":"..."} from exchange.In.Body, fetches the URL with the /// host / max-bytes / timeout guards configured in /// , and writes the response body (UTF-8 text) /// to exchange.Out.Body. /// /// Built on directly — does not depend on /// redb.Route.Http. Reuses one shared client across all callers. /// /// /// /// // Canonical usage on a tool route: /// From("direct:fetch-weather") /// .AsLlmTool("get_weather") /// .Description("Fetches the latest weather for a URL.") /// .Input("""{"type":"object","properties":{"url":{"type":"string"}},"required":["url"]}""") /// .Then() /// .HttpFetch(new HttpFetchOptions { HostAllowlist = ["api.weather.gov"] }); /// /// // Or as a plain enrichment step in any pipeline: /// From("amqp:queue:urls").HttpFetch(opts).To("amqp:queue:fetched"); /// /// /// public static class HttpFetchDsl { private static readonly HttpClient SharedClient = new() { DefaultRequestHeaders = { { "User-Agent", "redb.Route.Llm/HttpFetch" } } }; /// Adds an HTTP-GET fetcher step that reads {"url":"..."} from the body. public static IRouteDefinition HttpFetch(this IRouteDefinition self, HttpFetchOptions options) { ArgumentNullException.ThrowIfNull(self); ArgumentNullException.ThrowIfNull(options); return self.Process(async (exchange, ct) => { var url = ExtractUrl(exchange.In.Body); if (!Uri.TryCreate(url, UriKind.Absolute, out var uri) || uri.Scheme is not ("http" or "https")) throw new ArgumentException($"Invalid URL '{url}' — expected absolute http(s)."); if (options.HostAllowlist.Count > 0 && !options.HostAllowlist.Contains(uri.Host, StringComparer.OrdinalIgnoreCase)) throw new InvalidOperationException( $"Host '{uri.Host}' is not in the allowlist for '{options.ToolName}'."); using var timeoutCts = CancellationTokenSource.CreateLinkedTokenSource(ct); timeoutCts.CancelAfter(options.Timeout); using var request = new HttpRequestMessage(HttpMethod.Get, uri); using var response = await SharedClient .SendAsync(request, HttpCompletionOption.ResponseHeadersRead, timeoutCts.Token) .ConfigureAwait(false); response.EnsureSuccessStatusCode(); var (text, truncated) = await ReadBodyAsync(response, options.MaxBytes, timeoutCts.Token) .ConfigureAwait(false); exchange.Out ??= exchange.In.Clone(); exchange.Out.Body = text; exchange.Out.Headers["llm.http_fetch.status"] = (int)response.StatusCode; exchange.Out.Headers["llm.http_fetch.bytes"] = text.Length; if (truncated) exchange.Out.Headers["llm.http_fetch.truncated"] = true; }); } private static string ExtractUrl(object? body) { using var doc = LlmToolJson.ParseObject(body, "HttpFetch"); return LlmToolJson.RequiredString(doc.RootElement, "url", "HttpFetch"); } private static async Task<(string Text, bool Truncated)> ReadBodyAsync( HttpResponseMessage response, int maxBytes, CancellationToken ct) { await using var stream = await response.Content.ReadAsStreamAsync(ct).ConfigureAwait(false); var buffer = new byte[Math.Min(maxBytes, 16 * 1024)]; using var ms = new MemoryStream(); var truncated = false; int read; while ((read = await stream.ReadAsync(buffer.AsMemory(0, buffer.Length), ct).ConfigureAwait(false)) > 0) { if (ms.Length + read > maxBytes) { var remaining = maxBytes - (int)ms.Length; if (remaining > 0) ms.Write(buffer, 0, remaining); truncated = true; break; } ms.Write(buffer, 0, read); } return (Encoding.UTF8.GetString(ms.ToArray()), truncated); } } Path: redb-route/redb.Route.Llm.Tools/HttpFetchOptions.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/HttpFetchOptions.cs ---- namespace redb.Route.Llm.Tools; /// /// Configuration for . Defaults are conservative so /// the tool is safe to expose to a model out of the box; tighten for production. /// public sealed class HttpFetchOptions { /// /// Allowed hosts (case-insensitive, exact match). When non-empty, requests to any /// other host are rejected. Empty means "no restriction" \u2014 use only in trusted contexts. /// public IReadOnlyCollection HostAllowlist { get; init; } = []; /// /// Maximum response body size in bytes. Bytes past the limit are not buffered and /// the tool returns a truncation marker. Default 1 MiB. /// public int MaxBytes { get; init; } = 1_048_576; /// Request timeout. Default 15 seconds. public TimeSpan Timeout { get; init; } = TimeSpan.FromSeconds(15); /// /// Endpoint URI the tool is mounted on. Override only if the default collides /// with an existing route. Default "direct:llm.http_fetch". /// public string EndpointUri { get; init; } = "direct:llm.http_fetch"; /// /// Tool name exposed to the model. Override only if the default collides with /// another registered tool. Default "http_fetch". /// public string ToolName { get; init; } = "http_fetch"; } Path: redb-route/redb.Route.Llm.Tools/HttpFetchTool.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/HttpFetchTool.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 .HttpFetch(opts) on any existing route — this shim is /// only useful when you want a self-contained RouteBuilder to hand to /// context.AddRoutes(...). /// /// Input schema: {"url":"https://..."}. Response body is returned as /// UTF-8 text in exchange.Out.Body; bytes past /// are truncated. /// /// public sealed class HttpFetchTool : RouteBuilder { private const string InputSchema = """ { "type": "object", "properties": { "url": { "type": "string", "description": "Absolute http(s) URL to fetch." } }, "required": ["url"], "additionalProperties": false } """; private readonly HttpFetchOptions _options; /// Creates the tool with the given options. public HttpFetchTool(HttpFetchOptions options) { _options = options ?? throw new ArgumentNullException(nameof(options)); } /// protected override void Configure() => From(_options.EndpointUri) .AsLlmTool(_options.ToolName) .Description("Fetches a URL via HTTP GET and returns the response body as UTF-8 text.") .Input(InputSchema) .SideEffect(ToolSideEffect.External) .Cost(ToolCostClass.Moderate) .Then() .HttpFetch(_options); } Path: redb-route/redb.Route.Llm.Tools/JsonPathDsl.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/JsonPathDsl.cs ---- using System.Linq; using Newtonsoft.Json.Linq; using redb.Route.Abstractions; using redb.Route.Core; namespace redb.Route.Llm.Tools; /// /// DSL extension that wires a JsonPath query into a route step. Reads /// {"json":"<document>","path":"$.foo[0].bar"} from /// exchange.In.Body, evaluates the path against the embedded document /// and writes the matched value (re-serialised as JSON) — or the literal /// null when nothing matched — to exchange.Out.Body. /// /// Uses Newtonsoft JToken.SelectToken / SelectTokens directly, /// the same engine that backs /// redb.Route.Expressions.JsonPathExpression (which is built for /// in-route property extraction and trips on the JValue → JToken path /// for primitives). The full Newtonsoft JsonPath dialect is supported: /// recursive descent (..), wildcards ([*]), filters /// ([?(@.foo == 1)]), slicing ([1:5]). /// /// /// /// From("direct:llm.json_path") /// .AsLlmTool("json_path").Description("Query a JSON document.").Then() /// .JsonPath(new JsonPathOptions()); /// /// /// public static class JsonPathDsl { /// Adds a JsonPath query step. Uses default options when is null. public static IRouteDefinition JsonPath(this IRouteDefinition self, JsonPathOptions? options = null) { ArgumentNullException.ThrowIfNull(self); options ??= new JsonPathOptions(); return self.Process((exchange, _) => { var (json, path) = ParseInput(exchange.In.Body); if (json.Length > options.MaxJsonChars) throw new ArgumentException( $"Input json exceeds MaxJsonChars ({options.MaxJsonChars}); got {json.Length}."); JToken? token; try { var root = JToken.Parse(json); if (path.Contains("..") || path.Contains("[?") || path.Contains("[*]") || System.Text.RegularExpressions.Regex.IsMatch(path, @"\[\d+:\d+\]")) { var matches = root.SelectTokens(path).ToArray(); token = matches.Length == 0 ? null : new JArray(matches.Cast().ToArray()); } else { token = root.SelectToken(path); } } catch (Newtonsoft.Json.JsonException ex) { throw new ArgumentException($"JsonPath evaluation failed: {ex.Message}", ex); } exchange.Out ??= exchange.In.Clone(); exchange.Out.Body = token is null ? "null" : token.ToString(Newtonsoft.Json.Formatting.None); exchange.Out.Headers["llm.json_path.matched"] = token is not null; return Task.CompletedTask; }); } private static (string Json, string Path) ParseInput(object? body) { using var doc = LlmToolJson.ParseObject(body, "JsonPath"); return ( LlmToolJson.RequiredString(doc.RootElement, "json", "JsonPath"), LlmToolJson.OptionalString(doc.RootElement, "path") ?? "$"); } } Path: redb-route/redb.Route.Llm.Tools/JsonPathOptions.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/JsonPathOptions.cs ---- namespace redb.Route.Llm.Tools; /// /// Configuration for . /// public sealed class JsonPathOptions { /// /// Endpoint URI the tool is mounted on. Default "direct:llm.json_path". /// public string EndpointUri { get; init; } = "direct:llm.json_path"; /// /// Tool name exposed to the model. Default "json_path". /// public string ToolName { get; init; } = "json_path"; /// /// Maximum length of the inbound json string in characters. Anything /// larger is rejected with an before parsing /// — guards against the model handing the tool an entire response body. /// Default 1 MiB. /// public int MaxJsonChars { get; init; } = 1_048_576; } Path: redb-route/redb.Route.Llm.Tools/JsonPathTool.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/JsonPathTool.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 .JsonPath(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 JsonPathTool : RouteBuilder { private const string InputSchema = """ { "type": "object", "properties": { "json": { "type": "string", "description": "JSON document to query." }, "path": { "type": "string", "description": "JsonPath expression (full Newtonsoft dialect)." } }, "required": ["json", "path"], "additionalProperties": false } """; private readonly JsonPathOptions _options; /// Creates the tool with default options. public JsonPathTool() : this(new JsonPathOptions()) { } /// Creates the tool with the given options. public JsonPathTool(JsonPathOptions options) { _options = options ?? throw new ArgumentNullException(nameof(options)); } /// protected override void Configure() => From(_options.EndpointUri) .AsLlmTool(_options.ToolName) .Description("Extracts a value from a JSON document via JsonPath (Newtonsoft dialect: " + "recursive '..', wildcards '[*]', filters '[?...]', slices). Returns the matched " + "value as JSON, or null when nothing matches.") .Input(InputSchema) .SideEffect(ToolSideEffect.ReadOnly) .Cost(ToolCostClass.Cheap) .Then() .JsonPath(_options); } Path: redb-route/redb.Route.Llm.Tools/LlmToolJson.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/LlmToolJson.cs ---- using System.Text.Json; namespace redb.Route.Llm.Tools; /// /// Internal JSON helpers shared by the LLM-tool DSL extensions /// (, , , /// , , ). /// internal static class LlmToolJson { /// /// Parses as a JSON object. Accepts either a /// or any other type whose renders the JSON document. /// Throws on null / non-object / malformed input. /// /// The raw exchange body (typically exchange.In.Body). /// Tool name used to build a helpful error message. /// A disposable whose root is an object. public static JsonDocument ParseObject(object? body, string toolName) { if (body is null) throw new ArgumentException($"{toolName} input is empty — expected a JSON object."); var raw = body as string ?? body.ToString() ?? string.Empty; JsonDocument doc; try { doc = JsonDocument.Parse(raw); } catch (JsonException ex) { throw new ArgumentException($"{toolName} input is not valid JSON.", ex); } if (doc.RootElement.ValueKind != JsonValueKind.Object) { doc.Dispose(); throw new ArgumentException($"{toolName} input must be a JSON object."); } return doc; } /// Reads a required string property from a JSON object root. public static string RequiredString(JsonElement root, string name, string toolName) { if (!root.TryGetProperty(name, out var v) || v.ValueKind != JsonValueKind.String) throw new ArgumentException($"{toolName} input must include '{name}' as a string."); return v.GetString() ?? string.Empty; } /// Reads an optional string property, returning when missing. public static string? OptionalString(JsonElement root, string name, string? fallback = null) => root.TryGetProperty(name, out var v) && v.ValueKind == JsonValueKind.String ? v.GetString() : fallback; /// Reads an optional bool property, returning when missing or not a bool. public static bool OptionalBool(JsonElement root, string name, bool fallback = false) => root.TryGetProperty(name, out var v) ? v.ValueKind switch { JsonValueKind.True => true, JsonValueKind.False => false, _ => fallback } : fallback; /// Reads an optional integer property, returning when missing or not numeric. public static int? OptionalInt(JsonElement root, string name, int? fallback = null) => root.TryGetProperty(name, out var v) && v.ValueKind == JsonValueKind.Number && v.TryGetInt32(out var i) ? i : fallback; } Path: redb-route/redb.Route.Llm.Tools/MathEvalDsl.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/MathEvalDsl.cs ---- using System.Globalization; using System.Text.Json; using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.Expressions; namespace redb.Route.Llm.Tools; /// /// DSL extension that wires an expression evaluator into a route step. Reads /// {"expression":"2 * (3 + 4)"} from exchange.In.Body, evaluates /// it via (same /// compiled-lambda cache the rest of redb.Route uses for value expressions) /// and writes the result re-serialised as JSON to exchange.Out.Body. /// /// Grammar (whatever ExpressionResolver accepts): arithmetic /// (+ - * / %), comparisons, ternary (?:), null-coalescing /// (??), boolean operators (AND/OR/NOT), property / header / /// body references and JsonPath via jpath(...). Expression compilation /// is cached, so repeated calls with the same text are effectively free. /// /// /// /// From("direct:llm.math_eval") /// .AsLlmTool("math_eval").Description("Evaluate an arithmetic expression.").Then() /// .MathEval(new MathEvalOptions()); /// /// /// public static class MathEvalDsl { /// Adds an expression evaluator step. Uses default options when is null. public static IRouteDefinition MathEval(this IRouteDefinition self, MathEvalOptions? options = null) { ArgumentNullException.ThrowIfNull(self); options ??= new MathEvalOptions(); return self.Process((exchange, _) => { var expression = ParseInput(exchange.In.Body); if (expression.Length > options.MaxExpressionChars) throw new ArgumentException( $"Expression exceeds MaxExpressionChars ({options.MaxExpressionChars}); got {expression.Length}."); var compiled = ExpressionResolver.GetCompiledValueExpression(expression); var child = exchange.CreateChild(new Message(string.Empty)); var result = compiled(child); exchange.Out ??= exchange.In.Clone(); exchange.Out.Body = SerialiseResult(result); exchange.Out.Headers["llm.math_eval.finite"] = result is null || (result is double d && !double.IsNaN(d) && !double.IsInfinity(d)) || result is not double; return Task.CompletedTask; }); } private static string SerialiseResult(object? value) => value switch { null => "null", double d when double.IsNaN(d) || double.IsInfinity(d) => "null", double d => d.ToString("R", CultureInfo.InvariantCulture), float f when float.IsNaN(f) || float.IsInfinity(f) => "null", float f => f.ToString("R", CultureInfo.InvariantCulture), bool b => b ? "true" : "false", string s => JsonSerializer.Serialize(s), IFormattable num when num is byte or sbyte or short or ushort or int or uint or long or ulong or decimal => num.ToString(null, CultureInfo.InvariantCulture), _ => JsonSerializer.Serialize(value) }; private static string ParseInput(object? body) { using var doc = LlmToolJson.ParseObject(body, "MathEval"); return LlmToolJson.RequiredString(doc.RootElement, "expression", "MathEval"); } } Path: redb-route/redb.Route.Llm.Tools/MathEvalOptions.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/MathEvalOptions.cs ---- namespace redb.Route.Llm.Tools; /// /// Configuration for . /// public sealed class MathEvalOptions { /// Endpoint URI the tool is mounted on. Default "direct:llm.math_eval". public string EndpointUri { get; init; } = "direct:llm.math_eval"; /// Tool name exposed to the model. Default "math_eval". public string ToolName { get; init; } = "math_eval"; /// /// Maximum length of the inbound expression in characters. Default 4096. /// Guards against pathological input. /// public int MaxExpressionChars { get; init; } = 4096; } Path: redb-route/redb.Route.Llm.Tools/MathEvalTool.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/MathEvalTool.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 .MathEval(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 MathEvalTool : RouteBuilder { private const string InputSchema = """ { "type": "object", "properties": { "expression": { "type": "string", "description": "Value expression supported by redb.Route's ExpressionResolver, e.g. '2 * (3 + 4)' or 'property.x + 1'." } }, "required": ["expression"], "additionalProperties": false } """; private readonly MathEvalOptions _options; /// Creates the tool with default options. public MathEvalTool() : this(new MathEvalOptions()) { } /// Creates the tool with the given options. public MathEvalTool(MathEvalOptions options) { _options = options ?? throw new ArgumentNullException(nameof(options)); } /// protected override void Configure() => From(_options.EndpointUri) .AsLlmTool(_options.ToolName) .Description("Evaluates a value expression via redb.Route's ExpressionResolver " + "(arithmetic, comparisons, ternary, jpath/property/header/body refs). " + "Returns the result as JSON.") .Input(InputSchema) .SideEffect(ToolSideEffect.ReadOnly) .Cost(ToolCostClass.Cheap) .Then() .MathEval(_options); } Path: redb-route/redb.Route.Llm.Tools/README.md 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/README.md ---- # redb.Route.Llm.Tools > Documentation and articles: Optional batteries package for `redb.Route.Llm`. Ships reusable building blocks the agent engine can dispatch to as tools. Every tool is shipped twice: 1. **As a DSL extension on `IRouteDefinition`** — the canonical, composable form. Plug into any existing route step (LLM tool, AMQP enrichment, HTTP pipeline) by adding `.HttpFetch(opts)` / `.JsonPath()` / etc. just like any other built-in route operator. 2. **As a standalone `RouteBuilder` wrapper** — a thin convenience class (`HttpFetchTool`, `JsonPathTool`, …) that mounts the same logic behind a `direct:` endpoint with the right `AsLlmTool(...)` aspect already attached. Use it when you want to hand a single object to `context.AddRoutes(...)` or `route.AddRouteBuilder()` — for example for external/process tools (shell, RPC) where the `direct:` indirection is the whole point. Pick **the DSL extension** for everything else. ## Pre-built tools | DSL extension | Standalone wrapper | Endpoint URI (default) | Side-effect | Cost | Purpose | |------------------------|-------------------------|-------------------------------|-------------|-----------|--------------------------------------------------------------------------------| | `.HttpFetch(opts)` | `HttpFetchTool` | `direct:llm.http_fetch` | External | Moderate | HTTP GET a URL, return UTF-8 body. Host allowlist, max-bytes, timeout. | | `.JsonPath(opts?)` | `JsonPathTool` | `direct:llm.json_path` | ReadOnly | Cheap | JSONPath query (Newtonsoft dialect — recursive `..`, wildcards, filters, slices). | | `.XPath(opts?)` | `XPathTool` | `direct:llm.xpath` | ReadOnly | Cheap | XPath 1.0 query backed by `redb.Route.Expressions.XPathExpression`. | | `.RegexExtract(opts?)` | `RegexExtractTool` | `direct:llm.regex_extract` | ReadOnly | Cheap | Extract a substring (or array of substrings) from text by a .NET regex. | | `.MathEval(opts?)` | `MathEvalTool` | `direct:llm.math_eval` | ReadOnly | Cheap | Value expression eval via redb.Route's `ExpressionResolver` (cached lambdas). | | `.TavilyWebSearch(opts)`| `TavilyWebSearchTool` | `direct:llm.web_search` | External | Expensive | Web search via the Tavily API; returns `{answer, results[]}`. | The query/eval extensions (`JsonPath`, `XPath`, `MathEval`) are thin wrappers over redb.Route framework primitives — same engines the rest of the framework uses for `jpath()`/`xpath()`/expression evaluation in routes. Use as-is, or copy the pattern to author your own. > **Why both forms?** The DSL extension is the canonical way to compose a tool into any route. The standalone wrapper class is kept (a) so external/process tools (HTTP, Tavily, shell) have a clean `direct:` mount point and (b) as a copy-paste reference — every wrapper in this package is literally a one-line bridge `From(uri).AsLlmTool(...).Then().Xxx(opts)`, so they double as the canonical template for authoring your own `RouteBuilder`-shaped tool. ## Wiring — the DSL way (preferred) ```csharp services.AddRedbRoute(route => { route.Services.AddRedbRouteLlm(); route.AddRouteBuilder(); }); internal sealed class InlineToolRoutes : RouteBuilder { protected override void Configure() { var fetchOpts = new HttpFetchOptions { HostAllowlist = ["api.example.com"] }; var tavily = new TavilyWebSearchOptions { ApiKey = Environment.GetEnvironmentVariable("TAVILY_API_KEY")! }; From("direct:llm.http_fetch") .AsLlmTool("http_fetch").Description("HTTP GET a URL.").Then() .HttpFetch(fetchOpts); From("direct:llm.json_path") .AsLlmTool("json_path").Description("Query a JSON document via JsonPath.").Then() .JsonPath(); From("direct:llm.xpath") .AsLlmTool("xpath").Description("Query an XML document via XPath 1.0.").Then() .XPath(); From("direct:llm.regex_extract") .AsLlmTool("regex_extract").Description("Extract text by a .NET regex.").Then() .RegexExtract(); From("direct:llm.math_eval") .AsLlmTool("math_eval").Description("Evaluate an arithmetic expression.").Then() .MathEval(); From("direct:llm.web_search") .AsLlmTool("web_search").Description("Search the web via Tavily.").Then() .TavilyWebSearch(tavily); } } ``` DSL extensions are equally usable as plain enrichment steps in any pipeline — no `AsLlmTool(...)` required: ```csharp From("amqp:queue:urls") .HttpFetch(opts) .JsonPath(new JsonPathOptions()) // pre-pull a field .To("amqp:queue:enriched"); ``` ## Wiring — the wrapper way (only for self-contained delivery) When you want to ship a tool as a single object — typically because the route is exposed only via its `direct:` endpoint and never composed further: ```csharp services.AddRedbRoute(route => { route.Services.AddRedbRouteLlm(); // A wrapper is resolved from DI, so its options are registered as services. route.Services.AddSingleton(new HttpFetchOptions { HostAllowlist = ["api.example.com"] }); route.Services.AddSingleton(new TavilyWebSearchOptions { ApiKey = Environment.GetEnvironmentVariable("TAVILY_API_KEY")! }); route.AddRouteBuilder(); route.AddRouteBuilder(); route.AddRouteBuilder(); route.AddRouteBuilder(); route.AddRouteBuilder(); route.AddRouteBuilder(); }); ``` The wrappers do nothing more than `From(opts.EndpointUri).AsLlmTool(...).Then().Xxx(opts)` — the canonical idiom for external/process tools (e.g. the shell-out tool in `demos/Llm.HttpShell`). Reference the registered tool name in any LLM step: ```csharp .To(Llm.Factory("openai") .Tools("http_fetch,json_path,xpath,regex_extract,math_eval,web_search") .MaxIterations(6) .AsUri()) ``` ## Tool I/O contracts ### `json_path` / `.JsonPath()` - **Input:** `{"json":"","path":"$.foo[0].bar"}` - **Output:** matched value re-serialised as JSON, or `null` if nothing matches. - **Path syntax:** full Newtonsoft JsonPath dialect — recursive descent (`..`), wildcards (`[*]`), filters (`[?(@.x > 1)]`), slicing (`[1:5]`), plus the simple property/index forms. Same engine that backs `redb.Route.Expressions.JsonPathExpression`. ### `xpath` / `.XPath()` - **Input:** `{"xml":"","xpath":"//book[1]/title"}` - **Output:** matched value as a string, or `null` if nothing matches. Use XPath functions like `string(...)` / `count(...)` to coerce node-sets to scalars. - Backed by `redb.Route.Expressions.XPathExpression` (W3C XPath 1.0 via `System.Xml.XPath`). ### `regex_extract` / `.RegexExtract()` - **Input:** `{"text":"...","pattern":"...","group":"name|number","all":bool}` - **Output:** matched string, or array of strings (`all:true`), or `null`. - `group` selects a capture group; `"0"` or omitted = whole match. - Pattern execution is bounded by `RegexExtractOptions.MatchTimeout` (default 1 s) — guards against catastrophic backtracking from a careless pattern. ### `math_eval` / `.MathEval()` - **Input:** `{"expression":"2 * (3 + 4)"}` - **Output:** result re-serialised as JSON (number, string, bool, or `null`). - **Grammar:** whatever `redb.Route.Expressions.ExpressionResolver` accepts — arithmetic (`+ - * /`), comparisons, ternary (`?:`), null-coalescing (`??`), boolean operators (`AND`/`OR`/`NOT`), property/header/body refs, `jpath(...)`. Compilation is cached, so repeated calls with the same text are effectively free. ### `http_fetch` / `.HttpFetch()` - **Input:** `{"url":"https://..."}` - **Output:** response body as UTF-8 text. Bytes past `HttpFetchOptions.MaxBytes` are truncated; `llm.http_fetch.truncated` header is set in that case. - **Guards:** `HostAllowlist` (case-insensitive exact match — leave empty only in trusted contexts), `MaxBytes` (default 1 MiB), `Timeout` (default 15 s). ### `web_search` / `.TavilyWebSearch()` - **Input:** `{"query":"...","max_results":int?}` - **Output:** `{"answer":"...","results":[{"title","url","content"}]}` — `answer` is omitted if Tavily did not return one. - Requires a Tavily API key (`TavilyWebSearchOptions.ApiKey`); set `IncludeAnswer=false` if you only want raw results. ## Authoring your own tool The DSL-extension shape (preferred): ```csharp public static class MyToolDsl { public static IRouteDefinition MyTool(this IRouteDefinition self, MyToolOptions? options = null) { options ??= new MyToolOptions(); return self.Process(async (exchange, ct) => { // Read JSON input from exchange.In.Body, write result to exchange.Out.Body. // Use LlmToolJson.ParseObject(...) to validate the input shape. }); } } ``` Wire it on a tool route exactly like the built-ins: ```csharp From("direct:llm.my_tool") .AsLlmTool("my_tool").Description("...").Input(MySchema).Then() .MyTool(opts); ``` For external/process tools where you really need a self-contained `RouteBuilder` (shell-out, RPC), keep the wrapper-class idiom — see `HttpFetchTool` / `TavilyWebSearchTool` in this package and the shell tool in `demos/Llm.HttpShell` for examples. Package depends on `redb.Route.Llm.Abstractions` only — does **not** require the `redb.Route.Llm` engine at compile time. The engine is needed at runtime to actually dispatch the tools. Path: redb-route/redb.Route.Llm.Tools/RegexExtractDsl.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/RegexExtractDsl.cs ---- using System.Text.Json.Nodes; using System.Text.RegularExpressions; using redb.Route.Abstractions; using redb.Route.Core; namespace redb.Route.Llm.Tools; /// /// DSL extension that wires a regex-extraction step into a route. Reads /// {"text":"...","pattern":"...","group":"name|number","all":bool} /// from exchange.In.Body, runs the pattern under /// (default 1 s — guards /// against catastrophic backtracking) and writes the result to /// exchange.Out.Body as JSON: a string, an array of strings, or /// null when nothing matched. /// /// /// From("direct:llm.regex_extract") /// .AsLlmTool("regex_extract").Description("Extract text by a .NET regex.").Then() /// .RegexExtract(new RegexExtractOptions()); /// /// /// public static class RegexExtractDsl { /// Adds a regex extraction step. Uses default options when is null. public static IRouteDefinition RegexExtract(this IRouteDefinition self, RegexExtractOptions? options = null) { ArgumentNullException.ThrowIfNull(self); options ??= new RegexExtractOptions(); return self.Process((exchange, _) => { var input = ParseInput(exchange.In.Body); if (input.Text.Length > options.MaxTextChars) throw new ArgumentException( $"Input text exceeds MaxTextChars ({options.MaxTextChars}); got {input.Text.Length}."); Regex regex; try { regex = new Regex(input.Pattern, RegexOptions.CultureInvariant, options.MatchTimeout); } catch (ArgumentException ex) { throw new ArgumentException($"Invalid regex pattern: {ex.Message}", ex); } JsonNode? result; if (input.All) { var arr = new JsonArray(); var count = 0; foreach (Match m in regex.Matches(input.Text)) { if (count >= options.MaxMatches) break; var v = SelectGroup(m, input.Group); if (v is not null) arr.Add(v); count++; } result = arr.Count == 0 ? null : arr; } else { var m = regex.Match(input.Text); result = m.Success ? SelectGroup(m, input.Group) : null; } exchange.Out ??= exchange.In.Clone(); exchange.Out.Body = result is null ? "null" : result.ToJsonString(); exchange.Out.Headers["llm.regex_extract.matched"] = result is not null; return Task.CompletedTask; }); } private static string? SelectGroup(Match m, string? group) { if (string.IsNullOrEmpty(group) || group == "0") return m.Value; if (int.TryParse(group, out var idx)) return idx < m.Groups.Count && m.Groups[idx].Success ? m.Groups[idx].Value : null; var named = m.Groups[group]; return named.Success ? named.Value : null; } private static (string Text, string Pattern, string? Group, bool All) ParseInput(object? body) { using var doc = LlmToolJson.ParseObject(body, "RegexExtract"); var root = doc.RootElement; return ( LlmToolJson.RequiredString(root, "text", "RegexExtract"), LlmToolJson.RequiredString(root, "pattern", "RegexExtract"), LlmToolJson.OptionalString(root, "group"), LlmToolJson.OptionalBool(root, "all")); } } Path: redb-route/redb.Route.Llm.Tools/RegexExtractOptions.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/RegexExtractOptions.cs ---- namespace redb.Route.Llm.Tools; /// /// Configuration for . /// public sealed class RegexExtractOptions { /// Endpoint URI the tool is mounted on. Default "direct:llm.regex_extract". public string EndpointUri { get; init; } = "direct:llm.regex_extract"; /// Tool name exposed to the model. Default "regex_extract". public string ToolName { get; init; } = "regex_extract"; /// /// Maximum length of the inbound text in characters. Default 1 MiB. /// public int MaxTextChars { get; init; } = 1_048_576; /// /// Per-pattern execution timeout. Default 1 second. Guards against catastrophic /// backtracking when the model produces a pathological pattern. /// public TimeSpan MatchTimeout { get; init; } = TimeSpan.FromSeconds(1); /// /// Maximum number of matches returned in array mode. Default 64. /// public int MaxMatches { get; init; } = 64; } Path: redb-route/redb.Route.Llm.Tools/RegexExtractTool.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/RegexExtractTool.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 .RegexExtract(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 RegexExtractTool : RouteBuilder { private const string InputSchema = """ { "type": "object", "properties": { "text": { "type": "string", "description": "Text to scan." }, "pattern": { "type": "string", "description": ".NET regular expression." }, "group": { "type": "string", "description": "Capture group name or number. Omit / '0' for the whole match." }, "all": { "type": "boolean", "description": "Return every match as an array. Default false." } }, "required": ["text", "pattern"], "additionalProperties": false } """; private readonly RegexExtractOptions _options; /// Creates the tool with default options. public RegexExtractTool() : this(new RegexExtractOptions()) { } /// Creates the tool with the given options. public RegexExtractTool(RegexExtractOptions options) { _options = options ?? throw new ArgumentNullException(nameof(options)); } /// protected override void Configure() => From(_options.EndpointUri) .AsLlmTool(_options.ToolName) .Description("Extracts text by a .NET regex. Returns the matched group as JSON " + "(string, array of strings, or null when nothing matches).") .Input(InputSchema) .SideEffect(ToolSideEffect.ReadOnly) .Cost(ToolCostClass.Cheap) .Then() .RegexExtract(_options); } Path: redb-route/redb.Route.Llm.Tools/TavilyWebSearchDsl.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/TavilyWebSearchDsl.cs ---- using System.Text; using System.Text.Json; using System.Text.Json.Nodes; using redb.Route.Abstractions; using redb.Route.Core; namespace redb.Route.Llm.Tools; /// /// DSL extension that wires a Tavily (https://tavily.com/) web-search call /// into a route step. Reads {"query":"...","max_results":int?} from /// exchange.In.Body, calls the Tavily Search API with the API key /// configured in and writes the shaped /// response — {"answer":"...?", "results":[{"title","url","content"}]} /// — to exchange.Out.Body as a JSON string. /// /// /// From("direct:llm.web_search") /// .AsLlmTool("web_search").Description("Search the web via Tavily.").Then() /// .TavilyWebSearch(new TavilyWebSearchOptions { ApiKey = apiKey }); /// /// /// public static class TavilyWebSearchDsl { private static readonly HttpClient SharedClient = new() { DefaultRequestHeaders = { { "User-Agent", "redb.Route.Llm/TavilyWebSearch" } } }; /// Adds a Tavily web-search step. is required. public static IRouteDefinition TavilyWebSearch(this IRouteDefinition self, TavilyWebSearchOptions options) { ArgumentNullException.ThrowIfNull(self); ArgumentNullException.ThrowIfNull(options); if (string.IsNullOrWhiteSpace(options.ApiKey)) throw new ArgumentException("TavilyWebSearchOptions.ApiKey is required.", nameof(options)); return self.Process(async (exchange, ct) => { var (query, maxResults) = ParseInput(exchange.In.Body); var effectiveMax = Math.Clamp(maxResults ?? options.MaxResults, 1, 20); var requestBody = new JsonObject { ["api_key"] = options.ApiKey, ["query"] = query, ["max_results"] = effectiveMax, ["search_depth"] = options.SearchDepth, ["include_answer"] = options.IncludeAnswer }; using var timeoutCts = CancellationTokenSource.CreateLinkedTokenSource(ct); timeoutCts.CancelAfter(options.Timeout); using var request = new HttpRequestMessage(HttpMethod.Post, options.Endpoint) { Content = new StringContent(requestBody.ToJsonString(), Encoding.UTF8, "application/json") }; using var response = await SharedClient.SendAsync(request, timeoutCts.Token).ConfigureAwait(false); var raw = await response.Content.ReadAsStringAsync(timeoutCts.Token).ConfigureAwait(false); if (!response.IsSuccessStatusCode) throw new InvalidOperationException( $"Tavily search failed with HTTP {(int)response.StatusCode}: {Truncate(raw, 512)}"); var output = ShapeOutput(raw); exchange.Out ??= exchange.In.Clone(); exchange.Out.Body = output.ToJsonString(); exchange.Out.Headers["llm.web_search.results"] = (output["results"] as JsonArray)?.Count ?? 0; }); } private static (string Query, int? MaxResults) ParseInput(object? body) { using var doc = LlmToolJson.ParseObject(body, "TavilyWebSearch"); return ( LlmToolJson.RequiredString(doc.RootElement, "query", "TavilyWebSearch"), LlmToolJson.OptionalInt(doc.RootElement, "max_results")); } private static JsonObject ShapeOutput(string raw) { var node = JsonNode.Parse(raw) as JsonObject ?? throw new InvalidOperationException("Tavily returned a non-object response."); var shaped = new JsonObject(); if (node["answer"] is JsonValue answerValue && answerValue.GetValueKind() == JsonValueKind.String) shaped["answer"] = answerValue.DeepClone(); var results = new JsonArray(); if (node["results"] is JsonArray arr) { foreach (var item in arr) { if (item is not JsonObject obj) continue; var entry = new JsonObject(); if (obj["title"] is JsonNode title) entry["title"] = title.DeepClone(); if (obj["url"] is JsonNode url) entry["url"] = url.DeepClone(); if (obj["content"] is JsonNode content) entry["content"] = content.DeepClone(); results.Add(entry); } } shaped["results"] = results; return shaped; } private static string Truncate(string s, int max) => s.Length <= max ? s : s[..max] + "…"; } Path: redb-route/redb.Route.Llm.Tools/TavilyWebSearchOptions.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/TavilyWebSearchOptions.cs ---- namespace redb.Route.Llm.Tools; /// /// Configuration for . /// public sealed class TavilyWebSearchOptions { /// Endpoint URI the tool is mounted on. Default "direct:llm.web_search". public string EndpointUri { get; init; } = "direct:llm.web_search"; /// Tool name exposed to the model. Default "web_search". public string ToolName { get; init; } = "web_search"; /// /// Tavily API key. Required. Get one at https://tavily.com/. /// public string ApiKey { get; init; } = string.Empty; /// /// Tavily search endpoint. Override only for testing/proxying. /// Default https://api.tavily.com/search. /// public string Endpoint { get; init; } = "https://api.tavily.com/search"; /// /// Maximum results to request from Tavily. Default 5. Tavily caps at 20. /// public int MaxResults { get; init; } = 5; /// /// "basic" (faster, cheaper) or "advanced" (deeper crawl). /// Default "basic". /// public string SearchDepth { get; init; } = "basic"; /// /// When true, ask Tavily to include a short answer summary in the response. /// Default true. /// public bool IncludeAnswer { get; init; } = true; /// /// HTTP request timeout. Default 20 seconds. /// public TimeSpan Timeout { get; init; } = TimeSpan.FromSeconds(20); } 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); } Path: redb-route/redb.Route.Llm.Tools/XPathDsl.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/XPathDsl.cs ---- using redb.Route.Abstractions; using redb.Route.Core; using FrameworkXPathExpression = redb.Route.Expressions.XPathExpression; namespace redb.Route.Llm.Tools; /// /// DSL extension that wires an XPath query into a route step. Reads /// {"xml":"<document>","xpath":"//book[1]/title"} from /// exchange.In.Body, evaluates the path against the embedded document /// using (W3C XPath 1.0 — same engine /// the rest of redb.Route uses for xpath(...) in routes) and writes /// the matched value as a string — or the literal null when nothing /// matched — to exchange.Out.Body. /// /// /// From("direct:llm.xpath") /// .AsLlmTool("xpath").Description("Query an XML document.").Then() /// .XPath(new XPathOptions()); /// /// /// public static class XPathDsl { /// Adds an XPath query step. Uses default options when is null. public static IRouteDefinition XPath(this IRouteDefinition self, XPathOptions? options = null) { ArgumentNullException.ThrowIfNull(self); options ??= new XPathOptions(); return self.Process((exchange, _) => { var (xml, xpath) = ParseInput(exchange.In.Body); if (xml.Length > options.MaxXmlChars) throw new ArgumentException( $"Input xml exceeds MaxXmlChars ({options.MaxXmlChars}); got {xml.Length}."); var child = exchange.CreateChild(new Message(xml)); string? value; try { value = new FrameworkXPathExpression(xpath).Evaluate(child); } catch (InvalidOperationException) { value = null; } exchange.Out ??= exchange.In.Clone(); exchange.Out.Body = value is null ? "null" : value; exchange.Out.Headers["llm.xpath.matched"] = value is not null; return Task.CompletedTask; }); } private static (string Xml, string XPath) ParseInput(object? body) { using var doc = LlmToolJson.ParseObject(body, "XPath"); return ( LlmToolJson.RequiredString(doc.RootElement, "xml", "XPath"), LlmToolJson.OptionalString(doc.RootElement, "xpath") ?? "/"); } } Path: redb-route/redb.Route.Llm.Tools/XPathOptions.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/XPathOptions.cs ---- namespace redb.Route.Llm.Tools; /// /// Configuration for . /// public sealed class XPathOptions { /// Endpoint URI the tool is mounted on. Default "direct:llm.xpath". public string EndpointUri { get; init; } = "direct:llm.xpath"; /// Tool name exposed to the model. Default "xpath". public string ToolName { get; init; } = "xpath"; /// /// Maximum length of the inbound xml string in characters. Default 1 MiB. /// public int MaxXmlChars { get; init; } = 1_048_576; } Path: redb-route/redb.Route.Llm.Tools/XPathTool.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/XPathTool.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 .XPath(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 XPathTool : RouteBuilder { private const string InputSchema = """ { "type": "object", "properties": { "xml": { "type": "string", "description": "XML document to query." }, "xpath": { "type": "string", "description": "XPath 1.0 expression (e.g. '//book[1]/title')." } }, "required": ["xml", "xpath"], "additionalProperties": false } """; private readonly XPathOptions _options; /// Creates the tool with default options. public XPathTool() : this(new XPathOptions()) { } /// Creates the tool with the given options. public XPathTool(XPathOptions options) { _options = options ?? throw new ArgumentNullException(nameof(options)); } /// protected override void Configure() => From(_options.EndpointUri) .AsLlmTool(_options.ToolName) .Description("Extracts a value from an XML document via XPath 1.0. Returns the matched " + "value as a string, or null when nothing matches.") .Input(InputSchema) .SideEffect(ToolSideEffect.ReadOnly) .Cost(ToolCostClass.Cheap) .Then() .XPath(_options); } Path: redb-route/redb.Route.Llm.Tools/redb.Route.Llm.Tools.csproj 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/redb.Route.Llm.Tools.csproj ---- redb.Route.Llm.Tools Batteries-included LLM tools for redb.Route.Llm. Reference implementations of common agent tools (HttpFetch, ShellExec, Fs, Calc) built directly on .NET BCL APIs — no redb.Route connector dependencies. Each tool is a route + descriptor pair registered via the .AsLlmTool(...) DSL. Optional package — host applications opt in by referencing it. esb;messaging;llm;ai;tools;agents;redb README.md