Skip to content

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

fix(context): remove unused context manager and related types

Steven Enamakelbb4b494a3d06
diff --git a/crates/openhuman-core/src/agent/context/manager.rs b/crates/openhuman-core/src/agent/context/manager.rs
index 107fa8cf34..dd896f126c 100644
--- a/crates/openhuman-core/src/agent/context/manager.rs
+++ b/crates/openhuman-core/src/agent/context/manager.rs
@@ -86,6 +86,10 @@ pub struct ContextManager {
/// `[context].autocompact_enabled` so a diagnostic/test opt-out doesn't spend
/// summarizer tokens or rewrite history. See [`ContextConfig::autocompact_enabled`].
autocompact_enabled: bool,
+ /// `[context].compaction_trigger_tokens`: absolute compaction trigger
+ /// overriding the window fraction. See
+ /// [`ContextConfig::compaction_trigger_tokens`].
+ compaction_trigger_tokens: Option<u64>,
}
impl ContextManager {
@@ -119,6 +123,7 @@ impl ContextManager {
// Summarization is off when the whole context system is disabled OR
// autocompaction specifically is turned off.
autocompact_enabled: config.enabled && config.autocompact_enabled,
+ compaction_trigger_tokens: config.compaction_trigger_tokens.filter(|t| *t > 0),
}
}
@@ -157,6 +162,12 @@ impl ContextManager {
self.autocompact_enabled
}
+ /// Absolute compaction trigger overriding the window fraction, when
+ /// configured (benchmarks / debugging).
+ pub fn compaction_trigger_tokens(&self) -> Option<u64> {
+ self.compaction_trigger_tokens
+ }
+
// ─── Budget tracking ──────────────────────────────────────────
/// Feed the latest provider [`BilledUsage`] into utilisation stats and the
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index 4ffc7ee11d..a70f5c7967 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -1387,6 +1387,7 @@ impl OpenHumanSessionHost {
tokenjuice_compaction_enabled,
microcompact_keep_recent,
autocompact_enabled,
+ compaction_trigger_tokens,
) = {
let context = self
.context
@@ -1397,6 +1398,7 @@ impl OpenHumanSessionHost {
context.compaction_enabled(),
context.microcompact_keep_recent(),
context.autocompact_enabled(),
+ context.compaction_trigger_tokens(),
)
};
let artifact_store = super::artifact_wiring::build_artifact_store(
@@ -1416,6 +1418,7 @@ impl OpenHumanSessionHost {
runtime_config: self.runtime_config.clone(),
microcompact_keep_recent,
autocompact_enabled,
+ compaction_trigger_tokens,
transcript_snapshot: None,
};
let driver = Arc::new(OpenHumanSessionDriver::new(
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/graph/dispatch.rs b/crates/openhuman-core/src/agent/subagent_host/ops/graph/dispatch.rs
index 0f58575748..2947a57aac 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/graph/dispatch.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/graph/dispatch.rs
@@ -553,6 +553,7 @@ fn build_subagent_context_mw(
// Summarization step honors the `[context].enabled` + autocompact
// opt-outs, same as `ContextManager::autocompact_enabled`.
mw.autocompact_enabled = ctx.enabled && ctx.autocompact_enabled;
+ mw.compaction_trigger_tokens = ctx.compaction_trigger_tokens.filter(|t| *t > 0);
tracing::debug!(
tokenjuice_compaction_enabled = mw.tokenjuice_compaction_enabled,
compression = ?mw.tokenjuice_compression,
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
index 9434ec42b3..2112d551cb 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
@@ -293,6 +293,7 @@ pub(super) fn assemble_turn_harness(
// Capture context settings before `install` consumes `context_mw`.
let autocompact_enabled = context_mw.autocompact_enabled;
+ let compaction_trigger_tokens = context_mw.compaction_trigger_tokens;
// Captured for the same reason `autocompact_enabled` is — `install` consumes
// `context_mw` — and used to site microcompact below, after compression.
let microcompact_keep_recent = context_mw.microcompact_keep_recent;
@@ -580,6 +581,7 @@ pub(super) fn assemble_turn_harness(
model,
context_window,
autocompact_enabled,
+ compaction_trigger_tokens,
microcompact_keep_recent,
summarizer_model,
pause_at_cap && subagent_scope.is_none(),
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
index 5a50e21651..3112ff0fb9 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
@@ -55,6 +55,10 @@ pub(crate) struct TurnContextMiddleware {
/// summarizer tokens or rewrite history. The deterministic hard-trim backstop
/// still installs regardless. Defaults to `true` (see [`defaults`](Self::defaults)).
pub(crate) autocompact_enabled: bool,
+ /// `[context].compaction_trigger_tokens`: absolute compaction trigger
+ /// overriding the window fraction, and installing compaction even when the
+ /// window is unknown. `None` (the default) keeps 90% of the window.
+ pub(crate) compaction_trigger_tokens: Option<u64>,
/// Live transcript snapshot sink (#4466). When set, a
/// [`TranscriptSnapshotMiddleware`] mirrors the running conversation into
/// this shared buffer before every model call, so an erroring run can still
@@ -347,6 +351,7 @@ impl TurnContextMiddleware {
runtime_config: None,
microcompact_keep_recent: 0,
autocompact_enabled: true,
+ compaction_trigger_tokens: None,
transcript_snapshot: None,
}
}
diff --git a/crates/openhuman-core/src/config/schema/context.rs b/crates/openhuman-core/src/config/schema/context.rs
index 5d0aadd5fa..b02aa42720 100644
--- a/crates/openhuman-core/src/config/schema/context.rs
+++ b/crates/openhuman-core/src/config/schema/context.rs
@@ -124,6 +124,16 @@ pub struct ContextConfig {
/// `compaction_enabled = false` or `OPENHUMAN_COMPACTION=0`.
#[serde(default = "default_true")]
pub compaction_enabled: bool,
+
+ /// Absolute token count at which context compaction (the summarization
+ /// step) fires, overriding the default of 90% of the model's context
+ /// window. Also enables compaction for a model whose window is unknown.
+ ///
+ /// For benchmarks and debugging that need compaction to happen early;
+ /// leave unset in normal use. `None` or `0` means no override. Env:
+ /// `OPENHUMAN_COMPACTION_TRIGGER_TOKENS`.
+ #[serde(default)]
+ pub compaction_trigger_tokens: Option<u64>,
}
fn default_enabled() -> bool {
@@ -168,6 +178,7 @@ impl Default for ContextConfig {
summarizer_model: None,
prefer_markdown_tool_output: default_true(),
compaction_enabled: default_true(),
+ compaction_trigger_tokens: None,
}
}
}
diff --git a/crates/openhuman-core/src/config/schema/load/env_overlay/dictation_context.rs b/crates/openhuman-core/src/config/schema/load/env_overlay/dictation_context.rs
index 587e4d992b..ec808be1b7 100644
--- a/crates/openhuman-core/src/config/schema/load/env_overlay/dictation_context.rs
+++ b/crates/openhuman-core/src/config/schema/load/env_overlay/dictation_context.rs
@@ -84,6 +84,20 @@ impl Config {
_ => {}
}
}
+ // Absolute compaction trigger (benchmarks / debugging). `0` or an
+ // empty value clears an override set in `config.toml`.
+ if let Some(val) = env.get("OPENHUMAN_COMPACTION_TRIGGER_TOKENS") {
+ match val.trim() {
+ "" | "0" => self.context.compaction_trigger_tokens = None,
+ raw => match raw.parse::<u64>() {
+ Ok(tokens) => self.context.compaction_trigger_tokens = Some(tokens),
+ Err(_) => tracing::warn!(
+ value = raw,
+ "[config] ignoring unparseable OPENHUMAN_COMPACTION_TRIGGER_TOKENS"
+ ),
+ },
+ }
+ }
if let Some(val) = env.get("OPENHUMAN_CONTEXT_TOOL_RESULT_BUDGET_BYTES") {
if let Ok(n) = val.trim().parse::<usize>() {
self.context.tool_result_budget_bytes = n;