turns

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: BSD-2-Clause Imports: 21 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package turns manages the user-turn lifecycle, ported from Pipecat's turns subsystem. A UserTurnProcessor drives a UserTurnController (which runs pluggable start and stop strategies) and a UserIdleController. Turn detection is decoupled: voice activity comes from a vad.Processor upstream as VADUser*SpeakingFrames, and the end-of-turn model lives inside a stop strategy; the subsystem reasons over frames, not raw audio (except the turn-analyzer stop strategy, which is fed InputAudioRawFrames).

Index

Constants

View Source
const (
	// EventUserTurnStarted fires when a user turn starts, carrying the
	// StartStrategy that decided it began.
	//
	//	events.On(p.Events(), turns.EventUserTurnStarted,
	//	    func(ctx context.Context, s turns.StartStrategy) { … })
	EventUserTurnStarted = "on_user_turn_started"
	// EventUserTurnInferenceTriggered fires when there is enough signal to start
	// LLM inference, carrying the StopStrategy that decided. It fires together
	// with EventUserTurnStopped for most strategies, and alone when the turn's
	// end waits for a decision on the inference, or for an eager end of turn to
	// be confirmed.
	EventUserTurnInferenceTriggered = "on_user_turn_inference_triggered"
	// EventUserTurnStopped fires when a user turn is semantically final,
	// carrying the StopStrategy that decided. It is nil when nothing decided:
	// the turn was closed because no strategy did.
	EventUserTurnStopped = "on_user_turn_stopped"
	// EventUserTurnResumed fires when the user starts speaking again in an open
	// turn, after they stopped or after the turn's inference was triggered. It
	// carries the UserTurnResumedParams, which say whether the turn interrupts
	// the bot and whether that inference was triggered.
	//
	//	events.On(p.Events(), turns.EventUserTurnResumed,
	//	    func(ctx context.Context, params turns.UserTurnResumedParams) { … })
	EventUserTurnResumed = "on_user_turn_resumed"
	// EventUserTurnStopTimeout fires when the stop timeout ends a user turn its
	// stop strategies did not end. It carries no argument.
	EventUserTurnStopTimeout = "on_user_turn_stop_timeout"
	// EventUserTurnIdle fires when the user has been idle for the configured
	// timeout. It carries no argument.
	EventUserTurnIdle = "on_user_turn_idle"
)

The events a UserTurnProcessor raises around each turn it decides.

View Source
const DefaultEmptyUserTurnInterruptedPrompt = "The user may have said something while you were responding, " +
	"but it was not " +
	"recognized. Your response was cut off there, and the conversation only includes " +
	"the part they heard, which may be none of it. Briefly ask them to repeat what they said, and " +
	"repeat any question of yours they may have missed."

DefaultEmptyUserTurnInterruptedPrompt is the developer message an empty user turn that interrupted the bot is answered with, unless another is configured.

View Source
const DefaultSpeculationTimeout = 5 * time.Second

DefaultSpeculationTimeout is how long a prediction may go unresolved before it is withdrawn.

Variables

View Source
var TurnCompletionQuestion = classifier.ChoiceQuestion{
	Instructions: "The user is talking to a voice assistant. Their words come from speech " +
		"recognition, without punctuation, and may have been cut off. Decide whether " +
		"the user's turn is complete. Complete means conversationally complete, not " +
		"long: one word can be a complete answer, a question is complete, a " +
		"correction is complete.",
	Options: []classifier.Option{
		{Name: kindComplete, Description: "the user has taken their turn and the assistant should answer"},
		{Name: kindShort, Description: "the user stopped mid-sentence and will continue in a few seconds: " +
			"the last words leave a phrase open, such as ending on a conjunction, a preposition, " +
			"an article, or an unfinished list or number"},
		{Name: kindLong, Description: "the user needs time to think or asked the assistant to wait, or has " +
			"only acknowledged the question without answering it"},
	},
}

TurnCompletionQuestion is the question ClassifierStop puts to its classifier. The state is the user's turn so far and, when the strategy has the conversation, the assistant's last message.

Functions

This section is empty.

Types

type AlwaysUserMute

type AlwaysUserMute struct {
	// contains filtered or unexported fields
}

AlwaysUserMute mutes the user whenever the bot is speaking.

func NewAlwaysUserMute

func NewAlwaysUserMute() *AlwaysUserMute

NewAlwaysUserMute builds an always-while-bot-speaking mute strategy.

func (*AlwaysUserMute) ShouldMute

func (s *AlwaysUserMute) ShouldMute(f frames.Frame) bool

ShouldMute reports muted while the bot speaks.

type ClassifierStop added in v0.3.0

type ClassifierStop struct {
	StopStrategyBase
	// contains filtered or unexported fields
}

ClassifierStop decides the user is done when a classifier says their turn is complete.

Each time the user pauses with new words transcribed, the strategy asks its classifier whether the turn so far is conversationally complete:

  • "complete": it reports that the user is done.
  • "short": the user was cut off mid-sentence. It reports after ShortTimeout unless they continue.
  • "long": the user asked for time or only acknowledged the question. It reports after LongTimeout unless they continue.

It asks once the pause's words are in: when the transcription service finalizes their transcript, or when its p99 latency has passed since the user stopped. Asking sooner could judge the turn without its last words.

If the classifier fails or takes longer than ClassificationTimeout, it reports right away, so a turn never waits on a classifier that cannot answer. A pause with no words transcribed is not classified, and the controller's stop timeout ends such a turn.

Next to a turn analyzer such as TurnAnalyzerStop, in a StrategyModeAll list, the default, the turn ends once both have decided: the analyzer hears that more is coming after words that read complete, but holds a complete turn until it decides too. As the only stop strategy, it ends a turn as soon as the classifier finds it complete. In a StrategyModeFirst list the classifier can only end a turn sooner.

ClassifierUserTurnStrategies adds it after the default stop strategies.

func NewClassifierStop added in v0.3.0

func NewClassifierStop(cfg ClassifierStopConfig) (*ClassifierStop, error)

NewClassifierStop builds a stop strategy that asks a classifier whether the turn is complete. It fails on a configuration without a classifier.

func (*ClassifierStop) Classifier added in v0.3.0

func (s *ClassifierStop) Classifier() classifier.Classifier

Classifier is the classifier that decides whether a turn is complete.

func (*ClassifierStop) Cleanup added in v0.3.0

func (s *ClassifierStop) Cleanup()

Cleanup cancels what is pending and cleans the classifier up. The controller calls it with its lock held.

func (*ClassifierStop) DecisionScheduled added in v0.3.0

func (s *ClassifierStop) DecisionScheduled() bool

DecisionScheduled reports whether a "short" or "long" wait is running, which decides when it ends.

func (*ClassifierStop) Process added in v0.3.0

Process collects the turn's text and classifies it once the user pauses and the words are in.

func (*ClassifierStop) Setup added in v0.3.0

func (s *ClassifierStop) Setup(processor.Setup) error

Setup sets the classifier up and passes on the metrics of each of its calls.

func (*ClassifierStop) TurnStarted added in v0.3.0

func (s *ClassifierStop) TurnStarted()

TurnStarted starts a fresh turn with no text.

func (*ClassifierStop) TurnStopped added in v0.3.0

func (s *ClassifierStop) TurnStopped()

TurnStopped forgets the turn and any pending decision.

type ClassifierStopConfig added in v0.3.0

type ClassifierStopConfig struct {
	// Classifier decides whether the turn is complete. Required.
	Classifier classifier.Classifier `validate:"required"`
	// Context is the conversation, so the classifier sees the assistant's last
	// message along with the user's turn: whether "that's interesting" is an
	// answer or an acknowledgement depends on what was asked. Nil leaves it
	// out.
	Context *frames.LLMContext
	// ShortTimeout is how long to wait after a "short" verdict before
	// reporting that the user is done; 0 uses 5s.
	ShortTimeout time.Duration `validate:"min=0"`
	// LongTimeout is how long to wait after a "long" verdict before reporting
	// that the user is done; 0 uses 10s.
	LongTimeout time.Duration `validate:"min=0"`
	// ClassificationTimeout is how long to wait for the classifier before
	// reporting without it; 0 uses 1s.
	ClassificationTimeout time.Duration `validate:"min=0"`
}

ClassifierStopConfig configures a ClassifierStop strategy.

type Config

type Config struct {
	// Strategies are the start/stop strategy chains; empty chains use the
	// defaults, which are VAD and transcription to start and a speech timeout to
	// stop. For end-of-turn from a model, build Stop with NewTurnAnalyzerStop.
	Strategies UserTurnStrategies
	// StrategiesParams is how the strategies combine with the ones a service
	// recommends, and how they decide. The zero value is the defaults: the
	// application's lists replace the service's, the first start strategy to
	// decide starts the turn, and the turn ends once every stop strategy
	// agrees.
	StrategiesParams UserTurnStrategiesParams
	// StopTimeout is how long an open turn goes without user activity before it
	// is ended, unless a stop strategy has a decision scheduled; 0 uses 5s.
	StopTimeout time.Duration
	// IdleTimeout enables the idle watchdog; a value <= 0 disables it.
	IdleTimeout time.Duration
	// OnIdle fires when the conversation goes idle. Required to enable idle.
	OnIdle IdleCallback
	// MuteStrategies suppress user input while engaged (e.g. while the bot
	// speaks or a tool call runs). They are OR-reduced; empty means never mute.
	MuteStrategies []MuteStrategy
	// EmptyUserTurn is how the user aggregator responds to a user turn that
	// ends with no transcript. Nil uses the defaults: such a turn is answered
	// when it interrupted the bot, and left unanswered otherwise. It is ignored
	// with a realtime LLM service, which hears the user's audio directly, and by
	// a UserTurnProcessor, which aggregates nothing.
	EmptyUserTurn *EmptyUserTurnConfig
}

Config configures turn taking, for the user aggregator that drives it or for a UserTurnProcessor of its own.

Run inside the aggregator, the strategies see the same frames in the same order as the aggregation, so a turn that ends on a finalized transcript ends with that transcript already folded into the user's message. Run in a processor of their own, the decision can instead be made once and shared by several aggregators.

type ControllerHooks

type ControllerHooks struct {
	// Started, Stopped, InferenceTriggered and ResetAggregation each carry the
	// strategy that made the decision, so what the hooks report can name it.
	Started func(ctx context.Context, s StartStrategy, params UserTurnStartedParams)
	Stopped func(ctx context.Context, s StopStrategy, params UserTurnStoppedParams)
	// InferenceTriggered carries the speculation the inference answers, or nil
	// on an ordinary one. The controller runs the turn's inference once the
	// stop strategies have decided; a strategy only starts one to speculate.
	InferenceTriggered func(ctx context.Context, s StopStrategy, speculation *UserTurnSpeculation)
	// SpeculationCanceled withdraws a speculative reply that is no longer the
	// right answer.
	SpeculationCanceled func(ctx context.Context)
	// Resumed fires when the user starts speaking again in an open turn, after
	// they stopped or after the turn's inference was triggered. The new speech
	// voids the answer that inference started, which the params say.
	Resumed func(ctx context.Context, params UserTurnResumedParams)
	// StopTimeout fires when the stop timeout ends a turn its stop strategies
	// did not end.
	StopTimeout      func(ctx context.Context)
	ResetAggregation func(ctx context.Context, s StartStrategy)
	Push             func(ctx context.Context, f frames.Frame, dir processor.Direction)
	Broadcast        func(ctx context.Context, build func() frames.Frame)
}

ControllerHooks are the callbacks the controller invokes upward (to the UserTurnProcessor). They all run with the controller's mutex held.

type EagerMatchPolicy added in v0.2.0

type EagerMatchPolicy interface {
	// Matches reports whether the committed transcript still matches the eager
	// one: true to keep the speculative reply, false to discard it and answer
	// the committed transcript instead.
	Matches(eager, final string) bool
}

EagerMatchPolicy decides whether a speculative reply is still the right answer.

A speculative reply is generated from an eager transcript, before the service commits one. This decides whether the committed transcript is close enough to the eager one for that reply to stand.

type EagerStop added in v0.2.0

type EagerStop struct {
	// contains filtered or unexported fields
}

EagerStop answers an eager end of turn while the turn is still open.

Some transcribers predict the end of a turn before committing to it, and withdraw the prediction if the user turns out to be mid-sentence. This strategy starts generating a reply on that prediction, so the gap between it and the committed end of turn is spent generating rather than waiting.

The prediction can be wrong in three ways, and each withdraws the reply: the user resumes speaking and the service withdraws the eager end of turn, the committed transcript differs from the eager one per the match policy, or the turn never commits within the speculation timeout. Every one of those leaves here as a withdrawal, so a reply is never dropped somewhere the rest of the pipeline cannot see.

Nothing the speculation produces reaches the user or the conversation. The inference runs against a provisional conversation, and its reply is held by the model service until the turn is confirmed. The turn ends normally: the user message written to the conversation is always the committed transcript, never the eager one.

It wraps an external strategy rather than replacing it: the service owns turn detection, so what ends the turn is unchanged, and what this adds is the speculation around it. The decision the strategy underneath reports comes back here first, which is where the speculation is kept or withdrawn.

Install it with EagerStrategies rather than directly.

func NewEagerStop added in v0.2.0

func NewEagerStop(cfg EagerStopConfig) *EagerStop

NewEagerStop builds an eager stop strategy.

func (*EagerStop) Cleanup added in v0.2.0

func (s *EagerStop) Cleanup()

Cleanup stops the speculation timer and tears the strategy down.

func (*EagerStop) DecisionScheduled added in v0.3.0

func (s *EagerStop) DecisionScheduled() bool

DecisionScheduled reports that the strategy schedules no decision of its own.

func (*EagerStop) MatchPolicy added in v0.2.0

func (s *EagerStop) MatchPolicy() EagerMatchPolicy

MatchPolicy is the policy deciding whether a speculative reply still applies.

func (*EagerStop) Process added in v0.2.0

func (s *EagerStop) Process(f frames.Frame) ProcessFrameResult

Process starts a speculation on an eager end of turn, withdraws one, or forgets one, then lets the strategy underneath see the frame as usual.

func (*EagerStop) ResolvesProposedTurnStopFrames added in v0.2.0

func (s *EagerStop) ResolvesProposedTurnStopFrames() bool

ResolvesProposedTurnStopFrames reports what the strategy underneath does with proposals: speculating changes what happens during a turn, not who ends it.

func (*EagerStop) SetWaitForTranscript added in v0.2.0

func (s *EagerStop) SetWaitForTranscript(wait bool)

SetWaitForTranscript changes it for the turns that follow.

func (*EagerStop) Setup added in v0.2.0

func (s *EagerStop) Setup(st processor.Setup) error

Setup hands the pipeline's configuration to the strategy underneath.

func (*EagerStop) TurnStarted added in v0.2.0

func (s *EagerStop) TurnStarted()

TurnStarted readies per-turn state, withdrawing a speculation left over from the turn before.

func (*EagerStop) TurnStopped added in v0.2.0

func (s *EagerStop) TurnStopped()

TurnStopped clears per-turn state, withdrawing a speculation the turn ended without resolving: the stop watchdog, an interruption, the session ending. Nothing else would withdraw it, so the reply would stay held.

func (*EagerStop) WaitForTranscript added in v0.2.0

func (s *EagerStop) WaitForTranscript() bool

WaitForTranscript reports whether the turn is held open for a transcript.

func (*EagerStop) WaitsForInference added in v0.3.0

func (s *EagerStop) WaitsForInference() bool

WaitsForInference reports that the strategy listens to the service rather than waiting for the turn's inference.

type EagerStopConfig added in v0.2.0

type EagerStopConfig struct {
	// ExternalStopConfig configures the external strategy underneath, which is
	// what actually ends the turn: the service owns turn detection here.
	ExternalStopConfig
	// MatchPolicy decides whether the committed transcript is close enough to
	// the eager one to keep the speculative reply. Nil uses NormalizedMatch,
	// which ignores the capitalization and punctuation services commonly add
	// when they commit a transcript. Use ExactMatch to require the two to be
	// identical.
	MatchPolicy EagerMatchPolicy
	// SpeculationTimeout is how long a prediction may go unresolved before it is
	// withdrawn; zero uses five seconds. A service that stops sending turn
	// signals mid-speculation would otherwise leave the reply held and the bot
	// silent for the rest of the session.
	SpeculationTimeout time.Duration
}

EagerStopConfig configures an EagerStop strategy.

type EagerStrategiesConfig added in v0.2.0

type EagerStrategiesConfig struct {
	ExternalStrategiesConfig
	// MatchPolicy decides whether the committed transcript is close enough to
	// the eager one to keep the speculative reply. Nil uses NormalizedMatch.
	MatchPolicy EagerMatchPolicy
	// SpeculationTimeout bounds how long a prediction may go unresolved; zero
	// uses five seconds.
	SpeculationTimeout time.Duration
}

EagerStrategiesConfig configures the strategies an eager service recommends.

type Emitter

type Emitter interface {
	// Push sends a frame to the neighbor in dir.
	Push(ctx context.Context, f frames.Frame, dir processor.Direction) error
	// Broadcast builds one frame per direction and sends them both ways. It takes
	// a constructor rather than a frame because the two directions must not share
	// one instance: each is processed on its own goroutine, and a frame is owned
	// by a single goroutine at a time.
	Broadcast(ctx context.Context, build func() frames.Frame) error
}

Emitter lets a controller or strategy push frames into the pipeline. The UserTurnProcessor implements it. Broadcast sends a frame both downstream and upstream, which is how turn decisions and interruptions reach the whole pipeline.

type EmptyUserTurnConfig added in v0.3.0

type EmptyUserTurnConfig struct {
	// InterruptedPrompt is the developer message for an empty turn that
	// interrupted the bot. Nil uses DefaultEmptyUserTurnInterruptedPrompt; an
	// empty string leaves such turns unanswered, and with IdlePrompt left empty
	// too, every empty turn.
	InterruptedPrompt *string
	// IdlePrompt is the developer message for an empty turn while the bot was
	// idle. Empty, the default, leaves such turns unanswered.
	IdlePrompt string
	// MaxConsecutiveRecoveries is how many empty turns in a row are answered;
	// zero uses 1. Further ones are left unanswered until the user says
	// something that is transcribed.
	MaxConsecutiveRecoveries int `validate:"min=0"`
}

EmptyUserTurnConfig is how the user aggregator responds to a user turn with no transcript.

A user turn can start on voice activity alone and then end with no transcript: a cough, background noise, or speech the STT could not recognize. Nothing is written to the context and the LLM does not run. With this config, the aggregator can append a developer message for such a turn and run the LLM once.

Either case may be noise. They differ in what happens if the turn goes unanswered, so each has its own prompt:

  • Interrupted: the turn started while the bot was thinking, speaking or running a function call, and cut it off. Unanswered, the bot stays silent mid-response, so by default the LLM runs and the bot asks the user to repeat or picks up where it left off. A turn before the bot has first finished speaking counts as interrupted too.
  • Idle: the bot had finished and was waiting for the user. The conversation is not stuck, and answering what may be noise would be intrusive, so by default the turn gets no answer.

func (EmptyUserTurnConfig) MaxRecoveries added in v0.3.0

func (c EmptyUserTurnConfig) MaxRecoveries() int

MaxRecoveries is how many empty turns in a row are answered.

func (EmptyUserTurnConfig) Prompt added in v0.3.0

func (c EmptyUserTurnConfig) Prompt(interrupted bool) string

Prompt is the developer message an empty turn is answered with, "" when it goes unanswered. interrupted says whether the turn interrupted the bot.

type ExactMatch added in v0.2.0

type ExactMatch struct{}

ExactMatch keeps the reply only when the two transcripts are identical.

func (ExactMatch) Matches added in v0.2.0

func (ExactMatch) Matches(eager, final string) bool

Matches reports whether the two transcripts are identical.

type ExternalCompletionStop deprecated

type ExternalCompletionStop struct {
	StopStrategyBase
}

ExternalCompletionStop reports the user done whenever a UserTurnInferenceCompletedFrame arrives, for pipelines where some external component judges when a turn is semantically complete and emits that frame.

It decides on the frame the turn's inference produces, so it waits for that inference. If the producer never emits the frame, the controller's stop timeout ends the turn after no activity.

Deprecated: use ExternalStop, and push a ProposedUserStoppedSpeakingFrame once the user is done. For the LLM's turn-completion markers, use LLMTurnCompletionStop.

func NewExternalCompletionStop deprecated

func NewExternalCompletionStop() *ExternalCompletionStop

NewExternalCompletionStop builds an external-completion stop strategy.

Deprecated: use ExternalStop, or LLMTurnCompletionStop for the LLM's turn-completion markers.

func (*ExternalCompletionStop) Process

Process reports the user done on a completion frame.

func (*ExternalCompletionStop) WaitsForInference added in v0.3.0

func (s *ExternalCompletionStop) WaitsForInference() bool

WaitsForInference reports that the strategy decides on the UserTurnInferenceCompletedFrame the turn's inference produces.

type ExternalStart

type ExternalStart struct {
	StartStrategyBase
}

ExternalStart takes its cue for the start of a turn from another processor rather than detecting it. It understands two signals, which differ in how much the emitter has already done:

  • A ProposedUserStartedSpeakingFrame is a service with its own turn detection proposing a turn boundary. This strategy makes the decision, emitting the UserStartedSpeakingFrame and broadcasting the interruption itself. Embed it to adjust when, or whether, a proposal opens a turn.
  • A UserStartedSpeakingFrame means the turn was already decided and announced elsewhere, typically by a shared turn processor fanning turns out to several aggregators. This strategy adopts that decision and emits nothing, so the turn is not announced twice.

A service that emits turn frames directly lands on the adopt path and keeps working, but it owns the interruption logic itself. Emitting proposals instead hands that job back to the pipeline.

func NewExternalStart

func NewExternalStart(cfg ExternalStartConfig) *ExternalStart

NewExternalStart builds an external start strategy.

func (*ExternalStart) Process

Process resolves a proposal, or adopts a turn start decided elsewhere.

func (*ExternalStart) ResolvesProposedTurnStartFrames added in v0.1.0

func (s *ExternalStart) ResolvesProposedTurnStartFrames() bool

ResolvesProposedTurnStartFrames reports that this strategy resolves proposals into turn starts.

type ExternalStartConfig added in v0.1.0

type ExternalStartConfig struct {
	// EnableInterruptions broadcasts an interruption when a proposal opens a
	// turn; nil defaults to true. It is ignored on the adopt path, where the
	// emitter has already broadcast one.
	EnableInterruptions *bool
}

ExternalStartConfig configures an ExternalStart strategy.

type ExternalStop

type ExternalStop struct {
	StopStrategyBase
	// contains filtered or unexported fields
}

ExternalStop takes its cue for the end of a turn from another processor. It is the counterpart to ExternalStart and takes the same two signals:

  • A ProposedUserStoppedSpeakingFrame is a service proposing that the turn has ended. This strategy decides, and emits the UserStoppedSpeakingFrame itself. It may also hold the turn open past the proposal, which is what WaitForTranscript does.
  • A UserStoppedSpeakingFrame means the turn end was already decided and announced elsewhere. This strategy adopts that decision and emits nothing.

func NewExternalStop

func NewExternalStop(cfg ExternalStopConfig) *ExternalStop

NewExternalStop builds an external stop strategy.

func (*ExternalStop) Cleanup

func (s *ExternalStop) Cleanup()

Cleanup stops the transcript timer.

func (*ExternalStop) Process

Process records the external signals and the transcripts around them. It always continues, so the rest of the stop chain is evaluated.

func (*ExternalStop) ResolvesProposedTurnStopFrames added in v0.1.0

func (s *ExternalStop) ResolvesProposedTurnStopFrames() bool

ResolvesProposedTurnStopFrames reports that this strategy resolves proposals into turn stops.

func (*ExternalStop) SetWaitForTranscript added in v0.2.0

func (s *ExternalStop) SetWaitForTranscript(wait bool)

SetWaitForTranscript changes it for the turns that follow.

func (*ExternalStop) TurnStarted added in v0.1.0

func (s *ExternalStop) TurnStarted()

TurnStarted readies the strategy to detect the end of the turn now starting.

func (*ExternalStop) TurnStopped added in v0.1.0

func (s *ExternalStop) TurnStopped()

TurnStopped clears per-turn state once the turn has ended.

func (*ExternalStop) WaitForTranscript added in v0.2.0

func (s *ExternalStop) WaitForTranscript() bool

WaitForTranscript reports whether the turn is held open for a transcript.

type ExternalStopConfig

type ExternalStopConfig struct {
	// Timeout is how long to wait after a final transcript for more of them,
	// so a turn whose transcript arrives late or in pieces is decided once the
	// text has settled; 0 uses 500ms.
	Timeout time.Duration
	// WaitForTranscript holds the turn open until transcript text arrives after
	// the external stop signal; nil defaults to true. Set it false when local
	// turn detection is the intended driver of the conversation, so transcripts
	// are off the latency critical path.
	WaitForTranscript *bool
}

ExternalStopConfig configures an ExternalStop strategy.

type ExternalStrategiesConfig added in v0.1.0

type ExternalStrategiesConfig struct {
	// EnableInterruptions broadcasts an interruption when a proposal opens a
	// turn; nil defaults to true. A service routes its own should-interrupt
	// setting here. It does not apply on the adopt path, where the emitter has
	// already broadcast one.
	EnableInterruptions *bool
}

ExternalStrategiesConfig configures ExternalStrategies.

type FirstSpeechUserMute

type FirstSpeechUserMute struct {
	// contains filtered or unexported fields
}

FirstSpeechUserMute mutes the user only during the bot's first speaking turn, allowing pre-speech input and never muting afterward.

func NewFirstSpeechUserMute

func NewFirstSpeechUserMute() *FirstSpeechUserMute

NewFirstSpeechUserMute builds a first-speech mute strategy.

func (*FirstSpeechUserMute) ShouldMute

func (s *FirstSpeechUserMute) ShouldMute(f frames.Frame) bool

ShouldMute reports muted only during the bot's first speech.

type FunctionCallUserMute

type FunctionCallUserMute struct {
	// contains filtered or unexported fields
}

FunctionCallUserMute mutes the user while any tool call is in flight.

func NewFunctionCallUserMute

func NewFunctionCallUserMute() *FunctionCallUserMute

NewFunctionCallUserMute builds a function-call mute strategy.

func (*FunctionCallUserMute) ShouldMute

func (s *FunctionCallUserMute) ShouldMute(f frames.Frame) bool

ShouldMute reports muted while one or more tool calls are running.

type IdleCallback

type IdleCallback func(ctx context.Context, c *UserIdleController) error

IdleCallback runs when the conversation has stayed quiet past the configured timeout. It receives the controller so it can Push or Broadcast frames (a reminder, or an EndFrame to hang up). It runs off the frame path. Following Pipecat, it fires once per arming; escalation/retry, if wanted, is the caller's responsibility.

type IdleConfig

type IdleConfig struct {
	// Timeout is how long the conversation may stay quiet after the bot stops
	// speaking before Callback fires. A value <= 0 disables idle detection.
	Timeout time.Duration
	// Callback fires on idle. A nil callback disables idle detection.
	Callback IdleCallback
}

IdleConfig configures a UserIdleController.

type LLMTurnCompletionStop added in v0.1.0

type LLMTurnCompletionStop struct {
	StopStrategyBase
	// contains filtered or unexported fields
}

LLMTurnCompletionStop decides the user is done only when the LLM marks the turn complete.

It turns on turn-completion markers in the LLM, which then starts every response with the complete marker, the short one (the user will continue shortly) or the long one (the user needs more time), and reports each as a UserTurnCompletionFrame. The settings update is marked to reach inactive services, so every LLM behind a switcher is configured rather than only the one in use at startup.

The strategy waits for the turn's inference rather than listening to the user, so it needs other stop strategies to decide the user stopped: once they have decided, the inference runs, as FilterIncompleteUserTurnStrategies sets up. It decides the user is done on that inference's complete marker, on a tool call, or on a response with no marker. The short and long markers leave the turn open. If the user then stays quiet for the configured timeout, the strategy decides the user is done and asks the LLM to re-engage them, and the controller's stop timeout waits for that decision. Another inference answering the user in the meantime, such as one for words transcribed after the turn's inference, cancels the re-prompt. When the user speaks again, it waits for the next inference instead.

An eager end of turn answers the turn speculatively, and the strategy decides on that answer too. An incomplete marker withdraws it, and the committed turn brings an inference of its own.

func NewLLMTurnCompletionStop

func NewLLMTurnCompletionStop(cfg llm.UserTurnCompletionConfig) *LLMTurnCompletionStop

NewLLMTurnCompletionStop builds the stop strategy that decides on the LLM's turn-completion marker. Pair it with stop strategies that listen to the user, as FilterIncompleteUserTurnStrategies does.

func (*LLMTurnCompletionStop) Cleanup added in v0.3.0

func (s *LLMTurnCompletionStop) Cleanup()

Cleanup cancels any pending re-prompt.

func (*LLMTurnCompletionStop) Config added in v0.1.0

Config is the turn-completion configuration this strategy applies.

func (*LLMTurnCompletionStop) DecisionScheduled added in v0.3.0

func (s *LLMTurnCompletionStop) DecisionScheduled() bool

DecisionScheduled reports whether a re-prompt is scheduled, which decides when it fires.

func (*LLMTurnCompletionStop) Process added in v0.1.0

Process configures the LLM on start, and follows the turn's inference and the user.

func (*LLMTurnCompletionStop) TurnStarted added in v0.3.0

func (s *LLMTurnCompletionStop) TurnStarted()

TurnStarted forgets the previous turn's inference and cancels any pending re-prompt.

func (*LLMTurnCompletionStop) TurnStopped added in v0.3.0

func (s *LLMTurnCompletionStop) TurnStopped()

TurnStopped forgets this turn's inference, keeping a pending re-prompt.

func (*LLMTurnCompletionStop) WaitsForInference added in v0.3.0

func (s *LLMTurnCompletionStop) WaitsForInference() bool

WaitsForInference reports that the strategy decides on the LLM's marker, which only the turn's inference produces.

type MergeMode added in v0.3.0

type MergeMode int

MergeMode is how an application's list of user turn strategies combines with the one a service recommends.

const (
	// MergeModeReplace uses the application's list on its own. It is the
	// default.
	MergeModeReplace MergeMode = iota
	// MergeModeExtend adds the strategies the application gave to the
	// service's list, or to the defaults when no service recommends any.
	MergeModeExtend
)

type MinWordsStart

type MinWordsStart struct {
	StartStrategyBase
	// contains filtered or unexported fields
}

MinWordsStart opens a turn only once enough words are heard, raising the bar for interrupting the bot.

func NewMinWordsStart

func NewMinWordsStart(cfg MinWordsStartConfig) *MinWordsStart

NewMinWordsStart builds a min-words start strategy.

func (*MinWordsStart) Process

Process counts words and reports the user started once the threshold is met.

func (*MinWordsStart) TurnStarted added in v0.1.0

func (s *MinWordsStart) TurnStarted()

TurnStarted clears the bot-speaking flag: the turn that just started will have interrupted the bot, so the rest of it counts against the single-word threshold without waiting for the bot-stopped frame to catch up.

type MinWordsStartConfig

type MinWordsStartConfig struct {
	// MinWords is the word count required to open a turn while the bot is
	// speaking (to gate barge-in); a single word suffices when the bot is silent.
	MinWords int
	// UseInterim counts interim transcripts too; nil defaults to true.
	UseInterim *bool
}

MinWordsStartConfig configures a MinWordsStart strategy.

type MuteStrategy

type MuteStrategy interface {
	ShouldMute(f frames.Frame) bool
}

MuteStrategy decides whether user input should be suppressed right now. ShouldMute is called for every frame (so the strategy can track state) and returns the muted state as of that frame. The UserTurnProcessor OR-reduces all strategies and, while muted, drops the user-input frames before they reach turn detection — so the user can neither barge in nor pollute the context at the wrong moment. Strategies are driven only from the processor (under its mute mutex) and need no locking of their own.

type MuteUntilFirstBotComplete

type MuteUntilFirstBotComplete struct {
	// contains filtered or unexported fields
}

MuteUntilFirstBotComplete mutes the user from the start of the session until the bot finishes its first speech.

The mute is also released when the bot's first speaking turn fails before producing any audio, so that a failed opening leaves the user able to speak.

func NewMuteUntilFirstBotComplete

func NewMuteUntilFirstBotComplete() *MuteUntilFirstBotComplete

NewMuteUntilFirstBotComplete builds a mute-until-first-bot-complete strategy.

func (*MuteUntilFirstBotComplete) ShouldMute

func (s *MuteUntilFirstBotComplete) ShouldMute(f frames.Frame) bool

ShouldMute reports muted until the bot's first speech completes, or until that first turn fails before it starts.

type NormalizedMatch added in v0.2.0

type NormalizedMatch struct{}

NormalizedMatch keeps the reply when the transcripts differ only in formatting.

It compares with case, punctuation and whitespace removed. Services commonly format the committed transcript, capitalizing it and punctuating it, while leaving the eager one raw, which ExactMatch counts as a difference.

func (NormalizedMatch) Matches added in v0.2.0

func (NormalizedMatch) Matches(eager, final string) bool

Matches reports whether the two transcripts match once formatting is removed.

type ProcessFrameResult

type ProcessFrameResult int

ProcessFrameResult is what a strategy returns from Process.

The result is deprecated in favor of StrategyMode: strategies return Continue, and every strategy sees every frame. A list whose strategies all have to agree, such as a wake phrase next to VAD, is StrategyModeAll. The type stays in the strategy interfaces until the result is removed.

const (
	// Continue evaluates the next strategy in the chain. It is what every
	// strategy returns.
	Continue ProcessFrameResult = iota
	// Stop short-circuits the remaining strategies for this frame, and only in
	// a StrategyModeFirst list, with a deprecation warning.
	//
	// Deprecated: use StrategyMode instead. Every strategy sees every frame,
	// and a list whose strategies all have to agree is StrategyModeAll.
	Stop
)

type SpeechTimeoutConfig

type SpeechTimeoutConfig struct {
	// UserSpeechTimeout is the silence the user gets to resume after the VAD
	// stops; 0 uses 600ms.
	UserSpeechTimeout time.Duration
	// WaitForTranscript holds the turn open until a transcript arrives; nil
	// defaults to true.
	WaitForTranscript *bool
}

SpeechTimeoutConfig configures a SpeechTimeoutStop strategy.

type SpeechTimeoutStop

type SpeechTimeoutStop struct {
	StopStrategyBase
	// contains filtered or unexported fields
}

SpeechTimeoutStop ends a turn purely on silence timers after the VAD reports the user stopped — no model. It is the model-free default stop strategy.

func NewSpeechTimeoutStop

func NewSpeechTimeoutStop(cfg SpeechTimeoutConfig) *SpeechTimeoutStop

NewSpeechTimeoutStop builds a speech-timeout stop strategy.

func (*SpeechTimeoutStop) Cleanup

func (s *SpeechTimeoutStop) Cleanup()

Cleanup stops the timers.

func (*SpeechTimeoutStop) Process

Process runs the silence timers and decides end-of-turn.

func (*SpeechTimeoutStop) SetWaitForTranscript added in v0.2.0

func (s *SpeechTimeoutStop) SetWaitForTranscript(wait bool)

SetWaitForTranscript changes it for the turns that follow.

func (*SpeechTimeoutStop) TurnStarted added in v0.1.0

func (s *SpeechTimeoutStop) TurnStarted()

TurnStarted readies the strategy to detect the end of the turn now starting.

func (*SpeechTimeoutStop) TurnStopped added in v0.1.0

func (s *SpeechTimeoutStop) TurnStopped()

TurnStopped clears per-turn state once the turn has ended.

func (*SpeechTimeoutStop) WaitForTranscript added in v0.2.0

func (s *SpeechTimeoutStop) WaitForTranscript() bool

WaitForTranscript reports whether the turn is held open for a transcript.

type StartStrategy

type StartStrategy interface {
	// Process examines one frame; returning Stop short-circuits the start chain
	// for that frame. It runs with the shared mutex held.
	Process(f frames.Frame) ProcessFrameResult
	// TurnStarted readies per-turn state when a turn begins.
	TurnStarted()
	// TurnStopped clears per-turn state when a turn ends.
	TurnStopped()
	// Setup hands the strategy the pipeline's configuration, which it knows
	// before any frame arrives.
	Setup(s processor.Setup) error
	// Cleanup releases resources (timers).
	Cleanup()
	// ResolvesProposedTurnStartFrames reports whether this strategy resolves
	// proposals into turn starts.
	ResolvesProposedTurnStartFrames() bool
	// contains filtered or unexported methods
}

StartStrategy decides when the user's turn begins. Concrete strategies embed StartStrategyBase and implement Process.

func DefaultStartStrategies

func DefaultStartStrategies() []StartStrategy

DefaultStartStrategies returns the default start chain: VAD onset, with transcription as a fallback for soft speech the VAD misses.

type StartStrategyBase

type StartStrategyBase struct {
	// EnableInterruptions broadcasts an InterruptionFrame on turn start.
	EnableInterruptions bool
	// EnableUserSpeakingFrames broadcasts a UserStartedSpeakingFrame on turn start.
	EnableUserSpeakingFrames bool
	// contains filtered or unexported fields
}

StartStrategyBase is embedded by every start strategy. It carries the open-turn flags and the trigger helpers.

func (*StartStrategyBase) Cleanup

func (b *StartStrategyBase) Cleanup()

Cleanup is the default no-op.

func (*StartStrategyBase) ReportStarted added in v0.3.0

func (b *StartStrategyBase) ReportStarted()

ReportStarted reports that the user started, with the flags the strategy was built with.

A strategy calls it when it decides the user's turn has started. The controller starts the turn on the first decision, or once every start strategy has decided in a StrategyModeAll list.

func (*StartStrategyBase) ReportStartedOverriding added in v0.3.0

func (b *StartStrategyBase) ReportStartedOverriding(o StartedOverrides)

ReportStartedOverriding reports that the user started, overriding the strategy's configured flags for this turn.

func (*StartStrategyBase) ResolvesProposedTurnStartFrames added in v0.1.0

func (b *StartStrategyBase) ResolvesProposedTurnStartFrames() bool

ResolvesProposedTurnStartFrames reports whether this strategy resolves proposals into turn starts.

A ProposedUserStartedSpeakingFrame is a request for a decision, so a strategy that acts on one consumes it: the frame stops traveling, and no resolver further along decides the same turn a second time. Override to true in a strategy that handles that frame.

func (*StartStrategyBase) Setup added in v0.1.0

Setup is the default no-op.

func (*StartStrategyBase) TriggerResetAggregation

func (b *StartStrategyBase) TriggerResetAggregation()

TriggerResetAggregation asks the user aggregator to drop the in-progress aggregation (e.g. pre-wake-phrase speech).

func (*StartStrategyBase) TriggerStarted deprecated

func (b *StartStrategyBase) TriggerStarted()

TriggerStarted reports that the user started.

Deprecated: use ReportStarted. A strategy reports its decision, and the controller decides when the turn starts.

func (*StartStrategyBase) TriggerStartedOverriding deprecated added in v0.1.0

func (b *StartStrategyBase) TriggerStartedOverriding(o StartedOverrides)

TriggerStartedOverriding reports that the user started, overriding the strategy's configured flags for this turn.

Deprecated: use ReportStartedOverriding.

func (*StartStrategyBase) TurnStarted added in v0.1.0

func (b *StartStrategyBase) TurnStarted()

TurnStarted is the default no-op.

func (*StartStrategyBase) TurnStopped added in v0.1.0

func (b *StartStrategyBase) TurnStopped()

TurnStopped is the default no-op.

type StartedOverrides added in v0.1.0

type StartedOverrides struct {
	// EnableInterruptions overrides whether an interruption is broadcast for
	// this turn. Set it false when something else in the pipeline has already
	// broadcast one.
	EnableInterruptions *bool
	// EnableUserSpeakingFrames overrides whether a UserStartedSpeakingFrame is
	// emitted for this turn. Set it false when something else in the pipeline
	// has already emitted it.
	EnableUserSpeakingFrames *bool
}

StartedOverrides overrides, for one turn, the flags the strategy was built with. A nil field keeps the configured value.

type StopStrategy

type StopStrategy interface {
	// Process examines one frame; returning Stop short-circuits the stop chain.
	// Stop strategies usually return Continue and signal via Trigger*. It runs
	// with the shared mutex held.
	Process(f frames.Frame) ProcessFrameResult
	// TurnStarted readies per-turn state when a turn begins.
	TurnStarted()
	// TurnStopped clears per-turn state, including any buffered speech, when a
	// turn ends.
	TurnStopped()
	// Setup hands the strategy the pipeline's configuration, which it knows
	// before any frame arrives.
	Setup(s processor.Setup) error
	// Cleanup releases resources (timers).
	Cleanup()
	// ResolvesProposedTurnStopFrames reports whether this strategy resolves
	// proposals into turn stops.
	ResolvesProposedTurnStopFrames() bool
	// WaitsForInference reports whether this strategy waits for the turn's
	// inference before deciding.
	WaitsForInference() bool
	// DecisionScheduled reports whether this strategy has a decision of its own
	// scheduled, which the stop timeout then waits for.
	DecisionScheduled() bool
	// contains filtered or unexported methods
}

StopStrategy decides when the user's turn ends. Concrete strategies embed StopStrategyBase and implement Process.

func DefaultStopStrategies

func DefaultStopStrategies() []StopStrategy

DefaultStopStrategies returns the default stop chain: end-of-turn decided by the Smart Turn v3 model, so a pause it rates as unfinished does not end the turn.

The model runs on the ONNX runtime, which is located at run time rather than linked in, so a pipeline that cannot find it fails to start with the reason (see the onnxrt package for where it looks). For turn-taking without a model, build the chain explicitly with NewSpeechTimeoutStop.

func Deferred deprecated

func Deferred(inner StopStrategy) StopStrategy

Deferred wraps inner, once a way to have it start the turn's inference but never end the turn.

Deprecated: there is no replacement; pass the wrapped strategy itself. The controller runs the turn's inference itself, and a stop strategy that waits for that inference, such as LLMTurnCompletionStop, ends the turn in either stop mode.

type StopStrategyBase

type StopStrategyBase struct {
	// EnableUserSpeakingFrames broadcasts a UserStoppedSpeakingFrame on turn stop.
	EnableUserSpeakingFrames bool
	// contains filtered or unexported fields
}

StopStrategyBase is embedded by every stop strategy.

func (*StopStrategyBase) Broadcast

func (b *StopStrategyBase) Broadcast(build func() frames.Frame)

Broadcast builds one frame per direction and sends them both ways. It takes a constructor so the two directions never share an instance.

func (*StopStrategyBase) CancelSpeculation added in v0.3.0

func (b *StopStrategyBase) CancelSpeculation()

CancelSpeculation withdraws the speculation this strategy has in flight, whatever voided it: the service withdrawing its prediction, a committed transcript that does not match, or a turn that never resolved the speculation at all.

It is broadcast the same way the turn end is. 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 reply the withdrawal was meant to discard.

func (*StopStrategyBase) Cleanup

func (b *StopStrategyBase) Cleanup()

Cleanup is the default no-op.

func (*StopStrategyBase) DecisionScheduled added in v0.3.0

func (b *StopStrategyBase) DecisionScheduled() bool

DecisionScheduled reports whether this strategy has a decision of its own scheduled.

While a stop strategy has one, the 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.

func (*StopStrategyBase) Push

Push sends a frame to the neighbor in dir.

func (*StopStrategyBase) ReportStopped added in v0.3.0

func (b *StopStrategyBase) ReportStopped()

ReportStopped reports that the user is done, with the flags the strategy was built with.

A strategy calls it 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.

func (*StopStrategyBase) ReportStoppedOverriding added in v0.3.0

func (b *StopStrategyBase) ReportStoppedOverriding(o StoppedOverrides)

ReportStoppedOverriding reports that the user is done, overriding the strategy's configured flags for this turn.

func (*StopStrategyBase) ResolvesProposedTurnStopFrames added in v0.1.0

func (b *StopStrategyBase) ResolvesProposedTurnStopFrames() bool

ResolvesProposedTurnStopFrames reports whether this strategy resolves proposals into turn stops.

A ProposedUserStoppedSpeakingFrame is a request for a decision, so a strategy that acts on one consumes it: the frame stops traveling, 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.

func (*StopStrategyBase) Setup added in v0.1.0

Setup is the default no-op.

func (*StopStrategyBase) StartSpeculation added in v0.3.0

func (b *StopStrategyBase) StartSpeculation(s UserTurnSpeculation)

StartSpeculation starts a speculative inference against a provisional conversation carrying the turn text the speculation names, for a turn that has not ended yet. The reply it produces is held until the turn is confirmed.

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.

func (*StopStrategyBase) TriggerFinalized deprecated

func (b *StopStrategyBase) TriggerFinalized()

TriggerFinalized reports that the user is done.

Deprecated: use ReportStopped, which reports the same decision.

func (*StopStrategyBase) TriggerFinalizedOverriding deprecated added in v0.1.0

func (b *StopStrategyBase) TriggerFinalizedOverriding(o StoppedOverrides)

TriggerFinalizedOverriding reports that the user is done, overriding the strategy's configured flags for this turn.

Deprecated: use ReportStoppedOverriding, which reports the same decision.

func (*StopStrategyBase) TriggerInferenceTriggered deprecated

func (b *StopStrategyBase) TriggerInferenceTriggered()

TriggerInferenceTriggered used to start the turn's inference. It does nothing now, with a warning the first time, since the controller runs the turn's inference once the stop strategies have decided.

Deprecated: call ReportStopped when the user is done, and StartSpeculation to answer ahead of that.

func (*StopStrategyBase) TriggerInferenceTriggeredSpeculating deprecated added in v0.2.0

func (b *StopStrategyBase) TriggerInferenceTriggeredSpeculating(s UserTurnSpeculation)

TriggerInferenceTriggeredSpeculating starts a speculative inference.

Deprecated: use StartSpeculation.

func (*StopStrategyBase) TriggerSpeculationCanceled deprecated added in v0.2.0

func (b *StopStrategyBase) TriggerSpeculationCanceled()

TriggerSpeculationCanceled withdraws the speculation this strategy has in flight.

Deprecated: use CancelSpeculation.

func (*StopStrategyBase) TriggerStopped deprecated

func (b *StopStrategyBase) TriggerStopped()

TriggerStopped reports that the user is done. It no longer starts the turn's inference, which the controller now runs once the stop strategies have decided.

Deprecated: use ReportStopped.

func (*StopStrategyBase) TriggerStoppedOverriding deprecated added in v0.1.0

func (b *StopStrategyBase) TriggerStoppedOverriding(o StoppedOverrides)

TriggerStoppedOverriding reports that the user is done, overriding the strategy's configured flags for this turn.

Deprecated: use ReportStoppedOverriding.

func (*StopStrategyBase) TurnStarted added in v0.1.0

func (b *StopStrategyBase) TurnStarted()

TurnStarted is the default no-op.

func (*StopStrategyBase) TurnStopped added in v0.1.0

func (b *StopStrategyBase) TurnStopped()

TurnStopped is the default no-op.

func (*StopStrategyBase) WaitsForInference added in v0.3.0

func (b *StopStrategyBase) WaitsForInference() bool

WaitsForInference reports whether this strategy waits for the turn's inference before deciding.

In a StrategyModeAll list, 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.

type StoppedOverrides added in v0.1.0

type StoppedOverrides struct {
	// EnableUserSpeakingFrames overrides whether a UserStoppedSpeakingFrame is
	// emitted for this turn. Set it false when something else in the pipeline
	// has already emitted it.
	EnableUserSpeakingFrames *bool
	// ConfirmsSpeculation reports that this turn end confirms a speculative
	// reply that has already been generated, so the model must not run again.
	ConfirmsSpeculation bool
}

StoppedOverrides overrides, for one turn, the flags the strategy was built with. A nil field keeps the configured value.

type StrategyMode added in v0.3.0

type StrategyMode int

StrategyMode is how a list of user turn strategies reaches a decision.

const (
	// StrategyModeDefault is the list's own default: StrategyModeFirst for the
	// start strategies and StrategyModeAll for the stop strategies.
	StrategyModeDefault StrategyMode = iota
	// StrategyModeAll has every strategy agree, and each one sees every frame.
	StrategyModeAll
	// StrategyModeFirst has the first strategy to decide win.
	StrategyModeFirst
)

type TranscriptWaiter added in v0.2.0

type TranscriptWaiter interface {
	StopStrategy
	// WaitForTranscript reports whether the turn is held open for a transcript.
	WaitForTranscript() bool
	// SetWaitForTranscript changes it for the turns that follow.
	SetWaitForTranscript(wait bool)
}

TranscriptWaiter is an optional interface a stop strategy implements when it can be told whether to hold a turn open until a transcript arrives.

A pipeline driven by a speech-to-speech service takes transcripts off the critical path: the service is answering the audio, so waiting on a transcript only delays the turn. The user aggregator flips this on the strategies that expose it when such a service announces itself.

type TranscriptionStart

type TranscriptionStart struct {
	StartStrategyBase
	// contains filtered or unexported fields
}

TranscriptionStart opens a turn on a transcript, a fallback for soft speech a VAD misses.

func NewTranscriptionStart

func NewTranscriptionStart(cfg TranscriptionStartConfig) *TranscriptionStart

NewTranscriptionStart builds a transcription-based start strategy.

func (*TranscriptionStart) Process

Process reports the user started on a transcript.

type TranscriptionStartConfig

type TranscriptionStartConfig struct {
	// UseInterim also triggers on interim transcripts; nil defaults to true.
	UseInterim *bool
}

TranscriptionStartConfig configures a TranscriptionStart strategy.

type TurnAnalyzerConfig

type TurnAnalyzerConfig struct {
	// Analyzer is the end-of-turn model (e.g. Smart Turn V3). Required.
	Analyzer turn.Analyzer
	// WaitForTranscript holds the turn open until a transcript arrives; nil
	// defaults to true. Set false for realtime services that bypass STT.
	WaitForTranscript *bool
}

TurnAnalyzerConfig configures a TurnAnalyzerStop strategy.

type TurnAnalyzerStop

type TurnAnalyzerStop struct {
	StopStrategyBase
	// contains filtered or unexported fields
}

TurnAnalyzerStop ends a turn using an end-of-turn model fed the user's audio, gated on a finalized transcript (or a safety-net timeout). This is the Smart-Turn stop strategy.

func NewTurnAnalyzerStop

func NewTurnAnalyzerStop(cfg TurnAnalyzerConfig) *TurnAnalyzerStop

NewTurnAnalyzerStop builds a Smart-Turn stop strategy.

func (*TurnAnalyzerStop) Cleanup

func (s *TurnAnalyzerStop) Cleanup()

Cleanup releases what the analyzer holds and stops the timeout.

The analyzer stays usable, since the strategy itself may be set up again when the strategies are updated; it reacquires what it released when the next turn needs it.

func (*TurnAnalyzerStop) Process

Process feeds the analyzer and decides end-of-turn.

func (*TurnAnalyzerStop) SetWaitForTranscript added in v0.2.0

func (s *TurnAnalyzerStop) SetWaitForTranscript(wait bool)

SetWaitForTranscript changes it for the turns that follow.

func (*TurnAnalyzerStop) Setup added in v0.1.0

func (s *TurnAnalyzerStop) Setup(st processor.Setup) error

Setup tells the analyzer the pipeline's input rate, which is known before any audio arrives. A chain whose analyzer could not be built fails here, which is the first point that can say so.

func (*TurnAnalyzerStop) TurnStarted added in v0.1.0

func (s *TurnAnalyzerStop) TurnStarted()

TurnStarted resets the bookkeeping but keeps the analyzer's buffered pre-speech audio for the turn now beginning.

func (*TurnAnalyzerStop) TurnStopped added in v0.1.0

func (s *TurnAnalyzerStop) TurnStopped()

TurnStopped resets the bookkeeping and clears the analyzer's buffered speech.

func (*TurnAnalyzerStop) WaitForTranscript added in v0.2.0

func (s *TurnAnalyzerStop) WaitForTranscript() bool

WaitForTranscript reports whether the turn is held open for a transcript.

type UserIdleController

type UserIdleController struct {
	// contains filtered or unexported fields
}

UserIdleController fires IdleConfig.Callback when the conversation stays quiet after the bot finishes speaking. It is owned by a UserTurnProcessor, which feeds it every frame plus synthetic user-speaking frames on its turn decisions. The timer arms on BotStoppedSpeakingFrame (only when no user turn is in progress and no tool calls are pending) and is canceled by bot/user speech onset or a tool call.

A UserIdleTimeoutUpdateFrame applies at once: it restarts a running timer with the new duration and, while the bot waits for the user to speak, arms the timer even when idle detection was disabled before.

func NewUserIdleController

func NewUserIdleController(cfg IdleConfig) *UserIdleController

NewUserIdleController builds a user-idle controller.

func (*UserIdleController) Broadcast

func (c *UserIdleController) Broadcast(ctx context.Context, build func() frames.Frame) error

Broadcast sends a frame both downstream and upstream (for use from the callback), building a separate instance for each direction.

func (*UserIdleController) Cleanup

func (c *UserIdleController) Cleanup()

Cleanup cancels any pending timer.

func (*UserIdleController) FunctionCallsInProgress added in v0.3.0

func (c *UserIdleController) FunctionCallsInProgress() bool

FunctionCallsInProgress reports whether function calls have started and not finished.

func (*UserIdleController) Process

func (c *UserIdleController) Process(f frames.Frame)

Process updates idle state from one frame and arms/cancels the timer.

func (*UserIdleController) Push

Push sends a frame to the neighbor in dir (for use from the callback).

func (*UserIdleController) Setup

func (c *UserIdleController) Setup(ctx context.Context, emit Emitter)

Setup records the session context and the emitter used by the callback.

func (*UserIdleController) Stop added in v0.1.0

func (c *UserIdleController) Stop()

Stop cancels any pending timer. Its owner calls it at the end of the session, so the timer cannot report an idleness that only means the session is over.

It has no Start to pair with: the timer is created in response to speech rather than at the start of the session, so there is nothing to bring up.

func (*UserIdleController) WaitForUser added in v0.3.0

func (c *UserIdleController) WaitForUser()

WaitForUser starts waiting for the user after a turn the bot will not answer.

The timer normally starts when the bot stops speaking. A user turn that ends with nothing for the bot to answer (no transcript, say) cancels the timer without the bot speaking again afterwards, so the caller re-arms it here. It does nothing while the bot is speaking, a user turn is in progress, or function calls are pending.

func (*UserIdleController) WaitingForUser added in v0.3.0

func (c *UserIdleController) WaitingForUser() bool

WaitingForUser reports whether the bot has finished responding and is waiting for the user. It is false while the bot is thinking, speaking or running a function call, and during a user turn.

type UserTurnController

type UserTurnController struct {
	// contains filtered or unexported fields
}

UserTurnController runs the start and stop strategy chains and owns the user-turn state machine: the decisions the strategies have made, the turn's inference, and a stop-timeout watchdog.

How a turn starts and ends follows the StartMode and StopMode of its UserTurnStrategiesParams. With StrategyModeFirst the first strategy to decide starts or ends the turn. With StrategyModeAll the turn starts or ends once every strategy in the list has decided. Turns start on the first start strategy and end once every stop strategy agrees by default. A stop strategy that waits for the turn's inference gets its say in either mode: in a StrategyModeFirst list, the first stop strategy to decide runs the inference, and the turn ends once a strategy waiting for that inference decides. A canceled answer voids the stop decisions made on it.

In a StrategyModeAll list the controller starts the turn's inference itself, once every stop strategy that listens to the user has decided. A stop strategy that waits for the inference instead, such as one reading the LLM's turn-completion marker, then decides on that inference. An eager end of turn still starts its speculation at once.

A single mutex serializes every state mutation. Process and all strategy timer callbacks acquire it, so strategies need no locking of their own.

func NewUserTurnController

func NewUserTurnController(strategies UserTurnStrategies, stopTimeout time.Duration) *UserTurnController

NewUserTurnController builds a controller with the default UserTurnStrategiesParams. A zero stopTimeout uses 5s; empty strategy lists fall back to the defaults.

func NewUserTurnControllerWithParams added in v0.3.0

func NewUserTurnControllerWithParams(
	strategies UserTurnStrategies, params UserTurnStrategiesParams, stopTimeout time.Duration,
) *UserTurnController

NewUserTurnControllerWithParams builds a controller whose strategies decide as params says. A zero stopTimeout uses 5s; empty strategy lists fall back to the defaults.

func (*UserTurnController) Cleanup

func (c *UserTurnController) Cleanup()

Cleanup stops the watchdog and cleans up the strategies.

func (*UserTurnController) Locked added in v0.1.0

func (c *UserTurnController) Locked(fn func())

Locked runs fn with the controller's lock held, so a caller can keep its own turn-scoped state in step with the decisions the strategies make.

A strategy decides a turn is over from a timer, and the whole stop sequence runs from that timer under this lock: the inference trigger and the finalization that follows it are one indivisible step. State a caller updates through here therefore cannot land in the middle of that step, only before or after it, which is what keeps a turn's end from being observed half-made.

fn must not push frames or re-enter the controller.

func (*UserTurnController) Process

func (c *UserTurnController) Process(f frames.Frame)

Process taps one frame: it updates the speaking state, re-arms the watchdog, and hands the frame to the start then the stop strategies. It holds the mutex throughout, so the strategies' synchronous callbacks run safely without re-locking.

func (*UserTurnController) ProcessFromHook added in v0.3.0

func (c *UserTurnController) ProcessFromHook(f frames.Frame)

ProcessFromHook is Process for a caller already running inside one of the controller's hooks, which hold its mutex. It is how the owner hands the strategies the LLMContextFrame it pushes for the turn's inference, so a stop strategy that waits for the inference waits for that one.

func (*UserTurnController) ResolvesProposedTurnStartFrames added in v0.1.0

func (c *UserTurnController) ResolvesProposedTurnStartFrames() bool

ResolvesProposedTurnStartFrames reports whether any active start strategy resolves proposed turn starts.

A proposal is resolved once, so a caller holding this controller stops forwarding a ProposedUserStartedSpeakingFrame when this is true: passing it along would let a resolver further down the pipeline decide the same turn a second time.

func (*UserTurnController) ResolvesProposedTurnStopFrames added in v0.1.0

func (c *UserTurnController) ResolvesProposedTurnStopFrames() bool

ResolvesProposedTurnStopFrames is the end-of-turn counterpart to ResolvesProposedTurnStartFrames.

func (*UserTurnController) SetHooks

func (c *UserTurnController) SetHooks(h ControllerHooks)

SetHooks installs the upward callbacks. Call before Setup.

func (*UserTurnController) Setup

Setup records the session context and binds each strategy to the shared environment.

func (*UserTurnController) Stop added in v0.1.0

func (c *UserTurnController) Stop()

Stop tears the turn watchdog down, leaving the strategies alone. Its owner calls it at the end of the session: left running the watchdog reports what ending looks like rather than a turn that really stalled, since no turn finishes once the session is over. The strategies may be shared, so cleaning them up waits for Cleanup.

func (*UserTurnController) Strategies added in v0.1.0

func (c *UserTurnController) Strategies() UserTurnStrategies

Strategies are the chains the controller is currently running.

func (*UserTurnController) StrategiesParams added in v0.3.0

func (c *UserTurnController) StrategiesParams() UserTurnStrategiesParams

StrategiesParams is how the controller's strategies decide.

func (*UserTurnController) UpdateStrategies added in v0.1.0

func (c *UserTurnController) UpdateStrategies(strategies UserTurnStrategies) error

UpdateStrategies replaces the current strategies with the given ones. The chains that go are cleaned up and the ones that arrive are set up with the same pipeline configuration the controller was given, so a caller swapping them does not have to hand it over again. The decisions the old strategies made go with them.

Empty chains fall back to the defaults, as they do at construction.

type UserTurnProcessor

type UserTurnProcessor struct {
	*processor.Base
	// contains filtered or unexported fields
}

UserTurnProcessor manages the user-turn lifecycle as a processor of its own.

It drives a UserTurnController, which runs the configured start and stop strategies, and a UserIdleController. What reaches the pipeline (the user speaking frames, the interruption) depends on which strategy decided and what it asked for.

Use it where the turn decision has to be made once and shared: several aggregators fanning off one turn, or a pipeline that wants the decision at a particular point rather than inside the aggregator. Where one aggregator owns the turn, configure the strategies on it instead with aggregators.WithTurns, which keeps the decision on the same frames as the aggregation.

func NewUserTurnProcessor

func NewUserTurnProcessor(cfg Config) *UserTurnProcessor

NewUserTurnProcessor builds a turn processor from the given configuration.

func (*UserTurnProcessor) Cleanup

func (p *UserTurnProcessor) Cleanup(ctx context.Context) error

Cleanup releases what the controllers hold. It is the one call that happens exactly once, which is why releasing a shared strategy belongs here rather than at the end of the session: an ordinary session ends and is then torn down, and a controller releasing what it took twice hands it back once more than it took it.

func (*UserTurnProcessor) Controller added in v0.1.0

func (p *UserTurnProcessor) Controller() *UserTurnController

Controller is the turn controller this processor drives, so a caller can read the strategies in force or replace them.

func (*UserTurnProcessor) ProcessFrame

func (p *UserTurnProcessor) ProcessFrame(
	ctx context.Context, f frames.Frame, dir processor.Direction,
) error

ProcessFrame gives each frame to the controllers and forwards it.

The frame is forwarded before the controllers see it, so the decisions they raise are queued behind the frame that caused them rather than ahead of it.

func (*UserTurnProcessor) Push

Push implements Emitter, so the idle controller's callback can reach the pipeline.

func (*UserTurnProcessor) Setup

Setup wires the controllers.

type UserTurnResumedParams added in v0.3.0

type UserTurnResumedParams struct {
	// EnableInterruptions reports whether the turn interrupts the bot, as
	// decided when it started.
	EnableInterruptions bool
	// InferenceTriggered reports whether the turn's inference was already
	// triggered. The new speech voids the answer it started.
	InferenceTriggered bool
}

UserTurnResumedParams describes the user speaking again in an open turn.

type UserTurnSpeculation added in v0.2.0

type UserTurnSpeculation struct {
	// Text is the user turn text the inference was run against.
	Text string
	// Perception is how the user said it, as read at the eager end of turn,
	// or nil. Part of expressive conversation (alpha).
	Perception []expressive.PerceptionSignal
}

UserTurnSpeculation is a speculative inference a stop strategy has in flight.

It is produced from an eager end of turn: the turn is not over yet, so the inference runs against a provisional conversation and its reply is held back until the turn is confirmed.

type UserTurnStartedParams

type UserTurnStartedParams struct {
	// EnableInterruptions broadcasts an InterruptionFrame so the bot is barged
	// in on turn start.
	EnableInterruptions bool
	// EnableUserSpeakingFrames broadcasts a UserStartedSpeakingFrame on turn
	// start. External integrations disable this when they emit it themselves.
	EnableUserSpeakingFrames bool
}

UserTurnStartedParams describes how a start strategy wants a turn opened.

func DefaultStartedParams

func DefaultStartedParams() UserTurnStartedParams

DefaultStartedParams is the params a typical start strategy uses.

type UserTurnStoppedParams

type UserTurnStoppedParams struct {
	// EnableUserSpeakingFrames broadcasts a UserStoppedSpeakingFrame on turn
	// stop.
	EnableUserSpeakingFrames bool
	// ConfirmsSpeculation reports that this turn end confirms a speculative
	// reply that was already generated. The reply is waiting on the turn frame
	// this emits, so running the model again would answer the same turn twice.
	ConfirmsSpeculation bool
}

UserTurnStoppedParams describes how a stop strategy wants a turn closed.

func DefaultStoppedParams

func DefaultStoppedParams() UserTurnStoppedParams

DefaultStoppedParams is the params a typical stop strategy uses.

type UserTurnStrategies

type UserTurnStrategies struct {
	Start []StartStrategy
	Stop  []StopStrategy
	// contains filtered or unexported fields
}

UserTurnStrategies holds the start and stop strategy chains a controller runs.

How each chain reaches its decision follows the StartMode and StopMode of the UserTurnStrategiesParams it runs with: by default the first start strategy to decide starts the turn, and the turn ends once every stop strategy agrees.

Empty chains use the defaults: VAD and transcription to start, the Smart Turn v3 model to stop. An application's strategies replace the ones a service recommends, unless UserTurnStrategiesParams extends a list.

func ClassifierUserTurnStrategies added in v0.3.0

func ClassifierUserTurnStrategies(stop []StopStrategy, cfg ClassifierStopConfig) (UserTurnStrategies, error)

ClassifierUserTurnStrategies builds stop strategies that let a classifier decide whether the user's turn is complete.

It is an alternative to FilterIncompleteUserTurnStrategies for an LLM that does not 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.

ClassifierStop, 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 cannot 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 with NewClassifierStop.

With UserTurnStrategiesParams{StopMergeMode: MergeModeExtend}, the classifier strategy and any stop strategies given join the ones a service recommends instead. It fails on a configuration without a classifier.

func EagerStrategies added in v0.2.0

func EagerStrategies(cfg EagerStrategiesConfig) UserTurnStrategies

EagerStrategies returns the strategies for a service that predicts the end of a turn before committing to it.

They are the external strategies, the service owning turn detection either way, with the stop half wrapped so a predicted end of turn is answered while the turn is still open. Use them only with a service configured to report such a prediction: without one, nothing ever speculates and these behave as the external strategies do.

func ExternalStrategies

func ExternalStrategies(cfg ExternalStrategiesConfig) UserTurnStrategies

ExternalStrategies returns strategies driven by another component in the pipeline: a service with its own turn detection, or a shared turn processor fanning turns out to several aggregators.

What the aggregator emits depends on which signal drives the turn. A ProposedUserStarted/StoppedSpeakingFrame leaves the decision here, so the aggregator pushes the turn frames and broadcasts interruptions. A UserStarted/StoppedSpeakingFrame means the emitter already announced the turn, so the aggregator emits nothing and EnableInterruptions does not apply.

func FilterIncompleteUserTurnStrategies

func FilterIncompleteUserTurnStrategies(stop []StopStrategy, cfg llm.UserTurnCompletionConfig) UserTurnStrategies

FilterIncompleteUserTurnStrategies builds a stop chain gated on the LLM's own verdict of whether the user had finished speaking.

The LLM is asked to begin every response with one of three markers: complete, incomplete short, or incomplete long. Only the complete one ends the user turn; the incomplete ones keep the turn open so the user can continue speaking and the LLM can re-evaluate later.

It keeps the stop strategies given (the defaults when there are none) and adds an LLMTurnCompletionStop, 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 either StopMode. The LLM service is configured by that strategy itself when the pipeline starts, so nothing else has to be set up.

With UserTurnStrategiesParams{StopMergeMode: MergeModeExtend}, the LLM gate and any stop strategies given join the ones a service recommends instead, such as a transcription service's own turn detection.

func (*UserTurnStrategies) ApplyRealtimeServiceMode added in v0.2.0

func (s *UserTurnStrategies) ApplyRealtimeServiceMode() (dropped, flipped []string)

ApplyRealtimeServiceMode strips the transcript dependence from these chains, for a pipeline whose conversation is driven by a speech-to-speech service.

Two things go. The transcription start strategy, because a transcript must not open a turn when the service is the one listening to the audio. And the transcript wait on every stop strategy that has one, so a turn ends as soon as the VAD or the end-of-turn model says the speech is over rather than waiting on a transcript that is beside the point.

It reports what it changed, so a caller can say so: strategies the application configured itself are worth a warning, since the mutation is not what it asked for.

func (UserTurnStrategies) ExternalInterruptions added in v0.1.0

func (s UserTurnStrategies) ExternalInterruptions() (enabled, isExternal bool)

ExternalInterruptions reports whether these chains were built by ExternalStrategies and, when they were, whether they broadcast an interruption as a proposal opens a turn.

func (UserTurnStrategies) MergeWith added in v0.3.0

MergeWith combines these strategies with the ones a service recommends, list by list as params says. recommended is nil when no service recommends any, and the defaults then stand in for it.

A list that replaces the service's is returned as it is, so an empty one still falls back to the defaults where the strategies run. A list that extends it adds the strategies given after the service's.

type UserTurnStrategiesParams added in v0.3.0

type UserTurnStrategiesParams struct {
	// StartMergeMode is how the application's start strategies combine with the
	// ones a service recommends. It defaults to MergeModeReplace.
	StartMergeMode MergeMode
	// StopMergeMode is how the application's stop strategies combine with the
	// ones a service recommends. It defaults to MergeModeReplace.
	StopMergeMode MergeMode
	// StartMode is whether the turn starts on the first start strategy that
	// decides the user started, or once every start strategy has. It defaults
	// to StrategyModeFirst, so speech or a transcript starts a turn on its own.
	// In a StrategyModeAll list every strategy is a condition the turn needs,
	// so a fallback such as TranscriptionStart, which starts a turn when the
	// VAD misses speech, belongs in a StrategyModeFirst list.
	StartMode StrategyMode
	// StopMode is 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 LLMTurnCompletionStop, decides on it in
	// either mode. The user speaking again clears the decisions made so far. It
	// defaults to StrategyModeAll.
	StopMode StrategyMode
}

UserTurnStrategiesParams is how the user turn strategies combine with a service's and decide.

A service with its own turn detection, such as a transcription service, can recommend user turn strategies. Only the application sets these parameters: a service's recommendation contributes its lists. The zero value is the defaults.

func (UserTurnStrategiesParams) ReplacesServiceStrategies added in v0.3.0

func (p UserTurnStrategiesParams) ReplacesServiceStrategies() bool

ReplacesServiceStrategies reports whether the application's strategies replace both of a service's lists.

type VADStart

type VADStart struct {
	StartStrategyBase
}

VADStart opens a user turn as soon as the VAD reports speech.

func NewVADStart

func NewVADStart() *VADStart

NewVADStart builds a VAD-based start strategy.

func (*VADStart) Process

func (s *VADStart) Process(f frames.Frame) ProcessFrameResult

Process reports the user started on a VAD speech-start.

type WakePhraseStart

type WakePhraseStart struct {
	StartStrategyBase
	// contains filtered or unexported fields
}

WakePhraseStart requires a spoken wake phrase before interaction.

It starts a turn when it hears a wake phrase in a final transcript, and then, until the timeout, whenever the user starts speaking or a final transcript arrives, which covers speech the VAD missed. Use SingleActivation to require the phrase before every turn. Speech before the wake phrase is dropped from the aggregation.

It starts turns on its own, so use it as the only start strategy:

turns.UserTurnStrategies{
    Start: []turns.StartStrategy{turns.NewWakePhraseStart(turns.WakePhraseStartConfig{
        Phrases: []string{"hey jargo"},
    })},
}

To combine it with other start strategies, such as MinWordsStart, put them in a StrategyModeAll list, where it is one more condition a turn needs. In a StrategyModeFirst list next to other start strategies it has to come first: until it hears the wake phrase it keeps the strategies after it from seeing frames, and once awake it starts turns itself, so the strategies after it no longer decide. That is deprecated, along with ProcessFrameResult.

func NewWakePhraseStart

func NewWakePhraseStart(cfg WakePhraseStartConfig) *WakePhraseStart

NewWakePhraseStart builds a wake-phrase start strategy.

func (*WakePhraseStart) Cleanup

func (s *WakePhraseStart) Cleanup()

Cleanup stops the inactivity timer.

func (*WakePhraseStart) Process

Process matches the wake phrase while asleep, and starts turns and keeps the session alive while awake.

It returns Stop until the wake phrase is heard, which keeps the strategies after this one in a StrategyModeFirst list from seeing the frame. That gating is deprecated, along with ProcessFrameResult.

func (*WakePhraseStart) TurnStarted added in v0.1.0

func (s *WakePhraseStart) TurnStarted()

TurnStarted readies the strategy for a new turn.

In timeout mode it keeps the state and refreshes the timeout: a turn starting is the activity that keeps the strategy awake. In single-activation mode it does nothing, because the keepalive window opened when the phrase was detected is what puts the strategy back to sleep, and cutting it short here would block the very turn the phrase opened.

type WakePhraseStartConfig

type WakePhraseStartConfig struct {
	// Phrases are the wake phrases (case-insensitive, whitespace-flexible).
	Phrases []string
	// Timeout is how long the session stays awake without activity; 0 uses 10s.
	// In timeout mode the timer resets on activity (user or bot speech). In
	// single-activation mode it acts as a keepalive window: the strategy stays
	// awake for this long after the phrase is detected, which is what lets the
	// turn it opened run to completion before it sleeps again.
	Timeout time.Duration
	// SingleActivation requires the phrase again for every turn: the strategy
	// returns to sleep once the keepalive window closes.
	SingleActivation bool
	// OnWakePhraseDetected is called with the phrase that matched. It runs with
	// the turn lock held, so it must not block or push frames.
	OnWakePhraseDetected func(phrase string)
	// OnWakePhraseTimeout is called when the inactivity timeout expires and the
	// strategy goes back to sleep. Same rules as OnWakePhraseDetected.
	OnWakePhraseTimeout func()
}

WakePhraseStartConfig configures a WakePhraseStart strategy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL