Skip to content

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

refactor(config): bundle compaction trigger and strategy into a single struct

Steven Enamakel4ec7fba4c8b4
diff --git a/crates/openhuman-core/src/agent/context/manager.rs b/crates/openhuman-core/src/agent/context/manager.rs
index 98c091f311..f45652ff1c 100644
--- a/crates/openhuman-core/src/agent/context/manager.rs
+++ b/crates/openhuman-core/src/agent/context/manager.rs
@@ -86,13 +86,9 @@ 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>,
- /// `[context].compaction_strategy`. See
- /// [`ContextConfig::compaction_strategy`].
- compaction_strategy: crate::config::CompactionStrategy,
+ /// `[context].compaction_trigger_tokens` and `compaction_strategy`. See
+ /// [`ContextConfig::compaction_settings`].
+ compaction: crate::config::CompactionSettings,
}
impl ContextManager {
@@ -126,8 +122,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),
- compaction_strategy: config.compaction_strategy,
+ compaction: config.compaction_settings(),
}
}
@@ -166,15 +161,10 @@ 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
- }
-
- /// How compaction writes its checkpoint.
- pub fn compaction_strategy(&self) -> crate::config::CompactionStrategy {
- self.compaction_strategy
+ /// The compaction trigger override (benchmarks / debugging) and the
+ /// checkpoint strategy.
+ pub fn compaction(&self) -> crate::config::CompactionSettings {
+ self.compaction
}
// ─── Budget tracking ──────────────────────────────────────────
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 e95dd85bc2..06430cb62e 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -1387,7 +1387,7 @@ impl OpenHumanSessionHost {
tokenjuice_compaction_enabled,
microcompact_keep_recent,
autocompact_enabled,
- (compaction_trigger_tokens, compaction_strategy),
+ compaction,
) = {
let context = self
.context
@@ -1398,10 +1398,7 @@ impl OpenHumanSessionHost {
context.compaction_enabled(),
context.microcompact_keep_recent(),
context.autocompact_enabled(),
- (
- context.compaction_trigger_tokens(),
- context.compaction_strategy(),
- ),
+ context.compaction(),
)
};
let artifact_store = super::artifact_wiring::build_artifact_store(
@@ -1421,8 +1418,7 @@ impl OpenHumanSessionHost {
runtime_config: self.runtime_config.clone(),
microcompact_keep_recent,
autocompact_enabled,
- compaction_trigger_tokens,
- compaction_strategy,
+ compaction,
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 d246591cb2..1afbf6c289 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,8 +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);
- mw.compaction_strategy = ctx.compaction_strategy;
+ mw.compaction = ctx.compaction_settings();
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 54062cefa2..4b3fbf6672 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
@@ -293,8 +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;
- let compaction_strategy = context_mw.compaction_strategy;
+ let compaction = context_mw.compaction;
// 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;
@@ -582,8 +581,8 @@ pub(super) fn assemble_turn_harness(
model,
context_window,
autocompact_enabled,
- compaction_trigger_tokens,
- compaction_strategy,
+ compaction.trigger_tokens,
+ compaction.strategy,
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 300e100089..1868a6515d 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
@@ -55,12 +55,11 @@ 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>,
- /// `[context].compaction_strategy`: how compaction writes its checkpoint.
- pub(crate) compaction_strategy: crate::config::CompactionStrategy,
+ /// `[context].compaction_trigger_tokens` and `compaction_strategy`: the
+ /// absolute compaction trigger override (installing compaction even when
+ /// the window is unknown; `None` keeps the window-relative default) and
+ /// how a compaction writes its checkpoint.
+ pub(crate) compaction: crate::config::CompactionSettings,
/// 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
@@ -352,8 +351,7 @@ impl TurnContextMiddleware {
runtime_config: None,
microcompact_keep_recent: 0,
autocompact_enabled: true,
- compaction_trigger_tokens: None,
- compaction_strategy: Default::default(),
+ compaction: Default::default(),
transcript_snapshot: None,
}
}
diff --git a/crates/openhuman-core/src/config/mod.rs b/crates/openhuman-core/src/config/mod.rs
index cbdf2b4e0d..2391ba40a8 100644
--- a/crates/openhuman-core/src/config/mod.rs
+++ b/crates/openhuman-core/src/config/mod.rs
@@ -42,29 +42,30 @@ pub use schema::{
build_runtime_proxy_client_with_timeouts, output_language_directive, runtime_proxy_config,
set_runtime_proxy_config, AgentConfig, AuditConfig, AutonomyConfig, BrowserComputerUseConfig,
BrowserConfig, CapabilityProviderConfig, CapabilityProviderTrustState, ChannelsConfig,
- CompactionStrategy, ComposioConfig, ComposioDirectBaseUrls, ComposioHostCredential,
- ComputerConfig, Config, ContextConfig, CostConfig, CronConfig, CurlConfig, DashboardConfig,
- DecisionModel, DelegateAgentConfig, DiagramViewerConfig, DictationActivationMode,
- DictationConfig, DiscordConfig, DockerRuntimeConfig, EmailConfig, EmbeddingRouteConfig,
- GitbooksConfig, HttpHeader, HttpRequestConfig, IMessageConfig, IntegrationToggle,
- IntegrationsConfig, LarkConfig, LearningConfig, LegacySearchInputs, LinqConfig, LlmBackend,
- LocalAiConfig, MatrixConfig, McpAuthConfig, McpClientConfig, McpClientIdentityConfig,
- McpServerConfig, McpToolExposure, MemoryConfig, MemoryTreeConfig, ModelRouteConfig,
- MultimodalConfig, MultimodalFileConfig, ObservabilityConfig, OrchestratorModelConfig,
- PrivacyConfig, PrivacyMode, ProxyConfig, ProxyScope, ReflectionSource, ReliabilityConfig,
- ResourceLimitsConfig, RuntimeConfig, RuntimePoolConfig, RuntimePoolLangConfig, SandboxBackend,
- SandboxConfig, SchedulerConfig, SchedulerGateConfig, SchedulerGateMode, SearchConfig,
- SearchEngineCredentials, SearchPresentation, SearchProviderSettings, SearchRoute,
- SearxngConfig, SecretsConfig, SecurityConfig, ShellConfig, SlackConfig, StorageConfig,
- StorageProviderConfig, StorageProviderSection, StreamMode, SttEngine, TeamModelConfig,
- TelegramConfig, TokenjuiceConfig, UpdateConfig, UpdateRestartStrategy, VoiceActivationMode,
- VoiceServerConfig, WebSearchConfig, WebhookConfig, YuanbaoConfig, DEFAULT_CLOUD_LLM_MODEL,
- DEFAULT_MEMORY_SYNC_INTERVAL_SECS, DEFAULT_MODEL, LEGACY_TIER_MODELS,
- MANAGED_MULTIMODAL_MODELS, MANAGED_SEARCH_PROVIDERS, MEMORY_SYNC_INTERVAL_PRESETS_SECS,
- MODEL_IMAGE_GENERATION_AGENT, MODEL_MANAGED_DEFAULT, MODEL_MEDIA_UNDERSTANDING,
- MODEL_VIDEO_GENERATION_AGENT, SEARCH_ENGINE_BRAVE, SEARCH_ENGINE_DISABLED, SEARCH_ENGINE_EXA,
- SEARCH_ENGINE_MANAGED, SEARCH_ENGINE_PARALLEL, SEARCH_ENGINE_QUERIT, SEARCH_ENGINE_TAVILY,
- SEARCH_PROVIDERS, SEARCH_ROLES, SEARCH_ROLE_ANSWER, SEARCH_ROLE_CONTENTS, SEARCH_ROLE_SEARCH,
+ CompactionSettings, CompactionStrategy, ComposioConfig, ComposioDirectBaseUrls,
+ ComposioHostCredential, ComputerConfig, Config, ContextConfig, CostConfig, CronConfig,
+ CurlConfig, DashboardConfig, DecisionModel, DelegateAgentConfig, DiagramViewerConfig,
+ DictationActivationMode, DictationConfig, DiscordConfig, DockerRuntimeConfig, EmailConfig,
+ EmbeddingRouteConfig, GitbooksConfig, HttpHeader, HttpRequestConfig, IMessageConfig,
+ IntegrationToggle, IntegrationsConfig, LarkConfig, LearningConfig, LegacySearchInputs,
+ LinqConfig, LlmBackend, LocalAiConfig, MatrixConfig, McpAuthConfig, McpClientConfig,
+ McpClientIdentityConfig, McpServerConfig, McpToolExposure, MemoryConfig, MemoryTreeConfig,
+ ModelRouteConfig, MultimodalConfig, MultimodalFileConfig, ObservabilityConfig,
+ OrchestratorModelConfig, PrivacyConfig, PrivacyMode, ProxyConfig, ProxyScope, ReflectionSource,
+ ReliabilityConfig, ResourceLimitsConfig, RuntimeConfig, RuntimePoolConfig,
+ RuntimePoolLangConfig, SandboxBackend, SandboxConfig, SchedulerConfig, SchedulerGateConfig,
+ SchedulerGateMode, SearchConfig, SearchEngineCredentials, SearchPresentation,
+ SearchProviderSettings, SearchRoute, SearxngConfig, SecretsConfig, SecurityConfig, ShellConfig,
+ SlackConfig, StorageConfig, StorageProviderConfig, StorageProviderSection, StreamMode,
+ SttEngine, TeamModelConfig, TelegramConfig, TokenjuiceConfig, UpdateConfig,
+ UpdateRestartStrategy, VoiceActivationMode, VoiceServerConfig, WebSearchConfig, WebhookConfig,
+ YuanbaoConfig, DEFAULT_CLOUD_LLM_MODEL, DEFAULT_MEMORY_SYNC_INTERVAL_SECS, DEFAULT_MODEL,
+ LEGACY_TIER_MODELS, MANAGED_MULTIMODAL_MODELS, MANAGED_SEARCH_PROVIDERS,
+ MEMORY_SYNC_INTERVAL_PRESETS_SECS, MODEL_IMAGE_GENERATION_AGENT, MODEL_MANAGED_DEFAULT,
+ MODEL_MEDIA_UNDERSTANDING, MODEL_VIDEO_GENERATION_AGENT, SEARCH_ENGINE_BRAVE,
+ SEARCH_ENGINE_DISABLED, SEARCH_ENGINE_EXA, SEARCH_ENGINE_MANAGED, SEARCH_ENGINE_PARALLEL,
+ SEARCH_ENGINE_QUERIT, SEARCH_ENGINE_TAVILY, SEARCH_PROVIDERS, SEARCH_ROLES, SEARCH_ROLE_ANSWER,
+ SEARCH_ROLE_CONTENTS, SEARCH_ROLE_SEARCH,
};
// Kept as a separate re-export (issue #4117) so the large alphabetized group
// above stays byte-identical and rustfmt-stable.
diff --git a/crates/openhuman-core/src/config/schema/load_env_overlay_context_tests.rs b/crates/openhuman-core/src/config/schema/load_env_overlay_context_tests.rs
index 1eb0b30b9e..a46170761b 100644
--- a/crates/openhuman-core/src/config/schema/load_env_overlay_context_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load_env_overlay_context_tests.rs
@@ -142,3 +142,17 @@ fn compaction_strategy_reads_from_toml() {
let cfg: crate::config::ContextConfig = toml::from_str("").unwrap();
assert_eq!(cfg.compaction_strategy, CompactionStrategy::TaskState);
}
+
+#[test]
+fn compaction_settings_bundle_the_trigger_and_strategy() {
+ use crate::config::{CompactionSettings, CompactionStrategy, ContextConfig};
+ let mut cfg = ContextConfig::default();
+ assert_eq!(cfg.compaction_settings(), CompactionSettings::default());
+ cfg.compaction_trigger_tokens = Some(0);
+ cfg.compaction_strategy = CompactionStrategy::Summary;
+ let settings = cfg.compaction_settings();
+ assert_eq!(settings.trigger_tokens, None, "a 0 trigger is no override");
+ assert_eq!(settings.strategy, CompactionStrategy::Summary);
+ cfg.compaction_trigger_tokens = Some(64_000);
+ assert_eq!(cfg.compaction_settings().trigger_tokens, Some(64_000));
+}