Skip to content

IToolMetricsAccessor

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework.Diagnostics

IToolMetricsAccessor Interface

Allows tools to attach custom domain-specific metrics during execution. Metrics are collected by the diagnostics function-calling middleware and included in NexusLabs.Needlr.AgentFramework.Diagnostics.ToolCallDiagnostics.CustomMetrics.

public interface IToolMetricsAccessor

Remarks

Tools inject this interface via DI and call AttachMetric(string, object) during execution:

public class WebSearchTool(IToolMetricsAccessor metrics)
{
    [AgentFunction]
    public async Task<string[]> Search(string query)
    {
        metrics.AttachMetric("cache_hit", false);
        metrics.AttachMetric("provider", "brave");
        // ... search logic
    }
}

If called outside a diagnostics scope (no middleware), AttachMetric(string, object) is a no-op.

Methods

IToolMetricsAccessor.AttachMetric(string, object) Method

Attaches a custom metric to the current tool invocation. No-op if called outside a diagnostics scope.

void AttachMetric(string key, object? value);

Parameters

key System.String

The metric key (case-insensitive).

value System.Object

The metric value.

IToolMetricsAccessor.GetCurrentMetrics() Method

Gets the metrics dictionary for the current tool invocation, or null if called outside a tool invocation scope.

System.Collections.Generic.IReadOnlyDictionary<string,object?>? GetCurrentMetrics();

Returns

System.Collections.Generic.IReadOnlyDictionary<System.String,System.Object>