feat(nova-sonic): add proactive session continuation for conversations >8min
Nova Sonic sessions have an AWS-imposed ~8-minute time limit. This adds transparent session continuation that rotates sessions in the background before the limit is reached, preserving conversation context with no user-perceptible interruption. Implementation follows the AWS reference architecture: - Monitor loop detects when session age exceeds threshold - On assistant AUDIO contentStart: start buffering user audio, create next session (sessionStart + promptStart + system instruction) - Track SPECULATIVE/FINAL text counts as completion signal - On completion signal: send conversation history + audioInputStart + buffered audio to next session, then promote immediately - Close old session in background (non-blocking) - Dead session detection: recreate next session if idle >30s Key design decisions: - Session continuation enabled by default (fundamental for long conversations) - Conversation history tracked in real-time via _sc_conversation_history (independent of pipeline context aggregator which updates asynchronously) - Completion signal check in _handle_content_end_event (after history update) to ensure latest text is included in handoff - Rolling audio buffer (default 3s) captures user audio during transition - transition_threshold_seconds capped at 420s (7min) for safety margin - Unified event methods (_send_text_event, _send_client_event, etc.) accept optional stream/prompt_name params, eliminating duplicate SC methods Also adds: - SessionContinuationParams config (enabled, threshold, buffer, timeout)
This commit is contained in:
@@ -30,6 +30,7 @@ from pipecat.processors.aggregators.llm_response_universal import (
|
||||
from pipecat.runner.types import RunnerArguments
|
||||
from pipecat.runner.utils import create_transport
|
||||
from pipecat.services.aws.nova_sonic.llm import AWSNovaSonicLLMService
|
||||
from pipecat.services.aws.nova_sonic.session_continuation import SessionContinuationParams
|
||||
from pipecat.services.llm_service import FunctionCallParams
|
||||
from pipecat.transports.base_transport import BaseTransport, TransportParams
|
||||
from pipecat.transports.daily.transport import DailyParams
|
||||
@@ -132,6 +133,16 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
||||
voice="tiffany",
|
||||
system_instruction=system_instruction,
|
||||
),
|
||||
# Session continuation is enabled by default, allowing seamless
|
||||
# conversations longer than the AWS ~8-minute session limit.
|
||||
# The service rotates sessions in the background with no
|
||||
# user-perceptible interruption. You can tune the threshold or
|
||||
# disable it with: session_continuation=SessionContinuationParams(enabled=False)
|
||||
session_continuation=SessionContinuationParams(
|
||||
# When to start preparing the next session (default: 360 = 6 min).
|
||||
# Lower this (e.g. 20) to see a handoff happen quickly during testing.
|
||||
transition_threshold_seconds=360,
|
||||
),
|
||||
# you could choose to pass tools here rather than via context
|
||||
# tools=tools
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user