diff --git a/aider/history.py b/aider/history.py index 4a1e2ca3d..283ca34ed 100644 --- a/aider/history.py +++ b/aider/history.py @@ -48,6 +48,10 @@ class ChatSummary: else: break + # Ensure the head ends with an assistant message + while messages[split_index - 1]["role"] != "assistant" and split_index < len(messages): + split_index += 1 + head = messages[:split_index] tail = messages[split_index:]