From b489e52080a103ad48953c78b8d506cf1c8c9d33 Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Fri, 30 May 2025 15:20:42 -0400 Subject: [PATCH] Add InterruptionConfig --- src/pipecat/frames/frames.py | 15 +++++++++++++++ src/pipecat/pipeline/task.py | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/src/pipecat/frames/frames.py b/src/pipecat/frames/frames.py index b24ff7b19..bd92fb400 100644 --- a/src/pipecat/frames/frames.py +++ b/src/pipecat/frames/frames.py @@ -438,6 +438,20 @@ class OutputDTMFFrame(DTMFFrame, DataFrame): # +@dataclass +class InterruptionConfig: + """Configuration for interruption behavior. + + When specified, the bot will not be interrupted immediately when the user speaks. + Instead, interruption will only occur when the configured conditions are met. + + Args: + min_words: If set, user must speak at least this many words to interrupt + """ + + min_words: Optional[int] = None + + @dataclass class StartFrame(SystemFrame): """This is the first frame that should be pushed down a pipeline.""" @@ -448,6 +462,7 @@ class StartFrame(SystemFrame): enable_metrics: bool = False enable_usage_metrics: bool = False report_only_initial_ttfb: bool = False + interruption_config: Optional[InterruptionConfig] = None @dataclass diff --git a/src/pipecat/pipeline/task.py b/src/pipecat/pipeline/task.py index 0fe330655..0647d1c02 100644 --- a/src/pipecat/pipeline/task.py +++ b/src/pipecat/pipeline/task.py @@ -22,6 +22,7 @@ from pipecat.frames.frames import ( ErrorFrame, Frame, HeartbeatFrame, + InterruptionConfig, LLMFullResponseEndFrame, MetricsFrame, StartFrame, @@ -58,6 +59,7 @@ class PipelineParams(BaseModel): report_only_initial_ttfb: Whether to report only initial time to first byte. send_initial_empty_metrics: Whether to send initial empty metrics. start_metadata: Additional metadata for pipeline start. + interruption_config: Configuration for bot interruption behavior. """ model_config = ConfigDict(arbitrary_types_allowed=True) @@ -73,6 +75,7 @@ class PipelineParams(BaseModel): report_only_initial_ttfb: bool = False send_initial_empty_metrics: bool = True start_metadata: Dict[str, Any] = Field(default_factory=dict) + interruption_config: Optional[InterruptionConfig] = None class PipelineTaskSource(FrameProcessor): @@ -518,6 +521,7 @@ class PipelineTask(BaseTask): enable_metrics=self._params.enable_metrics, enable_usage_metrics=self._params.enable_usage_metrics, report_only_initial_ttfb=self._params.report_only_initial_ttfb, + interruption_config=self._params.interruption_config, ) start_frame.metadata = self._params.start_metadata await self._source.queue_frame(start_frame, FrameDirection.DOWNSTREAM)