Skip to content

DiagnosticsCharCounter

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework.Diagnostics

DiagnosticsCharCounter Class

Computes character counts of chat messages, responses, tool arguments, and tool results for diagnostics capture. Character counts are a direct programmatic measure of payload size — distinct from the LLM-provider-reported TokenUsage — and are useful for detecting chat-reducer drift, prompt bloat, and unexpectedly large tool responses during evaluation.

public static class DiagnosticsCharCounter

Inheritance System.Object 🡒 DiagnosticsCharCounter

Remarks

All methods are null-safe and exception-tolerant: any failure to measure returns 0 rather than throwing. This matches the diagnostics alpha invariant that capture must never destabilize the live path.

Methods

DiagnosticsCharCounter.ChatMessagesLength(IEnumerable<ChatMessage>) Method

Sums the character count of all text contents across the supplied chat messages. Non-text content (images, function calls) is ignored.

public static long ChatMessagesLength(System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.ChatMessage>? messages);

Parameters

messages System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.ChatMessage>

Returns

System.Int64

DiagnosticsCharCounter.ChatResponseLength(ChatResponse) Method

Sums the character count of all text contents across every message in the supplied Microsoft.Extensions.AI.ChatResponse. Returns 0 when the response is null or contains no text content.

public static long ChatResponseLength(Microsoft.Extensions.AI.ChatResponse? response);

Parameters

response Microsoft.Extensions.AI.ChatResponse

Returns

System.Int64

DiagnosticsCharCounter.JsonLength(object) Method

Returns the character length of the JSON-serialized representation of the supplied value. Null-safe and exception-tolerant: returns 0 when the value is null or cannot be serialized.

public static long JsonLength(object? value);

Parameters

value System.Object

Returns

System.Int64