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.
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.
Properties¶
IAgentMetrics.ActivitySource Property¶
Gets the System.Diagnostics.ActivitySource for creating distributed tracing spans. Middleware uses this to create System.Diagnostics.Activity instances for agent runs, tool calls, and chat completions that are exported via OpenTelemetry when a listener is registered.
Property Value¶
System.Diagnostics.ActivitySource
Methods¶
IAgentMetrics.RecordChatCompletion(string, TimeSpan, bool) Method¶
Records a completed LLM chat completion call.
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.
Parameters¶
agentName System.String
The name of the agent.
IAgentMetrics.RecordToolCall(string, TimeSpan, bool) Method¶
Records a completed tool call.
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.