Skip to content

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

chore(agent): remove unused context manager and stats modules

Steven Enamakel5894bc672e4c
diff --git a/crates/openhuman-core/src/agent/context/manager.rs b/crates/openhuman-core/src/agent/context/manager.rs
index 107fa8cf34..97030c8a8d 100644
--- a/crates/openhuman-core/src/agent/context/manager.rs
+++ b/crates/openhuman-core/src/agent/context/manager.rs
@@ -11,23 +11,14 @@
//! [`ContextManager::build_system_prompt_with`].
//!
//! 2. **Context bookkeeping** — a [`ContextStatsState`] with utilisation
-//! stats, tool-result budget config, and session-memory trigger state.
+//! stats and tool-result budget config.
//! Live history reduction/summarization moved to the
//! tinyagents graph (`ContextCompressionMiddleware` +
//! `MessageTrimMiddleware`, issue #4249); this manager no longer runs
//! an in-turn summarizer.
//!
-//! # What it doesn't own
-//!
-//! The session-memory extraction *task itself* still lives in the
-//! agent harness (`turn.rs` spawns the archivist sub-agent). The
-//! manager only owns the *state* that decides whether the trigger
-//! should fire; it exposes that via
-//! [`ContextManager::should_extract_session_memory`] so `turn.rs` can
-//! gate its existing `spawn_subagent` call.
-use super::session_memory::SessionMemoryConfig;
-use super::stats::{ContextStatsState, SessionMemoryHandle};
+use super::stats::ContextStatsState;
use crate::agent::prompts::{PromptContext, SystemPromptBuilder};
use crate::config::ContextConfig;
use crate::inference::provider::BilledUsage;
@@ -42,9 +33,6 @@ pub struct ContextStats {
pub input_tokens: u64,
pub output_tokens: u64,
pub context_window: u64,
- pub session_memory_total_tokens: u64,
- pub session_memory_current_turn: u64,
- pub session_memory_total_tool_calls: u64,
}
/// Per-session context manager. Constructed once by the agent harness
@@ -97,15 +85,10 @@ impl ContextManager {
///
/// The manager no longer owns a summarizer: live history reduction moved
/// to the tinyagents graph (issue #4249). What remains here is the system
- /// prompt, the stats/utilisation surface, tool-result budgeting, and
- /// session-memory bookkeeping.
+ /// prompt, the stats/utilisation surface and tool-result budgeting.
pub fn new(config: &ContextConfig, default_prompt_builder: SystemPromptBuilder) -> Self {
Self {
- stats_state: ContextStatsState::new(SessionMemoryConfig {
- min_token_growth: config.session_memory.min_token_growth,
- min_tool_calls: config.session_memory.min_tool_calls,
- min_turns_between: config.session_memory.min_turns_between,
- }),
+ stats_state: ContextStatsState::new(),
default_prompt_builder,
enabled: config.enabled,
tool_result_budget_bytes: config.tool_result_budget_bytes,
@@ -170,47 +153,6 @@ impl ContextManager {
self.stats_state.tick_turn();
}
- /// Accumulate a turn's tool-call count into the session-memory state.
- pub fn record_tool_calls(&mut self, n: usize) {
- self.stats_state.record_tool_calls(n);
- }
-
- /// Whether the caller should spawn a background session-memory
- /// extraction this turn. Delegates to the underlying stats state; the
- /// manager does not spawn the extraction itself.
- pub fn should_extract_session_memory(&self) -> bool {
- self.stats_state.should_extract_session_memory()
- }
-
- /// Mark a session-memory extraction as started (so repeated
- /// calls to [`should_extract_session_memory`] return `false` until
- /// the extraction completes).
- pub fn mark_session_memory_started(&mut self) {
- self.stats_state.mark_session_memory_started();
- }
-
- /// Mark a session-memory extraction as complete — resets deltas.
- pub fn mark_session_memory_complete(&mut self) {
- self.stats_state.mark_session_memory_complete();
- }
-
- /// Mark a session-memory extraction as failed — keeps deltas
- /// intact so the next turn retries.
- pub fn mark_session_memory_failed(&mut self) {
- self.stats_state.mark_session_memory_failed();
- }
-
- /// Clone the shared session-memory handle so a detached background
- /// task (see `turn.rs::spawn_session_memory_extraction`) can mark
- /// the extraction complete or failed once it finishes. The
- /// foreground path is expected to call
- /// [`Self::mark_session_memory_started`] *before* spawning so
- /// overlapping turns don't fire duplicate extractions while this
- /// one is in flight.
- pub(crate) fn session_memory_handle(&self) -> SessionMemoryHandle {
- self.stats_state.session_memory_handle()
- }
-
// ─── Prompt building ───────────────────────────────────────────
/// Assemble the opening system prompt for a session using the
@@ -245,15 +187,11 @@ impl ContextManager {
/// Read-only snapshot of the current budget state.
pub fn stats(&self) -> ContextStats {
let utilisation_pct = self.stats_state.utilization_pct();
- let sm = self.stats_state.session_memory_snapshot();
ContextStats {
utilisation_pct,
input_tokens: self.stats_state.last_input_tokens(),
output_tokens: self.stats_state.last_output_tokens(),
context_window: self.stats_state.context_window(),
- session_memory_total_tokens: sm.total_tokens,
- session_memory_current_turn: sm.current_turn,
- session_memory_total_tool_calls: sm.total_tool_calls,
}
}
}
diff --git a/crates/openhuman-core/src/agent/context/stats.rs b/crates/openhuman-core/src/agent/context/stats.rs
index d73d2bdecb..a2ed335be8 100644
--- a/crates/openhuman-core/src/agent/context/stats.rs
+++ b/crates/openhuman-core/src/agent/context/stats.rs
@@ -1,39 +1,21 @@
-//! Context utilisation and session-memory state for [`ContextManager`].
+//! Context utilisation for [`ContextManager`].
//!
//! Live context reduction is owned by the TinyAgents middleware stack. This
//! module keeps only OpenHuman-specific bookkeeping: last provider usage,
-//! context-window utilisation for the UI/footer, and session-memory extraction
-//! trigger state.
-
-use std::sync::{Arc, Mutex};
+//! and context-window utilisation for the UI/footer.
use crate::inference::provider::BilledUsage;
-use super::session_memory::{SessionMemoryConfig, SessionMemoryState};
-
-/// Shared handle to a [`SessionMemoryState`] so a detached background archivist
-/// task can mark extraction complete/failed after the foreground turn releases
-/// its borrow.
-pub(crate) type SessionMemoryHandle = Arc<Mutex<SessionMemoryState>>;
-
-#[derive(Debug)]
+#[derive(Debug, Default)]
pub(crate) struct ContextStatsState {
last_input_tokens: u64,
last_output_tokens: u64,
context_window: u64,
- session_memory_config: SessionMemoryConfig,
- session_memory: SessionMemoryHandle,
}
impl ContextStatsState {
- pub(crate) fn new(session_memory_config: SessionMemoryConfig) -> Self {
- Self {
- last_input_tokens: 0,
- last_output_tokens: 0,
- context_window: 0,
- session_memory_config,
- session_memory: Arc::new(Mutex::new(SessionMemoryState::default())),
- }
+ pub(crate) fn new() -> Self {
+ Self::default()
}
pub(crate) fn record_usage(&mut self, usage: &BilledUsage) {
@@ -42,58 +24,6 @@ impl ContextStatsState {
if usage.context_window() > 0 {
self.context_window = usage.context_window();
}
- let total = usage.input_tokens + usage.output_tokens;
- if let Ok(mut sm) = self.session_memory.lock() {
- sm.record_usage(total);
- }
- }
-
- pub(crate) fn tick_turn(&mut self) {
- if let Ok(mut sm) = self.session_memory.lock() {
- sm.tick_turn();
- }
- }
-
- pub(crate) fn record_tool_calls(&mut self, n: usize) {
- if let Ok(mut sm) = self.session_memory.lock() {
- sm.record_tool_calls(n);
- }
- }
-
- pub(crate) fn should_extract_session_memory(&self) -> bool {
- self.session_memory
- .lock()
- .map(|sm| sm.should_extract(&self.session_memory_config))
- .unwrap_or(false)
- }
-
- pub(crate) fn mark_session_memory_started(&mut self) {
- if let Ok(mut sm) = self.session_memory.lock() {
- sm.mark_extraction_started();
- }
- }
-
- pub(crate) fn mark_session_memory_complete(&mut self) {
- if let Ok(mut sm) = self.session_memory.lock() {
- sm.mark_extraction_complete();
- }
- }
-
- pub(crate) fn mark_session_memory_failed(&mut self) {
- if let Ok(mut sm) = self.session_memory.lock() {
- sm.mark_extraction_failed();
- }
- }
-
- pub(crate) fn session_memory_snapshot(&self) -> SessionMemoryState {
- self.session_memory
- .lock()
- .map(|sm| sm.clone())
- .unwrap_or_default()
- }
-
- pub(crate) fn session_memory_handle(&self) -> SessionMemoryHandle {
- Arc::clone(&self.session_memory)
}
pub(crate) fn utilization_pct(&self) -> Option<u8> {