The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(inference): key remembered context windows by provider and model
Steven Enamakelec289565c9ec
diff --git a/crates/openhuman-core/src/agent/context_breakdown.rs b/crates/openhuman-core/src/agent/context_breakdown.rsindex 9491675075..8f26cbf736 100644--- a/crates/openhuman-core/src/agent/context_breakdown.rs+++ b/crates/openhuman-core/src/agent/context_breakdown.rs@@ -203,7 +203,11 @@ pub async fn context_breakdown(}let total_est_tokens: usize = sections.iter().map(|s| s.est_tokens).sum();- let context_window = crate::inference::context_window_for_model(&report.model).unwrap_or(0);+ let provider = crate::inference::provider::provider_for_role("chat", &config);+ let context_window = crate::inference::model_context::context_window_for_route(+ &provider,+ &report.model,+ ).unwrap_or(0);let response = ContextBreakdownResponse {agent_id: report.agent.clone(),diff --git a/crates/openhuman-core/src/inference/context_window.rs b/crates/openhuman-core/src/inference/context_window.rsindex ea473dac09..ea11f8e9c4 100644--- a/crates/openhuman-core/src/inference/context_window.rs+++ b/crates/openhuman-core/src/inference/context_window.rs@@ -75,26 +75,26 @@ pub(crate) fn config_override(model: &str, config: &Config) -> Option<u64> {.map(|entry| u64::from(entry.context_window))}-fn remembered() -> &'static Mutex<HashMap<String, u64>> {- static MAP: OnceLock<Mutex<HashMap<String, u64>>> = OnceLock::new();+fn remembered() -> &'static Mutex<HashMap<(String, String), u64>> {+ static MAP: OnceLock<Mutex<HashMap<(String, String), u64>>> = OnceLock::new();MAP.get_or_init(|| Mutex::new(HashMap::new()))}/// The last provider-sourced (or overridden) window resolved for `model` in/// this process.-pub(crate) fn remembered_window(model: &str) -> Option<u64> {+pub(crate) fn remembered_window(provider: &str, model: &str) -> Option<u64> {remembered().lock().unwrap_or_else(std::sync::PoisonError::into_inner)- .get(&model.trim().to_ascii_lowercase())+ .get(&(provider.trim().to_ascii_lowercase(), model.trim().to_ascii_lowercase())).copied()}-fn remember_window(model: &str, window: u64) {+fn remember_window(provider: &str, model: &str, window: u64) {remembered().lock().unwrap_or_else(std::sync::PoisonError::into_inner)- .insert(model.trim().to_ascii_lowercase(), window);+ .insert((provider.trim().to_ascii_lowercase(), model.trim().to_ascii_lowercase()), window);}/// Logs a static guess at `warn` the first time per model, `debug` after.@@ -198,7 +198,7 @@ pub(crate) async fn resolve_context_window_with(| WindowSource::ProviderReported| WindowSource::LearnedFromOverflow) {- remember_window(model, window);+ remember_window(provider, model, window);}}tracing::debug!(diff --git a/crates/openhuman-core/src/inference/model_context.rs b/crates/openhuman-core/src/inference/model_context.rsindex bc4bdba814..599e9e8ec4 100644--- a/crates/openhuman-core/src/inference/model_context.rs+++ b/crates/openhuman-core/src/inference/model_context.rs@@ -30,7 +30,12 @@ const TIER_FLASH_CONTEXT: u64 = 1_000_000;/// Returns `None` when the model is unknown — callers should skip pre-dispatch/// trimming rather than guess.pub fn context_window_for_model(model: &str) -> Option<u64> {- crate::inference::context_window::remembered_window(model)+ static_context_window_for_model(model)+}++/// Resolve the synchronous window for a model on a specific provider route.+pub(crate) fn context_window_for_route(provider: &str, model: &str) -> Option<u64> {+ crate::inference::context_window::remembered_window(provider, model).or_else(|| static_context_window_for_model(model))}