Class RedbToolIdempotencyStore

Assembly: redb.Route.Llm.dll

REDB-backed . Reservations are tracked by a
(processor name llm-tool-idempotency) over the same redb the tool
outputs go to: the instance the endpoint's ?redb= names, else the constructor's default name, else the
context's default redb. One rule for every case, so a reservation never sits in another database than the output it
guards. The scope of that redb is opened per operation, on first use. Idempotent tool outputs
are persisted in a row whose composite
key "llm-tool:{conv}:{toolUseId}" lives in _objects.value_string
(partial index on PostgreSQL/SQLite; MSSQL cannot index NVARCHAR(MAX)) and,
normalized, in _objects._value_unique — the per-scheme unique index
keeps a raced completion on a single row. The dedicated scheme keeps
idempotency rows physically separate from
content-hash entries — lookups touch a single scheme partition.
On a duplicate, the previously-saved output is returned and the model
never sees a second side effect.

The store does not own an instance — each call
resolves one through IRouteContext.GetRedbService(name, exchange),
which honours the per-exchange scope cache. The redb name is read from
exchange.Properties[LlmKeys.RedbName] (set by the LLM endpoint URI),
falling back to the constructor-supplied default name and then to the host's
default unnamed instance.

public sealed class RedbToolIdempotencyStore : IToolIdempotencyStore

Inheritance

Object→RedbToolIdempotencyStore

Implements

Methods

CompleteAsync(string, string, string, IExchange?, CancellationToken)

Persists the tool output JSON for the previously-reserved key.

public Task CompleteAsync(string conversationId, string toolUseId, string outputJson, IExchange? exchange = null, CancellationToken ct = default)

ReleaseAsync(string, string, IExchange?, CancellationToken)

Releases the reservation on failure so a retry can re-run the tool.

public Task ReleaseAsync(string conversationId, string toolUseId, IExchange? exchange = null, CancellationToken ct = default)

TryReserveAsync(string, string, IExchange?, CancellationToken)

Attempts to reserve toolUseId for the given conversation.

public Task<ToolIdempotencyReservation> TryReserveAsync(string conversationId, string toolUseId, IExchange? exchange = null, CancellationToken ct = default)

Constructors

RedbToolIdempotencyStore(IRouteContext, string?)

Creates the store over context's redb: the instance defaultRedbName names