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.
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.CompletionCollector Property¶
Gets the IChatCompletionCollector wired by the diagnostics system, or null if diagnostics were not configured. Used as a fallback when LastRunDiagnostics is unavailable (e.g., when AsyncLocal state does not propagate across workflow execution boundaries).
Property Value¶
IAgentDiagnosticsAccessor.LastRunDiagnostics Property¶
Gets the diagnostics from the last completed agent run in the current scope, or null if no run has completed yet.
Property Value¶
IAgentDiagnosticsAccessor.ToolCallCollector Property¶
Gets the IToolCallCollector wired by the diagnostics system, or null if diagnostics were not configured. Used as a fallback when LastRunDiagnostics is unavailable (e.g., when AsyncLocal state does not propagate across workflow execution boundaries).
Property Value¶
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.