diff --git a/src/pipecat/services/anthropic/llm.py b/src/pipecat/services/anthropic/llm.py index 15c4cebee..fadf17f16 100644 --- a/src/pipecat/services/anthropic/llm.py +++ b/src/pipecat/services/anthropic/llm.py @@ -448,14 +448,16 @@ class AnthropicLLMContext(OpenAILLMContext): system: System message content. """ super().__init__(messages=messages, tools=tools, tool_choice=tool_choice) + self.__setup_local() + self.system = system + def __setup_local(self): # For beta prompt caching. This is a counter that tracks the number of turns # we've seen above the cache threshold. We reset this when we reset the # messages list. We only care about this number being 0, 1, or 2. But # it's easiest just to treat it as a counter. self.turns_above_cache_threshold = 0 - - self.system = system + return @staticmethod def upgrade_to_anthropic(obj: OpenAILLMContext) -> "AnthropicLLMContext": @@ -472,6 +474,7 @@ class AnthropicLLMContext(OpenAILLMContext): logger.debug(f"Upgrading to Anthropic: {obj}") if isinstance(obj, OpenAILLMContext) and not isinstance(obj, AnthropicLLMContext): obj.__class__ = AnthropicLLMContext + obj.__setup_local() obj._restructure_from_openai_messages() return obj