Repository: livekit/agents
File: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realtime/realtime_model.py (Python)

Code before:
                    if self._chat_ctx_ready and not self._chat_ctx_ready.done():
                        logger.warning(
                            "Chat context not received after 500ms, proceeding with empty chat context"  # noqa: E501
                        )

            logger.info(
                f"Initializing Bedrock session with realtime options: {self._realtime_model._opts}"
            )
            # there is a 40-message limit on the chat context
            if len(self._chat_ctx.items) > MAX_MESSAGES:
                logger.warning(
                    f"Chat context has {len(self._chat_ctx.items)} messages, truncating to {MAX_MESSAGES}"  # noqa: E501
                )
                self._chat_ctx.truncate(max_items=MAX_MESSAGES)

            # On restart, ensure chat history starts with USER (Nova Sonic requirement)
            restart_ctx = self._chat_ctx
            if is_restart and self._chat_ctx.items:
                first_item = self._chat_ctx.items[0]
                if first_item.type == "message" and first_item.role == "assistant":
                    restart_ctx = self._chat_ctx.copy()
                    dummy_msg = restart_ctx.add_message(
                        role="user", content="[Resuming conversation]"
                    )
                    restart_ctx.items.remove(dummy_msg)
                    restart_ctx.items.insert(0, dummy_msg)
                    logger.debug("[SESSION] Added dummy USER message to start of chat history")

            init_events = self._event_builder.create_prompt_start_block(
                voice_id=self._realtime_model._opts.voice,
                sample_rate=DEFAULT_OUTPUT_SAMPLE_RATE,  # type: ignore
                system_content=self._instructions,
                chat_ctx=restart_ctx,
                tool_configuration=self._serialize_tool_config(),
                max_tokens=self._realtime_model._opts.max_tokens,
                top_p=self._realtime_model._opts.top_p,
                temperature=self._realtime_model._opts.temperature,
            )

            for event in init_events:
                await self._send_raw_event(event)
                logger.debug(f"Sent event: {event}")

            # Always create audio input task (even on restart)
            self._audio_input_task = asyncio.create_task(
                self._process_audio_input(), name="RealtimeSession._process_audio_input"
            )

            self._response_task = asyncio.create_task(
                self._process_responses(), name="RealtimeSession._process_responses"
            )

Review comment (suggestion):
```suggestion
                    dummy_msg = llm.ChatMessage(role="user", content=["[Resuming conversation]"])
                    restart_ctx.items.insert(0, dummy_msg)
```

Code after:
                    if self._instructions_ready and not self._instructions_ready.done():
                        logger.warning(
                            "Instructions not received after 500ms, proceeding with default instructions"  # noqa: E501
                        )
                    if self._chat_ctx_ready and not self._chat_ctx_ready.done():
                        logger.warning(
                            "Chat context not received after 500ms, proceeding with empty chat context"  # noqa: E501
                        )

            logger.info(
                f"Initializing Bedrock session with realtime options: {self._realtime_model._opts}"
            )
            # there is a 40-message limit on the chat context
            if len(self._chat_ctx.items) > MAX_MESSAGES:
                logger.warning(
                    f"Chat context has {len(self._chat_ctx.items)} messages, truncating to {MAX_MESSAGES}"  # noqa: E501
                )
                self._chat_ctx.truncate(max_items=MAX_MESSAGES)

            # On restart, ensure chat history starts with USER (Nova Sonic requirement)
            restart_ctx = self._chat_ctx
            if is_restart and self._chat_ctx.items:
                first_item = self._chat_ctx.items[0]
                if first_item.type == "message" and first_item.role == "assistant":
                    restart_ctx = self._chat_ctx.copy()
                    dummy_msg = llm.ChatMessage(role="user", content=["[Resuming conversation]"])
                    restart_ctx.items.insert(0, dummy_msg)
                    logger.debug("[SESSION] Added dummy USER message to start of chat history")

            init_events = self._event_builder.create_prompt_start_block(
                voice_id=self._realtime_model._opts.voice,
                sample_rate=DEFAULT_OUTPUT_SAMPLE_RATE,  # type: ignore
                system_content=self._instructions,
                chat_ctx=restart_ctx,
                tool_configuration=self._serialize_tool_config(),
                max_tokens=self._realtime_model._opts.max_tokens,
                top_p=self._realtime_model._opts.top_p,
                temperature=self._realtime_model._opts.temperature,
            )

            for event in init_events:
                await self._send_raw_event(event)
                logger.debug(f"Sent event: {event}")

            # Always create audio input task (even on restart)
            self._audio_input_task = asyncio.create_task(
                self._process_audio_input(), name="RealtimeSession._process_audio_input"
            )

            self._response_task = asyncio.create_task(
                self._process_responses(), name="RealtimeSession._process_responses"