Skip to content

IAgentDiagnosticsAccessor

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework.Diagnostics

IAgentDiagnosticsAccessor Interface

Provides access to the diagnostics captured during the most recent agent run in the current async flow. Uses the mutable-holder System.Threading.AsyncLocal<> pattern so that writes from child async flows (inside middleware) are visible to the parent scope.

public interface IAgentDiagnosticsAccessor

Remarks

Callers wrap agent execution in BeginCapture():

using (diagnosticsAccessor.BeginCapture())
{
    await agent.RunAsync(prompt);
    var diagnostics = diagnosticsAccessor.LastRunDiagnostics;
    // diagnostics contains token usage, tool calls, timing, etc.
}

Properties

IAgentDiagnosticsAccessor.LastRunDiagnostics Property

Gets the diagnostics from the last completed agent run in the current scope, or null if no run has completed yet.

NexusLabs.Needlr.AgentFramework.Diagnostics.IAgentRunDiagnostics? LastRunDiagnostics { get; }

Property Value

IAgentRunDiagnostics

Methods

IAgentDiagnosticsAccessor.BeginCapture() Method

Opens a capture scope. Diagnostics written by middleware during agent execution are visible via LastRunDiagnostics after the run completes. Disposing the returned handle restores the previous scope.

System.IDisposable BeginCapture();

Returns

System.IDisposable