DiagnosticsRecordingChatClient
NexusLabs.Needlr.AgentFramework¶
NexusLabs.Needlr.AgentFramework.Diagnostics¶
DiagnosticsRecordingChatClient Class¶
Microsoft.Extensions.AI.DelegatingChatClient that routes calls through a
NexusLabs.Needlr.AgentFramework.Diagnostics.DiagnosticsChatClientMiddleware and is detectable via
GetService. Because this extends
Microsoft.Extensions.AI.DelegatingChatClient, MEAI's GetService walks the
delegation chain and returns this instance when queried by type — enabling
idempotent middleware installation.
Inheritance System.Object 🡒 Microsoft.Extensions.AI.DelegatingChatClient 🡒 DiagnosticsRecordingChatClient
Remarks¶
Both UsingDiagnostics() and IterativeAgentLoop use this class
to wrap the chat client. Before wrapping, the loop checks
chatClient.GetService<DiagnosticsRecordingChatClient>() — if
one already exists in the pipeline, it skips installation. This makes it
structurally impossible for two diagnostics middlewares to both record
ChatCompletionDiagnostics to the same
AgentRunDiagnosticsBuilder.
Methods¶
DiagnosticsRecordingChatClient.GetResponseAsync(IEnumerable<ChatMessage>, ChatOptions, CancellationToken) Method¶
Sends chat messages and returns the response.
public override System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse> GetResponseAsync(System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.ChatMessage> messages, Microsoft.Extensions.AI.ChatOptions? options, System.Threading.CancellationToken cancellationToken);
Parameters¶
messages System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.ChatMessage>
The sequence of chat messages to send.
options Microsoft.Extensions.AI.ChatOptions
The chat options with which to configure the request.
cancellationToken System.Threading.CancellationToken
The System.Threading.CancellationToken to monitor for cancellation requests. The default is System.Threading.CancellationToken.None.
Implements GetResponseAsync(IEnumerable<ChatMessage>, ChatOptions, CancellationToken)
Returns¶
System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse>
The response messages generated by the client.
Exceptions¶
System.ArgumentNullException
messages is null.
DiagnosticsRecordingChatClient.GetStreamingResponseAsync(IEnumerable<ChatMessage>, ChatOptions, CancellationToken) Method¶
Sends chat messages and streams the response.
public override System.Collections.Generic.IAsyncEnumerable<Microsoft.Extensions.AI.ChatResponseUpdate> GetStreamingResponseAsync(System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.ChatMessage> messages, Microsoft.Extensions.AI.ChatOptions? options, System.Threading.CancellationToken cancellationToken);
Parameters¶
messages System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.ChatMessage>
The sequence of chat messages to send.
options Microsoft.Extensions.AI.ChatOptions
The chat options with which to configure the request.
cancellationToken System.Threading.CancellationToken
The System.Threading.CancellationToken to monitor for cancellation requests. The default is System.Threading.CancellationToken.None.
Implements GetStreamingResponseAsync(IEnumerable<ChatMessage>, ChatOptions, CancellationToken)
Returns¶
System.Collections.Generic.IAsyncEnumerable<Microsoft.Extensions.AI.ChatResponseUpdate>
The response messages generated by the client.