Skip to content

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

fix(inference): pass config to context_window_for_route for override support

Steven Enamakel5c35271aeaed
diff --git a/crates/openhuman-core/src/agent/context/README.md b/crates/openhuman-core/src/agent/context/README.md
index d8c1893b6a..aa6acf0827 100644
--- a/crates/openhuman-core/src/agent/context/README.md
+++ b/crates/openhuman-core/src/agent/context/README.md
@@ -17,7 +17,7 @@ Global context management for agent sessions: system-prompt assembly, per-sessio
| File | Role |
| --- | --- |
| `crates/openhuman-core/src/agent/context/mod.rs` | Module docstring, `pub mod` decls, `pub use` re-exports, and the three shared constants (`DEFAULT_TOOL_RESULT_BUDGET_BYTES`, `CLEARED_PLACEHOLDER`, `DEFAULT_KEEP_RECENT_TOOL_RESULTS`). No other logic. |
-| `crates/openhuman-core/src/agent/context/manager.rs` | `ContextManager`: per-session handle agents hold. Owns the default prompt builder, `ContextStatsState`, and the `ContextConfig`-derived knobs. Surfaces `build_system_prompt` / `build_system_prompt_tiered`, `stats()`, the getters the tinyagents turn reads (`tool_result_budget_bytes`, `compaction_enabled`, `microcompact_keep_recent`, `autocompact_enabled`, `compaction` (trigger override and strategy), `prefer_markdown_tool_output`), and the session-memory trigger/mark methods. |
+| `crates/openhuman-core/src/agent/context/manager.rs` | `ContextManager`: per-session handle agents hold. Owns the default prompt builder, `ContextStatsState`, and the `ContextConfig`-derived knobs. Surfaces `build_system_prompt` / `build_system_prompt_tiered`, `stats()`, the getters the tinyagents turn reads (`tool_result_budget_bytes`, `compaction_enabled`, `microcompact_keep_recent`, `autocompact_enabled`, `compaction()` (trigger override and strategy), `prefer_markdown_tool_output`), and the session-memory trigger/mark methods. |
| `crates/openhuman-core/src/agent/context/stats.rs` | `ContextStatsState`: last provider usage, context-window utilisation, and the shared `SessionMemoryHandle` (`Arc<Mutex<SessionMemoryState>>`). Pure state; issues no LLM calls and does not mutate history. |
| `crates/openhuman-core/src/agent/context/session_memory.rs` | `SessionMemoryState` / `SessionMemoryConfig`: threshold-gated `should_extract` decision (token growth, tool calls, and turns must all cross) and extraction bookkeeping. Holds `ARCHIVIST_EXTRACTION_PROMPT`. State-tracking only; does not spawn the archivist. |
| `crates/openhuman-core/src/agent/context/channels_prompt.rs` | Bespoke free functions `build_system_prompt(...)` / `build_system_prompt_with_identity(...)` (plus `PromptIdentityOverride`, `ProjectContextPlacement`, `render_project_context`) for channel runtimes (Discord/Slack/Telegram/…). Byte-stable for prefix-cache hits; injects workspace bootstrap files (`SOUL.md`, `IDENTITY.md`, optional `PROFILE.md`/`MEMORY.md`, with profile overrides for `SOUL.md`/`MEMORY.md`), tools, safety, skills, runtime, and channel-capabilities sections. |
diff --git a/crates/openhuman-core/src/agent/context_breakdown.rs b/crates/openhuman-core/src/agent/context_breakdown.rs
index 036ae188f9..44f9c8826b 100644
--- a/crates/openhuman-core/src/agent/context_breakdown.rs
+++ b/crates/openhuman-core/src/agent/context_breakdown.rs
@@ -204,9 +204,12 @@ pub async fn context_breakdown(
let total_est_tokens: usize = sections.iter().map(|s| s.est_tokens).sum();
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 context_window = crate::inference::model_context::context_window_for_route(
+ &provider,
+ &report.model,
+ &config,
+ )
+ .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.rs
index 695826ea6f..fce1f3da66 100644
--- a/crates/openhuman-core/src/inference/context_window.rs
+++ b/crates/openhuman-core/src/inference/context_window.rs
@@ -203,9 +203,7 @@ pub(crate) async fn resolve_context_window_with(
if let Some(window) = resolved.window {
if matches!(
resolved.source,
- WindowSource::ConfigOverride
- | WindowSource::ProviderReported
- | WindowSource::LearnedFromOverflow
+ WindowSource::ProviderReported | WindowSource::LearnedFromOverflow
) {
remember_window(provider, model, window);
}
diff --git a/crates/openhuman-core/src/inference/context_window_tests.rs b/crates/openhuman-core/src/inference/context_window_tests.rs
index c0a88f18b1..94941595c6 100644
--- a/crates/openhuman-core/src/inference/context_window_tests.rs
+++ b/crates/openhuman-core/src/inference/context_window_tests.rs
@@ -129,6 +129,7 @@ async fn deepseek_v41_flash_uses_provider_window_not_static_128k() {
crate::inference::model_context::context_window_for_route(
&format!("openrouter:{V41_FLASH}"),
V41_FLASH,
+ &config,
),
Some(1_048_576)
);
diff --git a/crates/openhuman-core/src/inference/model_context.rs b/crates/openhuman-core/src/inference/model_context.rs
index f2aefbf1db..db617c7a34 100644
--- a/crates/openhuman-core/src/inference/model_context.rs
+++ b/crates/openhuman-core/src/inference/model_context.rs
@@ -33,8 +33,13 @@ pub fn context_window_for_model(model: &str) -> Option<u64> {
}
/// 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)
+pub(crate) fn context_window_for_route(
+ provider: &str,
+ model: &str,
+ config: &crate::config::Config,
+) -> Option<u64> {
+ crate::inference::context_window::config_override(model, config)
+ .or_else(|| crate::inference::context_window::remembered_window(provider, model))
.or_else(|| static_context_window_for_model(model))
}