base_user_turn_stop_strategy
Base user turn stop strategy for determining when the user stopped speaking.
- class pipecat.turns.user_stop.base_user_turn_stop_strategy.UserTurnStoppedParams(enable_user_speaking_frames: bool, confirms_speculation: bool = False)[source]
Bases:
objectParameters emitted when a user turn stops.
These parameters are passed to the on_user_turn_stopped event and provide contextual information about how the end of user turn should be handled by the user aggregator.
- Parameters:
enable_user_speaking_frames – Whether to emit
UserStoppedSpeakingFramefor this turn. False when the turn end was already announced elsewhere — by a sharedUserTurnProcessor, or by a service that emits turn frames rather than proposing them.confirms_speculation – Whether this turn end confirms a speculative response that was already generated. The aggregator then writes the turn to the context without running inference again, since the answer is already on its way.
- class pipecat.turns.user_stop.base_user_turn_stop_strategy.BaseUserTurnStopStrategy(*, enable_user_speaking_frames: bool | None = None, **kwargs)[source]
Bases:
BaseObjectBase class for strategies that determine when the user stops speaking.
Subclasses should implement logic to detect when the user stops speaking. This could be based on analyzing incoming frames (such as transcriptions), conversation state, or other heuristics.
Events triggered by strategies:
on_push_frame: Indicates the strategy wants to push a frame.
on_broadcast_frame: Indicates the strategy wants to broadcast a frame.
on_user_turn_stopped: Reports the strategy’s decision that the user is done, from
report_user_turn_stopped(). The turn controller combines the stop strategies’ decisions into the turn end.on_user_turn_inference_triggered: Starts a speculative inference for a turn that hasn’t ended yet, carrying a
UserTurnSpeculation, fromstart_user_turn_speculation().on_user_turn_speculation_cancelled: Withdraws that speculation, from
cancel_user_turn_speculation().
- __init__(*, enable_user_speaking_frames: bool | None = None, **kwargs)[source]
Initialize the base user turn stop strategy.
- Parameters:
enable_user_speaking_frames –
Whether to emit
UserStoppedSpeakingFramewhen a turn ends, unlessreport_user_turn_stopped()overrides it for a given turn.Deprecated since version 1.8.0: Use
report_user_turn_stopped()’senable_user_speaking_framesargument instead. Will be removed in 2.0.0.**kwargs – Additional keyword arguments.
- property resolves_proposed_turn_stop_frames: bool
Whether this strategy resolves proposals into turn stops.
A
ProposedUserStoppedSpeakingFrameis a request for a decision, so a strategy that acts on one consumes it: the frame stops travelling, and no resolver further along decides the same turn a second time. Override to True in a strategy that handles that frame — including one that holds the proposal for a while before deciding.
- property waits_for_inference: bool
Whether this strategy waits for the turn’s inference before deciding.
In a
StrategyMode.ALLlist, the turn’s inference runs once every other stop strategy has decided, and this strategy then decides on it. Override to True in a strategy that decides from the turn’s answer, such as one reading the LLM’s turn-completion marker.
- property decision_scheduled: bool
Whether this strategy has a decision of its own scheduled.
While a stop strategy has one, the turn controller’s stop timeout waits for it instead of ending the turn. Override to return True only while the strategy is sure to decide soon on its own, as when a timer of its own will fire, so a turn whose decision never comes still times out.
- async setup(setup: FrameProcessorSetup)[source]
Set up the strategy.
- Parameters:
setup – Configuration object containing setup parameters.
- async reset()[source]
Reset the strategy to its initial state.
Deprecated since version 1.6.0: Use
handle_user_turn_started()andhandle_user_turn_stopped()instead. Will be removed in 2.0.0.A stop strategy is reset at both turn boundaries — armed on start, cleaned up on stop — so this historically ran at both. New strategies should override the boundary callbacks directly, which say plainly when the work runs, and reset however they like inside them (a private helper called from both, an extra
clear()on stop, and so on).
- async handle_user_turn_started()[source]
Notify the strategy that a user turn has started.
The controller calls this on every stop strategy when a turn begins. Override to run, for example, logic to arm the strategy to detect the end of the turn now in progress.
- async handle_user_turn_stopped()[source]
Notify the strategy that the user turn has stopped.
The controller calls this on every stop strategy when a turn ends, regardless of which strategy (or the stop watchdog timeout) ended it. Override to run stop-specific logic — e.g. dropping a turn analyzer’s buffered speech that must not survive an externally-ended turn.
- async process_frame(frame: Frame) ProcessFrameResult | None[source]
Process an incoming frame to decide whether the user stopped speaking.
Subclasses should override this to implement logic that decides whether the user has stopped speaking.
- Parameters:
frame – The frame to be analyzed.
- Returns:
Nothing. A returned
ProcessFrameResultis deprecated:STOPkeeps the strategies after this one from seeing the frame, and only in aStrategyMode.FIRSTlist.
- async push_frame(frame: Frame, direction: FrameDirection = FrameDirection.DOWNSTREAM)[source]
Emit on_push_frame to push a frame using the user aggreagtor.
- Parameters:
frame – The frame to be pushed.
direction – What direction the frame should be pushed to.
- async broadcast_frame(frame_cls: type[Frame], **kwargs)[source]
Emit on_broadcast_frame to broadcast a frame using the user aggreagtor.
- Parameters:
frame_cls – The class of the frame to be broadcasted.
**kwargs – Keyword arguments to be passed to the frame’s constructor.
- async cancel_user_turn_speculation()[source]
Withdraw the speculation this strategy has in flight.
Emitted rather than pushed so the host broadcasts it the same way it broadcasts the turn end. A withdrawal that took the queued path would reach a downstream gate after the turn end that follows it, and the gate would release the response the withdrawal was meant to discard.
- async report_user_turn_stopped(*, enable_user_speaking_frames: bool | None = None, confirms_speculation: bool = False)[source]
Report that the user is done, by firing
on_user_turn_stopped.A strategy calls this when it decides the user’s turn has ended. The controller combines the stop strategies’ decisions into the turn end, and runs the turn’s inference itself once they have decided.
- Parameters:
enable_user_speaking_frames – Whether to emit
UserStoppedSpeakingFramefor this turn. Pass False when something else in the pipeline has already emitted it.confirms_speculation – Whether a response generated ahead of this turn ending already answers it, so inference should not run again.
- async start_user_turn_speculation(speculation: UserTurnSpeculation)[source]
Start a speculative inference, by firing
on_user_turn_inference_triggered.The controller runs a turn’s inference itself once the stop strategies have decided, so a strategy only calls this to answer ahead of that, as an eager end of turn does.
- Parameters:
speculation – The speculation to run, against a provisional context carrying the turn text it names, for a turn that hasn’t ended yet. The speculation gate keeps its response back until the turn is confirmed.
- async trigger_user_turn_speculation_cancelled()[source]
Withdraw the speculation this strategy has in flight.
Deprecated since version 1.15.0: Use
cancel_user_turn_speculation()instead. Will be removed in 2.0.0.
- async trigger_user_turn_stopped(*, enable_user_speaking_frames: bool | None = None)[source]
Report that the user is done.
Deprecated since version 1.15.0: Use
report_user_turn_stopped()instead. Will be removed in 2.0.0.- Parameters:
enable_user_speaking_frames – Whether to emit
UserStoppedSpeakingFramefor this turn. Pass False when something else in the pipeline has already emitted it.
- async trigger_user_turn_inference_triggered(*, speculation: UserTurnSpeculation | None = None)[source]
Start a speculative inference.
Deprecated since version 1.15.0: Use
start_user_turn_speculation()instead. Will be removed in 2.0.0.- Parameters:
speculation – The speculation to run. A call without one is ignored, with a warning the first time, since the turn controller runs the turn’s inference itself.
- async trigger_user_turn_finalized(*, enable_user_speaking_frames: bool | None = None, confirms_speculation: bool = False)[source]
Fire only
on_user_turn_stopped.Deprecated since version 1.15.0: Use
report_user_turn_stopped()instead, which fires the same event. Will be removed in 2.0.0.- Parameters:
enable_user_speaking_frames – Whether to emit
UserStoppedSpeakingFramefor this turn. Pass False when something else in the pipeline has already emitted it.confirms_speculation – Whether a response generated ahead of this turn ending already answers it, so inference should not run again.