fix(anthropic): resolve mypy types in context management polyfill

Use AppliedEdit and CompactionBlock consistently in the dispatcher and streaming adapter.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Sameer Kankute 2026-05-27 19:28:34 +05:30
parent 8551e939d5
commit 88ec260771
No known key found for this signature in database
2 changed files with 5 additions and 3 deletions

View file

@ -18,6 +18,7 @@ from litellm._logging import verbose_logger
from litellm._uuid import uuid
from litellm.types.llms.anthropic import (
AppliedEdit,
CompactionBlock,
ContextManagementResponse,
UsageDelta,
UsageIteration,
@ -62,7 +63,7 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper):
model: str,
tool_name_mapping: Optional[Dict[str, str]] = None,
applied_edits: Optional[List[AppliedEdit]] = None,
compaction_block: Optional[Dict[str, Any]] = None,
compaction_block: Optional[CompactionBlock] = None,
iterations_usage: Optional[List[UsageIteration]] = None,
):
super().__init__(completion_stream)

View file

@ -4,6 +4,7 @@ import inspect
from typing import Any, Awaitable, Callable, Dict, List, Optional, Tuple, Union, cast
from litellm._logging import verbose_logger
from litellm.types.llms.anthropic import AppliedEdit
from .constants import CLEAR_TOOL_USES_EDIT_TYPE, COMPACT_EDIT_TYPE
from .editors import apply_clear_tool_uses_20250919, apply_compact_20260112
@ -75,7 +76,7 @@ async def apply_context_management(
current_messages = messages
current_system = system
aggregated_applied: List[Dict[str, Any]] = []
aggregated_applied: List[AppliedEdit] = []
aggregated_compaction_block = None
aggregated_iterations_usage = None
@ -118,7 +119,7 @@ async def apply_context_management(
return PolyfillResult(
messages=current_messages,
system=current_system,
applied_edits=cast(List[Any], aggregated_applied),
applied_edits=aggregated_applied,
compaction_block=aggregated_compaction_block,
iterations_usage=aggregated_iterations_usage,
)