Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions livekit-agents/livekit/agents/voice/agent_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,31 +990,57 @@ async def aclose(self) -> None:
def update_options(
self,
*,
endpointing_opts: NotGivenOr[EndpointingOptions] = NOT_GIVEN,
turn_detection: NotGivenOr[TurnDetectionMode | None] = NOT_GIVEN,
# deprecated
min_endpointing_delay: NotGivenOr[float] = NOT_GIVEN,
max_endpointing_delay: NotGivenOr[float] = NOT_GIVEN,
turn_detection: NotGivenOr[TurnDetectionMode | None] = NOT_GIVEN,
) -> None:
"""
Update the options for the agent session.

Args:
min_endpointing_delay (NotGivenOr[float], optional): The minimum endpointing delay.
max_endpointing_delay (NotGivenOr[float], optional): The maximum endpointing delay.
endpointing_opts (NotGivenOr[EndpointingOptions], optional): Endpointing options.
turn_detection (NotGivenOr[TurnDetectionMode | None], optional): Strategy for deciding
when the user has finished speaking. ``None`` reverts to automatic selection.
min_endpointing_delay: Deprecated, use ``endpointing_opts`` instead.
max_endpointing_delay: Deprecated, use ``endpointing_opts`` instead.
"""
if is_given(min_endpointing_delay):
self._opts.endpointing["min_delay"] = min_endpointing_delay
if is_given(max_endpointing_delay):
self._opts.endpointing["max_delay"] = max_endpointing_delay
if is_given(min_endpointing_delay) or is_given(max_endpointing_delay):
logger.warning(
"min_endpointing_delay and max_endpointing_delay are deprecated, "
"use endpointing_opts instead"
)
endpointing_opts = EndpointingOptions(
mode=self._opts.endpointing["mode"],
min_delay=(
min_endpointing_delay
if is_given(min_endpointing_delay)
else self._opts.endpointing["min_delay"]
),
max_delay=(
max_endpointing_delay
if is_given(max_endpointing_delay)
else self._opts.endpointing["max_delay"]
),
)

if is_given(endpointing_opts):
if (mode := endpointing_opts.get("mode")) is not None:
self._opts.endpointing["mode"] = mode
if (min_delay := endpointing_opts.get("min_delay")) is not None:
self._opts.endpointing["min_delay"] = min_delay
if (max_delay := endpointing_opts.get("max_delay")) is not None:
self._opts.endpointing["max_delay"] = max_delay

if is_given(turn_detection):
self._turn_detection = turn_detection

if self._activity is not None:
self._activity.update_options(
min_endpointing_delay=min_endpointing_delay,
max_endpointing_delay=max_endpointing_delay,
endpointing_opts=(
self._opts.endpointing if is_given(endpointing_opts) else NOT_GIVEN
),
turn_detection=turn_detection,
)

Expand Down
Loading