From ad2e1ba91633d3ffcc8a248d24f733580e64661f Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 28 May 2026 06:40:29 +0000 Subject: [PATCH] chore(compact_20260112): non-greedy summary regex; use COMPACT_EDIT_TYPE in bedrock filter - Make _SUMMARY_TAG_RE non-greedy so a response with multiple blocks captures only the first complete block. - Replace the hardcoded 'compact_20260112' literal in _filter_context_management_for_bedrock_converse with the shared COMPACT_EDIT_TYPE constant. --- .../context_management/editors/compact.py | 2 +- litellm/llms/bedrock/chat/converse_transformation.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/litellm/llms/anthropic/experimental_pass_through/context_management/editors/compact.py b/litellm/llms/anthropic/experimental_pass_through/context_management/editors/compact.py index c4b0315eac8..e942633aedc 100644 --- a/litellm/llms/anthropic/experimental_pass_through/context_management/editors/compact.py +++ b/litellm/llms/anthropic/experimental_pass_through/context_management/editors/compact.py @@ -52,7 +52,7 @@ _PROPAGATED_METADATA_KEYS = ( "litellm_parent_otel_span", ) -_SUMMARY_TAG_RE = re.compile(r"(.*)", re.IGNORECASE | re.DOTALL) +_SUMMARY_TAG_RE = re.compile(r"(.*?)", re.IGNORECASE | re.DOTALL) def _read_summary_model_setting() -> Optional[str]: diff --git a/litellm/llms/bedrock/chat/converse_transformation.py b/litellm/llms/bedrock/chat/converse_transformation.py index 0bd2abaf4b3..7d7d2307c49 100644 --- a/litellm/llms/bedrock/chat/converse_transformation.py +++ b/litellm/llms/bedrock/chat/converse_transformation.py @@ -1477,6 +1477,9 @@ class AmazonConverseConfig(BaseConfig): anthropic_beta_list: list, ) -> None: """Keep only compact_20260112 edits for Bedrock; add beta header or drop field.""" + from litellm.llms.anthropic.experimental_pass_through.context_management.constants import ( + COMPACT_EDIT_TYPE, + ) from litellm.types.llms.anthropic import ANTHROPIC_BETA_HEADER_VALUES cm = additional_request_params.get("context_management") @@ -1491,7 +1494,7 @@ class AmazonConverseConfig(BaseConfig): compact_edits = [ e for e in edits - if isinstance(e, dict) and e.get("type") == "compact_20260112" + if isinstance(e, dict) and e.get("type") == COMPACT_EDIT_TYPE ] if compact_edits: compact_beta = ANTHROPIC_BETA_HEADER_VALUES.COMPACT_2026_01_12.value