quick-art-43720
08/12/2025, 5:09 PMlivekit.plugins.aws.experimental.realtime
Classes
class *RealtimeModel*(*,
voice: NotGivenOr[VOICE_ID] = NOT_GIVEN,
temperature: NotGivenOr[float] = NOT_GIVEN,
top_p: NotGivenOr[float] = NOT_GIVEN,
max_tokens: NotGivenOr[int] = NOT_GIVEN,
tool_choice: NotGivenOr[llm.ToolChoice | None] = NOT_GIVEN,
region: NotGivenOr[str] = NOT_GIVEN)
Expand source code
```
High-level entry point that conforms to the LiveKit RealtimeModel interface.
The object is very light-weight-– it mainly stores default inference options and spawns a RealtimeSession when session() is invoked.
Instantiate a new RealtimeModel.
Args
*`voice`* : `VOICE_ID | NotGiven`
Preferred voice id for Sonic TTS output. Falls back to "tiffany".
*`temperature`* : `float | NotGiven`
Sampling temperature (0-1). Defaults to DEFAULT_TEMPERATURE.
*`top_p`* : `float | NotGiven`
Nucleus sampling probability mass. Defaults to DEFAULT_TOP_P.
*`max_tokens`* : `int | NotGiven`
Upper bound for tokens emitted by the model. Defaults to DEFAULT_MAX_TOKENS.
*`tool_choice`* : `llm.ToolChoice | None | NotGiven`
Strategy for tool invocation ("auto", "required", or explicit function).
*`region`* : `str | NotGiven`
AWS region of the Bedrock runtime endpoint.
Ancestors
• livekit.agents.llm.realtime.RealtimeModel
Methods
`def *session*(self) ‑> livekit.plugins.aws.experimental.realtime.realtime_model.RealtimeSession`
Expand source code
```
Return a new RealtimeSession bound to this model instance.
class *RealtimeSession*(realtime_model: RealtimeModel)
Expand source code
```
Bidirectional streaming session against the Nova Sonic Bedrock runtime.
The session owns two asynchronous tasks:
1. _process_audio_input – pushes user mic audio and tool results to Bedrock.
2. _process_responses – receives server events from Bedrock and converts them into LiveKit abstractions such as llm.MessageGeneration.
A set of helper handlers (_handle_*) transform the low-level Bedrock JSON payloads into higher-level application events and keep _ResponseGeneration state in sync.
Create and wire-up a new realtime session.
Args
*`realtime_model`* : `RealtimeModel`
Parent model instance that stores static inference options and the Smithy Bedrock client configuration.
Ancestors
• livekit.agents.llm.realtime.RealtimeSession abc.ABC <https://docs.livekit.io/reference/python/v1/livekit/rtc/event_emitter.html#livekit.rtc.event_emitter.EventEmitter|EventEmitter> typing.Generic
Instance variables
`prop *chat_ctx* : llm.ChatContext`
Expand source code
```
prop *tools* : llm.ToolContext
Expand source code
```
Methods
`async def *aclose*(self) ‑> None`
Expand source code
```
Gracefully shut down the realtime session and release network resources.
def *clear_audio*(self) ‑> None
Expand source code
```
`def *commit_audio*(self) ‑> None`
Expand source code
```
def *emit_generation_event*(self) ‑> None
Expand source code
```
Publish a llm.GenerationCreatedEvent to external subscribers.
`def *generate_reply*(self, *, instructions: NotGivenOr[str] = NOT_GIVEN) ‑> _asyncio.Future[livekit.agents.llm.realtime.GenerationCreatedEvent]`
Expand source code
```
async def *initialize_streams*(self, is_restart: bool = False) ‑> None
Expand source code
```
Open the Bedrock bidirectional stream and spawn background worker tasks.
This coroutine is idempotent and can be invoked again when recoverable errors (e.g. timeout, throttling) require a fresh session.
Args
*`is_restart`* : `bool`, optional
Marks whether we are re-initialising an existing session after an error. Defaults to False.
`def *interrupt*(self) ‑> None`
Expand source code
```
def *push_audio*(self, frame: rtc.AudioFrame) ‑> None
Expand source code
```
Enqueue an incoming mic rtc.AudioFrame for transcription.
`def *push_video*(self, frame: rtc.VideoFrame) ‑> None`
Expand source code
```
def *truncate*(self,
*,
message_id: str,
modalities: "list[Literal['text', 'audio']]",
audio_end_ms: int,
audio_transcript: NotGivenOr[str] = NOT_GIVEN) ‑> None
Expand source code
```
`async def *update_chat_ctx*(self, chat_ctx: llm.ChatContext) ‑> None`
Expand source code
```
Inject an initial chat history once during the very first session startup.
async def *update_instructions*(self, instructions: str) ‑> None
Expand source code
```
Injects the system prompt at the start of the session.
`def *update_options*(self, *, tool_choice: NotGivenOr[llm.ToolChoice | None] = NOT_GIVEN) ‑> None`
Expand source code
```
Live update of inference options is not supported by Sonic yet.
async def *update_tools*(self, tools: list[llm.FunctionTool | llm.RawFunctionTool | Any]) ‑> None
Expand source code
``````
Replace the active tool set with tools and notify Sonic if necessary.
Inherited memberstall-airline-16756
08/12/2025, 5:09 PMtall-airline-16756
08/12/2025, 5:10 PMgenerate_reply()
method with AWS Nova Sonic in LiveKit—it’s super handy, but it needs a little guidance to work its magic:
• Make sure to give it clear instructions. For example:
speech_handle = session.generate_reply(
instructions="Tell me a fascinating fact about AI."
)
• If you try to use it without any instructions, it won’t work and will throw an error.
So, just remember to include some meaningful instructions, and you’ll be all set to get the best out of this feature!
Sources: livekit-agents/livekit/agents/voice/agent_session.py | Amazon Nova Sonic integration guide | LiveKit Docs