Class RedbAuditObserver
REDB-backed that persists one
row per tool invocation. Non-blocking by
contract: a failed write never breaks a run, and it is logged as a warning with
the tool, the tool_use id and the exchange id, so the missing row can be found.
The observer is invoked from inside the agent loop, not from a route
pipeline, and therefore has no IExchange in scope. Many runs call it at
once, so every call opens a redb scope of its own with
IRouteContext.CreateRedbScope(name) and releases it: a shared instance would
put every run on one connection. The scope uses the constructor-supplied default
name, or the host's default service when null. A custom observer can be
substituted to pipe audit rows elsewhere.
The row belongs to the route's transaction when there is one: under
.Transacted() it is written and rolled back together with the tool writes it
describes.
public sealed class RedbAuditObserver : IAgentObserver
Inheritance
Implements
Methods
OnIterationCompletedAsync(AgentIterationContext, CancellationToken)
Called after each provider call returns, before tool dispatch.
public Task OnIterationCompletedAsync(AgentIterationContext context, CancellationToken ct = default)
OnRunCompletedAsync(AgentRunCompletedContext, CancellationToken)
Called once when an agent run ends (whether normally or via cancellation/error).
public Task OnRunCompletedAsync(AgentRunCompletedContext context, CancellationToken ct = default)
OnRunStartedAsync(AgentRunContext, CancellationToken)
Called once when an agent run begins.
public Task OnRunStartedAsync(AgentRunContext context, CancellationToken ct = default)
OnToolInvokedAsync(AgentToolInvocationContext, CancellationToken)
Called for each tool invocation, after it returns or throws.
public Task OnToolInvokedAsync(AgentToolInvocationContext context, CancellationToken ct = default)
Constructors
RedbAuditObserver(IRouteContext, string?)
Creates the observer. Scheme is synced by the host's redb.InitializeAsync().