AgentRunDiagnosticsBuilder
NexusLabs.Needlr.AgentFramework¶
NexusLabs.Needlr.AgentFramework.Diagnostics¶
AgentRunDiagnosticsBuilder Class¶
Thread-safe accumulator for diagnostics captured during a single agent run. Both Needlr's built-in diagnostics middleware and consumer-provided middleware use this class to record tool calls, chat completions, and message counts as an agent executes.
Inheritance System.Object 🡒 AgentRunDiagnosticsBuilder
Implements System.IDisposable
Remarks¶
Stored in an System.Threading.AsyncLocal<> so the agent-run, chat-completion, and function-calling middleware all access the same builder instance within an async flow. Call StartNew(string) at the beginning of an agent run and dispose the returned builder when the run completes.
Sequence numbers are reserved BEFORE async work begins (via System.Threading.Interlocked.Increment(System.Int32@)), ensuring parallel tool calls are ordered by invocation time, not completion time.
Methods¶
AgentRunDiagnosticsBuilder.ClearCurrent() Method¶
Clears the builder from the current async flow.
AgentRunDiagnosticsBuilder.Dispose() Method¶
Clears this builder from the current async flow. Equivalent to calling
ClearCurrent() but usable in a using statement.
Implements Dispose()
AgentRunDiagnosticsBuilder.GetCurrent() Method¶
Gets the builder for the current async flow, or null if outside a run.
Returns¶
AgentRunDiagnosticsBuilder.NextChatCompletionSequence() Method¶
Reserves a sequence number for a chat completion (thread-safe).
Returns¶
AgentRunDiagnosticsBuilder.NextToolCallSequence() Method¶
Reserves a sequence number for a tool call (thread-safe).
Returns¶
AgentRunDiagnosticsBuilder.SetExecutionMode(string) Method¶
Sets the execution mode label for these diagnostics.
Known values: "FunctionInvokingChatClient", "IterativeLoop".
Parameters¶
executionMode System.String
AgentRunDiagnosticsBuilder.StartNew(string) Method¶
Creates a new builder and stores it in the current async flow so middleware can access it.
public static NexusLabs.Needlr.AgentFramework.Diagnostics.AgentRunDiagnosticsBuilder StartNew(string agentName);
Parameters¶
agentName System.String