From 986160c077196b3643b0d02f807f05b687a78735 Mon Sep 17 00:00:00 2001 From: Paul Kompfner Date: Wed, 3 Sep 2025 22:44:08 -0400 Subject: [PATCH] Fix a bug where the Anthropic adapter's merge-consecutive-messages-with-the-same-role logic was unintentionally affecting the source `LLMContext`'s messages, resulting in more and more duplication of text with each inference --- src/pipecat/adapters/services/anthropic_adapter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pipecat/adapters/services/anthropic_adapter.py b/src/pipecat/adapters/services/anthropic_adapter.py index e66118093..a32857d8a 100644 --- a/src/pipecat/adapters/services/anthropic_adapter.py +++ b/src/pipecat/adapters/services/anthropic_adapter.py @@ -168,7 +168,7 @@ class AnthropicLLMAdapter(BaseLLMAdapter[AnthropicLLMInvocationParams]): def _from_universal_context_message(self, message: LLMContextMessage) -> MessageParam: if isinstance(message, LLMSpecificMessage): - return message.message + return copy.deepcopy(message.message) return self._from_standard_message(message) def _from_standard_message(self, message: LLMStandardMessage) -> MessageParam: @@ -210,6 +210,7 @@ class AnthropicLLMAdapter(BaseLLMAdapter[AnthropicLLMInvocationParams]): ] } """ + message = copy.deepcopy(message) if message["role"] == "tool": return { "role": "user",