From b021540c588f60f8c771959caa9cfd2082d2b7d3 Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Tue, 11 Nov 2025 15:30:52 -0300 Subject: [PATCH] feat(automation): limit compact prompt history to recent messages Modified compact_prompt_for_bot to only include the most recent N messages (messages_since_summary + 1) when building the compacted prompt string. This prevents excessive context from being included and improves performance by --- src/automation/compact_prompt.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/automation/compact_prompt.rs b/src/automation/compact_prompt.rs index bdcf2adc..7da65060 100644 --- a/src/automation/compact_prompt.rs +++ b/src/automation/compact_prompt.rs @@ -123,7 +123,11 @@ async fn compact_prompt_for_bot( messages_since_summary ); let mut compacted = String::new(); - for (role, content) in &history { + let messages_to_include = history.iter() + .skip(history.len().saturating_sub(messages_since_summary )) + .take(messages_since_summary + 1); + + for (role, content) in messages_to_include { compacted.push_str(&format!("{}: {}\n", role, content)); } let llm_provider = state.llm_provider.clone();