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); }