From a7c0bad857198c8a6752b003fd579357de00c80b Mon Sep 17 00:00:00 2001 From: cthomas Date: Mon, 8 Dec 2025 17:23:11 -0800 Subject: [PATCH] fix: unbound var in summarization [LET-6484] (#6568) * fix: unbound var in summarization * fix indentation --- letta/services/summarizer/summarizer_sliding_window.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/letta/services/summarizer/summarizer_sliding_window.py b/letta/services/summarizer/summarizer_sliding_window.py index 5fd77785..9f29f206 100644 --- a/letta/services/summarizer/summarizer_sliding_window.py +++ b/letta/services/summarizer/summarizer_sliding_window.py @@ -78,6 +78,7 @@ async def summarize_via_sliding_window( found_cutoff = False # Count tokens with system prompt, and message past cutoff point + assistant_message_index = None # Initialize to track if we found an assistant message while not found_cutoff: # Mark the approximate cutoff message_cutoff_index = round(message_count_cutoff_percent * len(all_in_context_messages)) @@ -110,6 +111,9 @@ async def summarize_via_sliding_window( # If we found the cutoff, summarize and return # If we didn't find the cutoff and we hit 100%, this is equivalent to complete summarization + if assistant_message_index is None: + raise ValueError("No assistant message found for sliding window summarization") # fall back to complete summarization + messages_to_summarize = all_in_context_messages[1:message_cutoff_index] summary_message_str = await simple_summary(