diff --git a/crates/goose/src/agents/moim.rs b/crates/goose/src/agents/moim.rs index ab8b99d2f..dcb9aa4f9 100644 --- a/crates/goose/src/agents/moim.rs +++ b/crates/goose/src/agents/moim.rs @@ -11,7 +11,6 @@ Each turn may include a `<{turn_context_tag}>` block added to the request. This block is generated by goose and contains current operational context such as: - current time - working directory -- compaction status - turn budget - extension-provided context @@ -41,7 +40,6 @@ pub async fn turn_context_message( turns_taken: u32, max_turns: u32, turn_start: chrono::DateTime, - compaction_info: Option, ) -> Option { if SKIP.with(|f| f.get()) { return None; @@ -85,7 +83,6 @@ pub async fn turn_context_message( .or_else(|| session.as_ref().map(|session| session.working_dir.clone())) .unwrap_or_else(|| PathBuf::from(".")); let mut parts = lease.moim().await; - parts.extend(compaction_info.map(|value| tag("compaction", &value))); parts.extend(turn_budget_part(turns_taken, max_turns)); turn_context_event(&working_dir, context_limit, parts, turn_start) } @@ -248,10 +245,9 @@ mod tests { let (session_id, em, _tmp) = session_and_manager().await; let lease = em.current_lease(&session_id).await.unwrap(); - let message = - turn_context_message(&session_id, &em, &lease, 0, 100, chrono::Local::now(), None) - .await - .expect("turn context should be produced"); + let message = turn_context_message(&session_id, &em, &lease, 0, 100, chrono::Local::now()) + .await + .expect("turn context should be produced"); assert_eq!(message.role, rmcp::model::Role::User); assert!(message.is_agent_visible()); @@ -268,10 +264,10 @@ mod tests { let lease = em.current_lease(&session_id).await.unwrap(); let turn_start = chrono::Local::now(); - let first = turn_context_message(&session_id, &em, &lease, 0, 100, turn_start, None) + let first = turn_context_message(&session_id, &em, &lease, 0, 100, turn_start) .await .unwrap(); - let second = turn_context_message(&session_id, &em, &lease, 0, 100, turn_start, None) + let second = turn_context_message(&session_id, &em, &lease, 0, 100, turn_start) .await .unwrap(); @@ -301,10 +297,9 @@ mod tests { ) .await; - let message = - turn_context_message(&session_id, &em, &lease, 0, 100, chrono::Local::now(), None) - .await - .unwrap(); + let message = turn_context_message(&session_id, &em, &lease, 0, 100, chrono::Local::now()) + .await + .unwrap(); let text = message.content[0].as_text().unwrap(); assert!(text.contains("old context")); @@ -319,10 +314,9 @@ mod tests { .resolve(&ExtensionSet::new(&session_id, Some(leased_working_dir), vec![]).unwrap()) .await; - let message = - turn_context_message(&session_id, &em, &lease, 0, 100, chrono::Local::now(), None) - .await - .unwrap(); + let message = turn_context_message(&session_id, &em, &lease, 0, 100, chrono::Local::now()) + .await + .unwrap(); let text = message.content[0].as_text().unwrap(); assert!(text.contains("/leased/dir")); diff --git a/crates/goose/src/agents/snapshots/goose__agents__prompt_manager__tests__all_platform_extensions.snap b/crates/goose/src/agents/snapshots/goose__agents__prompt_manager__tests__all_platform_extensions.snap index 154eb54dc..cdd985cf4 100644 --- a/crates/goose/src/agents/snapshots/goose__agents__prompt_manager__tests__all_platform_extensions.snap +++ b/crates/goose/src/agents/snapshots/goose__agents__prompt_manager__tests__all_platform_extensions.snap @@ -11,7 +11,6 @@ Each turn may include a `` block added to the request. This block is generated by goose and contains current operational context such as: - current time - working directory -- compaction status - turn budget - extension-provided context diff --git a/crates/goose/src/agents/snapshots/goose__agents__prompt_manager__tests__basic.snap b/crates/goose/src/agents/snapshots/goose__agents__prompt_manager__tests__basic.snap index 494d32289..b9d279e13 100644 --- a/crates/goose/src/agents/snapshots/goose__agents__prompt_manager__tests__basic.snap +++ b/crates/goose/src/agents/snapshots/goose__agents__prompt_manager__tests__basic.snap @@ -12,7 +12,6 @@ Each turn may include a `` block added to the request. This block is generated by goose and contains current operational context such as: - current time - working directory -- compaction status - turn budget - extension-provided context diff --git a/crates/goose/src/agents/snapshots/goose__agents__prompt_manager__tests__one_extension.snap b/crates/goose/src/agents/snapshots/goose__agents__prompt_manager__tests__one_extension.snap index f81e7549a..4116a456c 100644 --- a/crates/goose/src/agents/snapshots/goose__agents__prompt_manager__tests__one_extension.snap +++ b/crates/goose/src/agents/snapshots/goose__agents__prompt_manager__tests__one_extension.snap @@ -12,7 +12,6 @@ Each turn may include a `` block added to the request. This block is generated by goose and contains current operational context such as: - current time - working directory -- compaction status - turn budget - extension-provided context diff --git a/crates/goose/src/agents/snapshots/goose__agents__prompt_manager__tests__typical_setup.snap b/crates/goose/src/agents/snapshots/goose__agents__prompt_manager__tests__typical_setup.snap index 20c70bdeb..182404d91 100644 --- a/crates/goose/src/agents/snapshots/goose__agents__prompt_manager__tests__typical_setup.snap +++ b/crates/goose/src/agents/snapshots/goose__agents__prompt_manager__tests__typical_setup.snap @@ -12,7 +12,6 @@ Each turn may include a `` block added to the request. This block is generated by goose and contains current operational context such as: - current time - working directory -- compaction status - turn budget - extension-provided context diff --git a/crates/goose/src/agents/state_machine/ops_compaction.rs b/crates/goose/src/agents/state_machine/ops_compaction.rs index f9be0d60d..0b06b4f10 100644 --- a/crates/goose/src/agents/state_machine/ops_compaction.rs +++ b/crates/goose/src/agents/state_machine/ops_compaction.rs @@ -23,27 +23,6 @@ const COMPACTION_THINKING_TEXT: &str = "goose is compacting the conversation..." pub(super) const MAX_CONTEXT_ERROR_COMPACTIONS: usize = 2; -fn compaction_part( - total_tokens: Option, - context_limit: usize, - threshold: f64, -) -> Option { - let total_tokens = total_tokens?; - if total_tokens <= 0 || context_limit == 0 || threshold <= 0.0 || threshold >= 1.0 { - return None; - } - - let compaction_at = (context_limit as f64 * threshold) as i32; - if compaction_at <= 0 || (total_tokens as f64 / compaction_at as f64) < 0.5 { - return None; - } - - Some(format!( - "~{}k tokens remaining", - compaction_at.saturating_sub(total_tokens) / 1000 - )) -} - /// Reported usage stops at the inference that requested the tools, so the /// results that answered it are not counted until the next request. async fn unreported_tool_tokens(conversation: &Conversation) -> Result { @@ -210,23 +189,6 @@ impl Operation for CompactionOperation { ]) } - async fn moim_parts( - &self, - session: &Session, - conversation: &Conversation, - ) -> Result> { - if self.manages_own_context { - return Ok(Vec::new()); - } - Ok(compaction_part( - Some(self.context_tokens(session, conversation).await?), - self.context_limit, - self.threshold, - ) - .into_iter() - .collect()) - } - async fn run( &self, session: &Session, diff --git a/crates/goose/src/agents/state_machine/tests/compaction_lifecycle.rs b/crates/goose/src/agents/state_machine/tests/compaction_lifecycle.rs index 7f326ae20..7cdbb8f1d 100644 --- a/crates/goose/src/agents/state_machine/tests/compaction_lifecycle.rs +++ b/crates/goose/src/agents/state_machine/tests/compaction_lifecycle.rs @@ -31,7 +31,15 @@ async fn proactive_and_manual_compaction_continue_with_replaced_usage() -> Resul pipeline.run([half_full.as_str()]).await?; let budget = pipeline.run(["check the budget"]).await?; budget.assert_message(-1, Agent, "budget checked"); - assert!(api.calls().last().unwrap().input_contains("")); + assert!(!api.calls().last().unwrap().input_contains("")); + + pipeline + .set_total_tokens((pipeline.context_limit() as f64 * 0.79) as i32) + .await; + let near_threshold = pipeline.run(["check the budget"]).await?; + near_threshold.assert_message(-1, Agent, "budget checked"); + assert_eq!(near_threshold.history_replacements(), 0); + assert!(!api.calls().last().unwrap().input_contains("")); let filled_usage = (pipeline.context_limit() as f64 * 0.81) as i32; pipeline.set_total_tokens(filled_usage).await;