Skip to main content

nemo_flow_adaptive/types/
cache.rs

1// SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Hot-cache state shared by adaptive runtime features.
5
6use std::collections::HashMap;
7
8use serde::{Deserialize, Serialize};
9
10use crate::types::metadata::AgentHints;
11use crate::types::plan::ExecutionPlan;
12
13/// In-memory cache of adaptive artifacts needed on the hot path.
14///
15/// The adaptive runtime keeps this structure in an [`std::sync::RwLock`] so
16/// intercepts and event-processing tasks can exchange recently learned plans,
17/// trie state, and Adaptive Cache Governor (ACG) summaries without hitting the
18/// configured backend on every request.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct HotCache {
21    /// Current execution plan used for tool parallelism hints.
22    pub plan: Option<ExecutionPlan>,
23    /// Prediction trie used to derive default latency sensitivity hints.
24    pub trie: Option<crate::trie::data_models::PredictionTrieNode>,
25    /// Default agent-level hints computed from the prediction trie.
26    pub agent_hints_default: Option<AgentHints>,
27    /// Per-profile ACG stability results keyed by derived profile identifier.
28    #[serde(default, skip_serializing_if = "HashMap::is_empty")]
29    pub acg_profiles: HashMap<String, crate::acg::stability::StabilityAnalysisResult>,
30    /// Observation counts corresponding to entries in [`Self::acg_profiles`].
31    #[serde(default, skip_serializing_if = "HashMap::is_empty")]
32    pub acg_profile_observation_counts: HashMap<String, u32>,
33    /// Aggregate ACG stability result used for warm-first eligibility checks.
34    pub acg_stability: Option<crate::acg::stability::StabilityAnalysisResult>,
35    /// Observation count associated with [`Self::acg_stability`].
36    pub acg_observation_count: u32,
37}