diff --git a/src/pipecat/services/ai_service.py b/src/pipecat/services/ai_service.py index 759efcf00..f4510386d 100644 --- a/src/pipecat/services/ai_service.py +++ b/src/pipecat/services/ai_service.py @@ -152,6 +152,9 @@ class AIService(FrameProcessor): elif isinstance(frame, CancelFrame): await self.cancel(frame) elif isinstance(frame, EndFrame): + # Push EndFrame before stop(), because stop() may wait on tasks to + # finish and downstream processors need to receive the EndFrame. + await self.push_frame(frame, direction) await self.stop(frame) async def process_generator(self, generator: AsyncGenerator[Frame | None, None]):