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