user_turn_strategies
Turn start strategy configuration.
- class pipecat.turns.user_turn_strategies.MergeMode(*values)[source]
Bases:
EnumHow a bot’s list of user turn strategies combines with a service’s.
- Parameters:
EXTEND – The strategies the bot gave are added to the service’s list, or to the defaults when no service recommends any.
REPLACE – The bot’s list is used on its own.
- EXTEND = 'extend'
- REPLACE = 'replace'
- class pipecat.turns.user_turn_strategies.StrategyMode(*values)[source]
Bases:
EnumHow a list of user turn strategies reaches a decision.
- Parameters:
ALL – Every strategy has to agree, and each one sees every frame.
FIRST – The first strategy to decide wins.
- ALL = 'all'
- FIRST = 'first'
- class pipecat.turns.user_turn_strategies.UserTurnStrategiesParams(*, start_merge_mode: MergeMode = MergeMode.REPLACE, stop_merge_mode: MergeMode = MergeMode.REPLACE, start_mode: StrategyMode = StrategyMode.FIRST, stop_mode: StrategyMode = StrategyMode.ALL)[source]
Bases:
BaseModelHow the user turn strategies combine with a service’s and decide.
A service with its own turn detection, such as an STT service, can recommend user turn strategies. Only the bot sets these parameters: a service’s recommendation contributes its lists.
- Parameters:
start_merge_mode – How the bot’s start strategies combine with the ones a service recommends. Defaults to
MergeMode.REPLACE.stop_merge_mode – How the bot’s stop strategies combine with the ones a service recommends. Defaults to
MergeMode.REPLACE.start_mode – Whether the turn starts on the first start strategy that decides the user started, or once every start strategy has. Defaults to
StrategyMode.FIRST, so speech or a transcript starts a turn on its own. In aStrategyMode.ALLlist every strategy is a condition the turn needs, so a fallback such asTranscriptionUserTurnStartStrategy, which starts a turn when VAD misses speech, belongs in aStrategyMode.FIRSTlist.stop_mode – Whether the turn ends once every stop strategy has decided the user is done, or on the first one that does. A stop strategy that waits for the turn’s inference, such as
LLMTurnCompletionUserTurnStopStrategy, decides on it in either mode. The user speaking again clears the decisions made so far. Defaults toStrategyMode.ALL.
- class pipecat.turns.user_turn_strategies.UserTurnStrategies(start: list[BaseUserTurnStartStrategy] | None = None, stop: list[BaseUserTurnStopStrategy] | None = None)[source]
Bases:
objectContainer for user turn start and stop strategies.
If no strategies are specified, the following defaults are used:
- start: [VADUserTurnStartStrategy, TranscriptionUserTurnStartStrategy]
stop: [TurnAnalyzerUserTurnStopStrategy(LocalSmartTurnAnalyzerV3)]
A bot’s strategies replace the ones a service recommends, unless
UserTurnStrategiesParamsextends a list.- Parameters:
start – A list of user turn start strategies used to detect when the user starts speaking.
stop – A list of user turn stop strategies used to decide when the user stops speaking.
- start: list[BaseUserTurnStartStrategy] | None = None
- stop: list[BaseUserTurnStopStrategy] | None = None
- merge_with(recommended: UserTurnStrategies | None, params: UserTurnStrategiesParams) UserTurnStrategies[source]
Combine these strategies with the ones a service recommends.
- Parameters:
recommended – The strategies a service recommends, or None when no service recommends any, in which case the defaults stand in.
params – How each list combines with the service’s.
- Returns:
The strategies to run.
- class pipecat.turns.user_turn_strategies.ExternalUserTurnStrategies(start: list[BaseUserTurnStartStrategy] | None = None, stop: list[BaseUserTurnStopStrategy] | None = None, enable_interruptions: bool = True)[source]
Bases:
UserTurnStrategiesContainer for turn strategies driven by another component in the pipeline.
Preconfigures
UserTurnStrategieswithExternalUserTurnStartStrategyandExternalUserTurnStopStrategy, so a service with its own turn detection — or a sharedUserTurnProcessor— controls when user turns start and stop.What the aggregator emits depends on which signal drives the turn.
ProposedUserStarted/StoppedSpeakingFrameleaves the decision here, so the aggregator pushes the turn frames and broadcasts interruptions.UserStarted/StoppedSpeakingFramemeans the emitter already announced the turn, so the aggregator emits nothing and the parameter below doesn’t apply.- Parameters:
enable_interruptions – Whether to broadcast an interruption when a proposal starts a turn. Services route their
should_interruptsetting here.
- class pipecat.turns.user_turn_strategies.FilterIncompleteUserTurnStrategies(start: list[BaseUserTurnStartStrategy] | None = None, stop: list[BaseUserTurnStopStrategy] | None = None, config: UserTurnCompletionConfig | None = None)[source]
Bases:
UserTurnStrategiesStop strategies gated on the LLM’s turn-completion verdict.
The LLM is asked to begin every response with one of three markers: ● (complete), ◐ (incomplete short), or ○ (incomplete long). Only ● finalizes the user turn; ◐ / ○ keep the turn open so the user can continue speaking and the LLM can re-evaluate later.
Configuring strategies this way keeps the stop strategies (defaults or user-supplied) and adds
LLMTurnCompletionUserTurnStopStrategy, which waits for the turn’s inference. Once the other stop strategies decide the user stopped, the inference runs, and the turn ends once the LLM marks it complete. This works with eitherstop_mode.With
UserTurnStrategiesParams(stop_merge_mode=MergeMode.EXTEND), the LLM gate and any stop strategies given join the ones a service recommends instead, such as an STT service’s own turn detection.- Parameters:
config – Optional configuration applied to the LLM via the
filter_incomplete_user_turnssetting. Customizes the turn-completion instructions, incomplete-turn timeouts, and re-prompts. If None, defaults fromUserTurnCompletionConfigare used.
Example:
user_turn_strategies=FilterIncompleteUserTurnStrategies() # Custom stop strategies: user_turn_strategies=FilterIncompleteUserTurnStrategies( stop=[SpeechTimeoutUserTurnStopStrategy(...)], ) # On top of the turn detection a service recommends: user_turn_strategies=FilterIncompleteUserTurnStrategies(), user_turn_strategies_params=UserTurnStrategiesParams( stop_merge_mode=MergeMode.EXTEND, ), # Custom completion config: user_turn_strategies=FilterIncompleteUserTurnStrategies( config=UserTurnCompletionConfig( incomplete_short_timeout=5.0, incomplete_long_timeout=10.0, ), )
- config: UserTurnCompletionConfig | None = None
- class pipecat.turns.user_turn_strategies.ClassifierUserTurnStrategies(start: list[BaseUserTurnStartStrategy] | None = None, stop: list[BaseUserTurnStopStrategy] | None = None, classifier: BaseClassifier | None = None, context: LLMContext | None = None, short_timeout: float = 5.0, long_timeout: float = 10.0, classification_timeout: float = 1.0)[source]
Bases:
UserTurnStrategiesStop strategies that let a classifier decide whether the user’s turn is complete.
An alternative to
FilterIncompleteUserTurnStrategiesfor an LLM that doesn’t follow the turn-completion marker instructions well. A classifier decides from the user’s words, and the bot’s last line, whether the user finished their thought, and the LLM only answers complete turns.ClassifierUserTurnStopStrategy, which asks at every pause with new words, is added after the stop strategies given, or after the default ones (smart turn) when none are given, and the turn ends once all of them have decided. Smart turn hears from how the user sounds that more is coming after words that read complete, such as “I want to go to Paris”, which the classifier can’t tell from the words. A turn the classifier found complete then waits for smart turn too, up to its silence fallback when smart turn finds it incomplete. For the classifier alone, build the stop list yourself:UserTurnStrategies(stop=[ClassifierUserTurnStopStrategy(classifier=..., context=context)])
With
UserTurnStrategiesParams(stop_merge_mode=MergeMode.EXTEND), the classifier strategy and any stop strategies given join the ones a service recommends instead.- Parameters:
classifier – What decides whether a turn is complete. Required.
context – The conversation, so the classifier sees the assistant’s last message along with the user’s turn.
short_timeout – Seconds to wait after a
shortverdict before the classifier strategy decides the user is done.long_timeout – Seconds to wait after a
longverdict before the classifier strategy decides the user is done.classification_timeout – Seconds to wait for the classifier before leaving the decision to the other stop strategies.
Example:
user_turn_strategies=ClassifierUserTurnStrategies( classifier=JevClassifier(api_key=os.getenv("TYPESAFE_API_KEY")), context=context, )
- classifier: BaseClassifier | None = None
- context: LLMContext | None = None
- class pipecat.turns.user_turn_strategies.EagerUserTurnStrategies(start: list[BaseUserTurnStartStrategy] | None = None, stop: list[BaseUserTurnStopStrategy] | None = None, enable_interruptions: bool = True, match_policy: EagerMatchPolicy | None = None, speculation_timeout: float = 5.0)[source]
Bases:
ExternalUserTurnStrategiesStrategies for a service that predicts the end of a turn before committing.
Answers the prediction while the turn is still open, so the gap before the committed end of turn is spent generating a response instead of waiting for one. The response is discarded if the user resumes speaking or the committed transcript differs from the eager one. See
EagerUserTurnStopStrategy.The response is held by the LLM service until the turn is confirmed, so no extra processor is needed in the pipeline.
The service owns turn detection here, so this replaces the detector chain rather than extending it: a local detector running alongside would trigger a second inference for the same turn.
- Parameters:
match_policy – Decides whether the committed transcript is close enough to the eager one to keep the speculative response. Defaults to
NormalizedMatch, since services commonly format the transcript they commit (capitalization, punctuation) while leaving the eager one raw. PassExactMatchto require the two to be identical.speculation_timeout – Seconds a prediction may go unresolved before it is withdrawn and the turn falls back to answering the committed transcript. Guards against a service that stops sending turn signals mid-speculation, which would otherwise leave the response held and the bot silent.
enable_interruptions – Whether to broadcast an interruption when a proposal starts a turn. Services route their
should_interruptsetting here.
Example:
user_turn_strategies=EagerUserTurnStrategies() # Require the committed transcript to match the eager one exactly: user_turn_strategies=EagerUserTurnStrategies(match_policy=ExactMatch())
- match_policy: EagerMatchPolicy | None = None
- pipecat.turns.user_turn_strategies.default_user_turn_start_strategies() list[BaseUserTurnStartStrategy][source]
Return the default user turn start strategies.
Returns
[VADUserTurnStartStrategy, TranscriptionUserTurnStartStrategy]. Useful when building a custom strategy list that extends the defaults.Example:
start_strategies = [ WakePhraseUserTurnStartStrategy(phrases=["hey pipecat"]), *default_user_turn_start_strategies(), ]
- pipecat.turns.user_turn_strategies.default_user_turn_stop_strategies() list[BaseUserTurnStopStrategy][source]
Return the default user turn stop strategies.
Returns
[TurnAnalyzerUserTurnStopStrategy(LocalSmartTurnAnalyzerV3)]. Useful when building a custom strategy list that extends the defaults.