Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(inference): handle missing model context in turn models

Steven Enamakelef154650e361
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_models.rs b/crates/openhuman-core/src/agent/tinyagents/turn_models.rs
index 90a959694b..80832ba87e 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_models.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_models.rs
@@ -411,28 +411,33 @@ impl TurnModelSource {
}
}
- /// Resolve the model's effective context window (async provider probe) — the
- /// value that drives the context-window summarization step. Resolved before
- /// [`build`](Self::build) so the harness graph makes no async `Provider` call.
+ /// Resolve the model's effective context window — the value that drives the
+ /// context-window summarization step. Resolved before [`build`](Self::build)
+ /// so the harness graph makes no async call.
+ ///
+ /// A crate-native source asks the provider: config override, then the
+ /// provider's own model listing (bounded and cached, corrected by any limit
+ /// an overflow error stated), and only then the static tables
+ /// ([`crate::inference::context_window`]).
pub(crate) async fn effective_context_window(&self, model: &str) -> Option<u64> {
if let Some(direct) = &self.direct_model {
return direct
.profile()
.and_then(|profile| profile.max_input_tokens);
}
- let provider_string = self.crate_native.as_ref().map(|source| {
- source.primary_override.clone().unwrap_or_else(|| {
- crate::inference::provider::provider_for_role(&source.role, &source.config)
- })
+ let Some(source) = self.crate_native.as_ref() else {
+ return crate::inference::model_context::context_window_for_model(model);
+ };
+ let provider_string = source.primary_override.clone().unwrap_or_else(|| {
+ crate::inference::provider::provider_for_role(&source.role, &source.config)
});
- let local_kind = provider_string
- .as_deref()
- .and_then(tinyinference_local::profile::kind_from_provider_string);
- tinyinference_local::profile::context_window_with_local_fallback(
+ crate::inference::context_window::resolve_context_window(
+ &source.role,
+ &provider_string,
model,
- crate::inference::model_context::context_window_for_model(model),
- local_kind,
+ &source.config,
)
+ .await
}
/// Build this turn's [`TurnModels`] (primary + tier routes + summarizer),
diff --git a/crates/openhuman-core/src/inference/mod.rs b/crates/openhuman-core/src/inference/mod.rs
index eed6d679f9..4c3cb2e1fe 100644
--- a/crates/openhuman-core/src/inference/mod.rs
+++ b/crates/openhuman-core/src/inference/mod.rs
@@ -24,6 +24,7 @@
pub const INFERENCE_COMPILED_IN: bool = cfg!(feature = "inference");
pub mod auth_error_registry;
+pub(crate) mod context_window;
pub mod embedding_host;
pub(crate) mod failure_copy;
pub mod host_runtime;
diff --git a/crates/openhuman-core/src/inference/model_context.rs b/crates/openhuman-core/src/inference/model_context.rs
index 4f93f3c662..bc4bdba814 100644
--- a/crates/openhuman-core/src/inference/model_context.rs
+++ b/crates/openhuman-core/src/inference/model_context.rs
@@ -21,9 +21,23 @@ const TIER_FLASH_CONTEXT: u64 = 1_000_000;
/// Resolve the context window (in tokens) for a model id or OpenHuman tier alias.
///
+/// Prefers the window a turn last resolved for this model from the provider
+/// (or a config override) — see [`crate::inference::context_window`] — and
+/// otherwise falls back to [`static_context_window_for_model`]. Turns resolve
+/// through the async provider path; this synchronous form serves usage meters
+/// and the context breakdown.
+///
/// 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)
+ .or_else(|| static_context_window_for_model(model))
+}
+
+/// The static guess for a model's window: tier aliases, then the cost catalog,
+/// then the generic id-pattern hints. These never override a provider-reported
+/// window; [`crate::inference::context_window`] consults them last.
+pub(crate) fn static_context_window_for_model(model: &str) -> Option<u64> {
let normalized = model.trim();
if normalized.is_empty() {
return None;
diff --git a/vendor/tinyagents b/vendor/tinyagents
index a27ed48ab4..324b54571e 160000
--- a/vendor/tinyagents
+++ b/vendor/tinyagents
@@ -1 +1 @@
-Subproject commit a27ed48ab4dac2685f23e0b12397b647bd5f8b19
+Subproject commit 324b54571ed1740ded743d61e834c0f1965da33b