From c437ff6a08c9715ceb08c5248696c8a70eb10394 Mon Sep 17 00:00:00 2001 From: Paul Kompfner Date: Thu, 24 Jul 2025 09:51:30 -0400 Subject: [PATCH] Progress on LLM failover support --- .../aggregators/llm_response_universal.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/pipecat/processors/aggregators/llm_response_universal.py b/src/pipecat/processors/aggregators/llm_response_universal.py index e072d0ee4..2d6f44feb 100644 --- a/src/pipecat/processors/aggregators/llm_response_universal.py +++ b/src/pipecat/processors/aggregators/llm_response_universal.py @@ -822,3 +822,53 @@ class LLMAssistantContextAggregator_Universal(LLMContextAggregator): # this because otherwise the task manager would report a dangling task # if we don't remove it. asyncio.run_coroutine_threadsafe(self.wait_for_task(task), self.get_event_loop()) + + +@dataclass +class LLMContextAggregatorPair: + """Pair of LLM context aggregators for user and assistant messages. + + Parameters: + _user: User context aggregator for processing user messages. + _assistant: Assistant context aggregator for processing assistant messages. + """ + + _user: LLMUserContextAggregator_Universal + _assistant: LLMAssistantContextAggregator_Universal + + @staticmethod + def create( + context: LLMContext, + *, + user_params: LLMUserContextAggregatorParams = LLMUserContextAggregatorParams(), + assistant_params: LLMAssistantContextAggregatorParams = LLMAssistantContextAggregatorParams(), + ) -> "LLMContextAggregatorPair": + """Factory method to create an LLMContextAggregatorPair. + + Args: + context: The context managed by the aggregators. + user_params: Parameters for the user context aggregator. + assistant_params: Parameters for the assistant context aggregator. + + Returns: + LLMContextAggregatorPair: A new instance with configured aggregators. + """ + user = LLMUserContextAggregator_Universal(context, params=user_params) + assistant = LLMAssistantContextAggregator_Universal(context, params=assistant_params) + return LLMContextAggregatorPair(_user=user, _assistant=assistant) + + def user(self) -> LLMUserContextAggregator_Universal: + """Get the user context aggregator. + + Returns: + The user context aggregator instance. + """ + return self._user + + def assistant(self) -> LLMAssistantContextAggregator_Universal: + """Get the assistant context aggregator. + + Returns: + The assistant context aggregator instance. + """ + return self._assistant