MentorAgent Docs
Menu

Questa pagina non è ancora tradotta in italiano: qui la trovi in inglese.

ReferencePackage: Novior.MentorAgent

MentorMetrics class

The MentorMetrics class of Novior.MentorAgent.Core: Thread-safe, process-wide implementation of IMentorMetrics that feeds the admin token & cost dashboard…

On this page

Thread-safe, process-wide implementation of IMentorMetrics that feeds the admin token & cost dashboard (roadmap #9). Usage is bucketed per model — the cheap chat model, the strong routing model and the embedding model are tracked separately (tokens, requests, latency) with an hourly time series for the temporal charts. Cost is computed per model, only for models present in MentorOptions.ModelPricing. Conversation-level counters (turns, errors, guardrail blocks, top actions) are model-independent.

Namespace: Novior.MentorAgent.Core. Package: Novior.MentorAgent.

public sealed class MentorMetrics : IMentorMetrics

Implements IMentorMetrics.

Terminal
dotnet add package Novior.MentorAgent

public MentorMetrics(MentorTokenUsage tokens, IOptions<MentorOptions> options)

public string? EmbeddingModelId { get; set; }

Embedding model id, set by the orchestrator when an embedding generator is configured.

public string? ModelId { get; set; }

Primary (cheap) chat model id — set once by the orchestrator. Also used for pricing lookup.

public string? StrongModelId { get; set; }

Strong routing model id (roadmap #11), set by the orchestrator when configured.

public void EnsureConfiguredModels()

Registers the configured cheap / strong / embedding model ids as zero-usage buckets so they appear (and are selectable) in the dashboard before they serve any traffic — e.g. the strong routing model when no turn has escalated to it yet. Idempotent and non-destructive: it never resets a bucket that already has live counters.

The ids are read straight from the configured clients' metadata (the orchestrator captures the same values, but the coordinator is built lazily on first chat — this keeps the dashboard correct even when it's opened before any conversation).

public MentorMetricsSnapshot GetSnapshot()

public void RecordError()

public void RecordGuardrailBlock()

public void RecordModelUsage(string? modelId, long inputTokens, long outputTokens, double? latencyMs = null, double? timeToFirstByteMs = null, bool usageMeasured = true)

Records one model round-trip's usage against the given model id (roadmap #9 per-model dashboard). Called by TokenUsageChatClient (chat, reading response.ModelId) and by MeteringEmbeddingGenerator (embeddings). Latency/TTFB are optional.

Parameters

  • usageMeasured: false when the call reached the provider but never reported its token counts — a stream the user stopped. Such a call is still counted as a request (it was billed, input prompt included) and disclosed through MentorModelUsage.RequestsWithoutUsage, but it contributes nothing to the token totals: the numbers are unknown, and zero is a fabricated measurement, not a cautious one (BUG-032).
  • modelId: The model that served the call, as the provider reported it.
  • inputTokens: Input tokens of the call.
  • outputTokens: Output tokens of the call.
  • latencyMs: Duration of the whole call, when measured.
  • timeToFirstByteMs: Time to the first streamed byte, when measured.

public void RecordServed()

public void RecordToolCall(string toolName)

public void RecordTurn()

public void Reset()

public void Seed(MentorMetricsSnapshot snapshot)

Restores counters and per-model buckets from a persisted snapshot (roadmap #9 durable dashboard). Called once at startup by the persistence hosted service so totals continue across a restart.