From 009b9fa2a59c1bf90b50e1c554b893eeadf2dc4a Mon Sep 17 00:00:00 2001 From: AlonSoko <25619863+AlonSoko@users.noreply.github.com> Date: Wed, 21 Oct 2026 22:01:47 +0300 Subject: [PATCH] fix(context_management): take read-only types in the system prompt count The type-discipline gate (LIT001) rejects new list and dict annotations. --- .../context_management/editors/clear_tool_uses.py | 8 ++++---- .../pass_through/context_management/editors/compact.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/litellm/llms/anthropic/pass_through/context_management/editors/clear_tool_uses.py b/litellm/llms/anthropic/pass_through/context_management/editors/clear_tool_uses.py index 929655835c2..495bd659c4f 100644 --- a/litellm/llms/anthropic/pass_through/context_management/editors/clear_tool_uses.py +++ b/litellm/llms/anthropic/pass_through/context_management/editors/clear_tool_uses.py @@ -197,11 +197,11 @@ def _select_in_batches(candidates: Sequence[str], tokens: Mapping[str, int], cle def _with_system( - messages: list[dict[str, object]], system: str | list[dict[str, object]] | None -) -> list[dict[str, object]]: + messages: Sequence[Mapping[str, object]], system: str | Sequence[Mapping[str, object]] | None +) -> Sequence[Mapping[str, object]]: """The messages to count: like the API, an ``input_tokens`` trigger counts the system prompt too.""" system_text: Final = system_to_text(system) - return [{"role": "system", "content": system_text}, *messages] if system_text else messages + return ({"role": "system", "content": system_text}, *messages) if system_text else messages def _trigger_met( @@ -209,7 +209,7 @@ def _trigger_met( model: str, messages: list[dict[str, object]], tools: list[dict[str, object]] | None, - system: str | list[dict[str, object]] | None, + system: str | Sequence[Mapping[str, object]] | None, counted_tool_uses: int, ) -> tuple[bool, int | None]: """Return (trigger_met, input_tokens if counted for reuse).""" diff --git a/litellm/llms/anthropic/pass_through/context_management/editors/compact.py b/litellm/llms/anthropic/pass_through/context_management/editors/compact.py index 1a67c28818e..5b9be56f4f8 100644 --- a/litellm/llms/anthropic/pass_through/context_management/editors/compact.py +++ b/litellm/llms/anthropic/pass_through/context_management/editors/compact.py @@ -327,7 +327,7 @@ def _count_effective_tokens( def system_to_text( - system: str | list[dict[str, object]] | None, + system: str | Sequence[Mapping[str, object]] | None, ) -> str: """Flatten an Anthropic-style ``system`` value into a single string for token counting. Returns ``""`` when ``system`` carries no text."""