Path: redb-route/redb.Route.Llm.Abstractions/Tools/IToolClaimsSource.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.Abstractions/Tools/IToolClaimsSource.cs
----
using redb.Route.Abstractions;
namespace redb.Route.Llm.Abstractions.Tools;
///
/// Resolves the claims held by the principal of an agent run. The engine consults it before
/// dispatching a tool whose is not empty.
///
/// Returning null means "this run has no verifiable principal"; returning an empty set means
/// "a principal exists and holds nothing". Both deny a claimed tool — the distinction is diagnostic
/// only. AddRedbRouteLlm() registers the default implementation,
/// ExchangePrincipalClaimsSource, which reads the caller from the exchange; a host with its
/// own vocabulary registers its own source instead (it wins). Removing the default leaves
/// claim-declaring tools unbuildable: that is the fail-closed default, not an oversight.
///
///
/// Claim names are scope-like strings, matching the vocabulary the ecosystem already issues for
/// authorization scopes: redb.Identity hands out values such as identity:scopes:read /
/// identity:scopes:write (IdentityScopes) and puts them in the token's scope
/// claim. Which source feeds this interface — and therefore which exact names a tool may require —
/// is a deployment decision, not something this contract fixes; the engine only compares strings.
///
///
public interface IToolClaimsSource
{
///
/// Returns the claims held by the principal owning , or null
/// when the run has no verifiable principal.
///
/// The agent run's exchange — carries the DI scope the host resolves its
/// identity/security services from.
IReadOnlyCollection? GetClaims(IExchange exchange);
}
///
/// Claims source backed by a delegate — the seam for deployments that resolve claims from their own
/// identity layer, and for tests.
///
public sealed class DelegateToolClaimsSource : IToolClaimsSource
{
private readonly Func?> _resolve;
/// Creates a source over .
/// Delegate returning the claims (or null for "no verifiable principal").
public DelegateToolClaimsSource(Func?> resolve)
{
ArgumentNullException.ThrowIfNull(resolve);
_resolve = resolve;
}
///
public IReadOnlyCollection? GetClaims(IExchange exchange) => _resolve(exchange);
}