From 2c4d6cb3439c4434b7eec4c582800b2d750cc23d Mon Sep 17 00:00:00 2001 From: SwiftWinds <12981958+SwiftWinds@users.noreply.github.com> Date: Fri, 3 Apr 2026 16:48:16 -0700 Subject: [PATCH] fix: make it clearer to the llm that a compaction happened --- .../litellm_completion_transformation/handler.py | 1 - .../litellm_completion_transformation/transformation.py | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/litellm/responses/litellm_completion_transformation/handler.py b/litellm/responses/litellm_completion_transformation/handler.py index f07fb70d97b..63fd09e93a9 100644 --- a/litellm/responses/litellm_completion_transformation/handler.py +++ b/litellm/responses/litellm_completion_transformation/handler.py @@ -169,7 +169,6 @@ def _append_compaction_output( "type": "compaction", "id": "cmp_" + uuid.uuid4().hex, "encrypted_content": encoded_content, - "created_by": None, } if existing_output: return [existing_output[0], compaction_item] + list(existing_output[1:]) diff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.py index 1b765b6f422..81a79a75557 100644 --- a/litellm/responses/litellm_completion_transformation/transformation.py +++ b/litellm/responses/litellm_completion_transformation/transformation.py @@ -390,8 +390,13 @@ class LiteLLMCompletionResponsesConfig: else: decoded_content = compaction_item.get("content", "") messages.append( - ChatCompletionUserMessage( - role="user", content=decoded_content + ChatCompletionSystemMessage( + role="system", + content=( + "The following is a summary of the prior conversation history, " + "which was compacted to save context space. Treat this as established " + "context, not as a new user message:\n\n" + decoded_content + ), ) ) if last_compaction_idx > 0: