MentorAgent Docs
Menu

ReferencePackage: Novior.MentorAgent.Abstractions

IMentorMetricsStore interface

The IMentorMetricsStore interface of Novior.MentorAgent.Abstractions.Interfaces: Optional persistence/source for the admin token & cost dashboard (roadmap…

View as Markdown
On this page

Optional persistence/source for the admin token & cost dashboard (roadmap #9). By default MentorAgent keeps metrics only in RAM (they reset when the process restarts). Register a custom implementation beforeAddMentorAgent() to make the dashboard survive restarts or to read aggregated data from an external backend:

Example
// Local durability — persist a JSON/DB snapshot; the dashboard keeps reading live RAM,
// seeded from the last save on startup.
builder.Services.AddSingleton<IMentorMetricsStore, FileMetricsStore>();

// External source — the dashboard reads the aggregate the #8 OpenTelemetry export already
// pushed to Prometheus / Azure Monitor (multi-instance, historical).
builder.Services.AddSingleton<IMentorMetricsStore, PrometheusMetricsStore>();

builder.Services.AddMentorAgent(options => { ... });

The two scenarios use different halves of this contract, so each implementation overrides only the methods it needs (the others keep their no-op defaults):

Namespace: Novior.MentorAgent.Abstractions.Interfaces. Package: Novior.MentorAgent.Abstractions.

public interface IMentorMetricsStore

Terminal
dotnet add package Novior.MentorAgent.Abstractions

Task<MentorMetricsSnapshot?> LoadForSeedAsync(CancellationToken ct = default)

Called once at startup so a durable store can restore the previous totals into the in-RAM counters. Return null to start fresh (external sources return null — they serve live via IMentorMetricsStore.QueryAsync instead).

Task<MentorMetricsSnapshot?> QueryAsync(CancellationToken ct = default)

Called on every dashboard/endpoint read. External sources query the backend and return the authoritative (possibly multi-instance, historical) aggregate. Local/null stores return null, and the caller serves the live in-RAM snapshot instead.

Task SaveAsync(MentorMetricsSnapshot snapshot, CancellationToken ct = default)

Called periodically and on graceful shutdown with the current snapshot. Durable stores persist it (file/DB); external sources leave the default no-op because #8 OpenTelemetry already exports.