Skip to content

TeeDiagnosticsSink

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework.Diagnostics

TeeDiagnosticsSink Class

An IDiagnosticsSink that dispatches every record to N inner sinks. Owns its own sequence counters so all sinks see consistent sequence numbers.

public sealed class TeeDiagnosticsSink : NexusLabs.Needlr.AgentFramework.Diagnostics.IDiagnosticsSink

Inheritance System.Object 🡒 TeeDiagnosticsSink

Implements IDiagnosticsSink

Example

var inMemory = AgentRunDiagnosticsBuilder.StartNew("Agent");
var fileSink = new MyFileDiagnosticsSink("Agent");
var tee = new TeeDiagnosticsSink("Agent", [inMemory, fileSink]);
tee.AddToolCall(toolDiag); // dispatched to both sinks

Remarks

Secondary sink failures are best-effort: if an inner sink throws, the exception is swallowed and dispatch continues to remaining sinks. This ensures that a broken observability sink (e.g., a file writer with a full disk) never breaks production agent execution.

Use this when you need to fan out diagnostic records to multiple consumers — for example, an in-memory builder for programmatic access plus a file-based sink for post-hoc analysis.

Constructors

TeeDiagnosticsSink(string, IReadOnlyList<IDiagnosticsSink>) Constructor

Creates a tee-sink that dispatches to the specified inner sinks.

public TeeDiagnosticsSink(string agentName, System.Collections.Generic.IReadOnlyList<NexusLabs.Needlr.AgentFramework.Diagnostics.IDiagnosticsSink> sinks);

Parameters

agentName System.String

The agent name attributed to records routed through this sink.

sinks System.Collections.Generic.IReadOnlyList<IDiagnosticsSink>

The inner sinks to dispatch to. Must not be empty.

Exceptions

System.ArgumentNullException
sinks is null.

System.ArgumentException
sinks is empty.

Properties

TeeDiagnosticsSink.AgentName Property

Gets the name of the agent associated with this sink, or null if unknown. Writers use this to attribute diagnostic records to the correct agent.

public string? AgentName { get; }

Implements AgentName

Property Value

System.String

Methods

TeeDiagnosticsSink.AddChatCompletion(ChatCompletionDiagnostics) Method

Records a completed chat completion call.

public void AddChatCompletion(NexusLabs.Needlr.AgentFramework.Diagnostics.ChatCompletionDiagnostics diagnostics);

Parameters

diagnostics ChatCompletionDiagnostics

Implements AddChatCompletion(ChatCompletionDiagnostics)

TeeDiagnosticsSink.AddToolCall(ToolCallDiagnostics) Method

Records a completed tool call.

public void AddToolCall(NexusLabs.Needlr.AgentFramework.Diagnostics.ToolCallDiagnostics diagnostics);

Parameters

diagnostics ToolCallDiagnostics

Implements AddToolCall(ToolCallDiagnostics)

TeeDiagnosticsSink.NextChatCompletionSequence() Method

Reserves a sequence number for a chat completion (thread-safe).

public int NextChatCompletionSequence();

Implements NextChatCompletionSequence()

Returns

System.Int32

TeeDiagnosticsSink.NextToolCallSequence() Method

Reserves a sequence number for a tool call (thread-safe).

public int NextToolCallSequence();

Implements NextToolCallSequence()

Returns

System.Int32