Skip to content

IAgentMetrics

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework.Diagnostics

IAgentMetrics Interface

Records agent execution metrics for observability. The default implementation emits System.Diagnostics.Metrics.Meter counters/histograms and System.Diagnostics.ActivitySource activities compatible with OpenTelemetry.

public interface IAgentMetrics

Remarks

Registered via DI — consumers can replace with a no-op or custom implementation. The diagnostics middleware automatically calls these methods; tools and orchestrators do not need to call them directly.

If OpenTelemetry is wired in the host (e.g., via AddOpenTelemetry()), these metrics are exported automatically. No needlr-specific configuration required.

Methods

IAgentMetrics.RecordChatCompletion(string, TimeSpan, bool) Method

Records a completed LLM chat completion call.

void RecordChatCompletion(string model, System.TimeSpan duration, bool succeeded);

Parameters

model System.String

The model identifier.

duration System.TimeSpan

How long the completion took.

succeeded System.Boolean

Whether the completion succeeded.

IAgentMetrics.RecordRunCompleted(IAgentRunDiagnostics) Method

Records that an agent run has completed with the given diagnostics.

void RecordRunCompleted(NexusLabs.Needlr.AgentFramework.Diagnostics.IAgentRunDiagnostics diagnostics);

Parameters

diagnostics IAgentRunDiagnostics

The completed run's diagnostics.

IAgentMetrics.RecordRunStarted(string) Method

Records that an agent run has started.

void RecordRunStarted(string agentName);

Parameters

agentName System.String

The name of the agent.

IAgentMetrics.RecordToolCall(string, TimeSpan, bool) Method

Records a completed tool call.

void RecordToolCall(string toolName, System.TimeSpan duration, bool succeeded);

Parameters

toolName System.String

The tool that was invoked.

duration System.TimeSpan

How long the tool call took.

succeeded System.Boolean

Whether the tool call succeeded.