Skip to main content

agent_storage/contracts/
usage_store.rs

1//! Durable persistence contract for invocation usage and immutable pricing.
2
3use super::StorageError;
4use agent_metering::{ModelPricing, UsageRecord};
5use async_trait::async_trait;
6use uuid::Uuid;
7
8/// Stores accounting records independently of transient run events and telemetry.
9///
10/// Usage records are append-only and keyed by invocation ID. Re-appending an
11/// identical record is idempotent; reusing an ID for different data is rejected.
12/// Pricing versions are immutable once inserted.
13#[async_trait]
14pub trait UsageStore: Send + Sync {
15    async fn append_usage(&self, record: UsageRecord) -> Result<(), StorageError>;
16    async fn list_usage(&self, run_id: Option<Uuid>) -> Result<Vec<UsageRecord>, StorageError>;
17    async fn insert_pricing(&self, pricing: ModelPricing) -> Result<(), StorageError>;
18    async fn get_pricing(
19        &self,
20        provider: &str,
21        model: &str,
22        version: &str,
23    ) -> Result<Option<ModelPricing>, StorageError>;
24    async fn list_pricing(
25        &self,
26        provider: &str,
27        model: &str,
28    ) -> Result<Vec<ModelPricing>, StorageError>;
29    async fn list_all_pricing(&self) -> Result<Vec<ModelPricing>, StorageError>;
30}