Stateful realtime session handle, owning a transport process.
Implemented as a GenServer that:
- subscribes to a transport (typically a
MintTransportpid) - receives raw OpenAI realtime events, normalises them into
vendor-neutral
Mojentic.Realtime.Eventvalues, and forwards each to subscribers - tracks per-turn state and dispatches
function_callitems as a batch via the configuredMojentic.LLM.Tools.Runner - submits
function_call_outputitems back through the transport and triggers the nextresponse.create
Tool batch execution
When response.done arrives with pending function calls, the
session spawns a supervised Task to run the batch so the GenServer
remains responsive to inbound WebSocket messages (e.g.
input_audio_buffer.speech_started barge-in) during execution.
The task sends {:tool_batch_done, executions, outcomes, duration_ms}
back to the session when it completes.
An :atomics-backed cancel ref is stored in the RunContext so
calling interrupt/1 mid-batch signals cancellation to any tool
that has opted in via run/3.
This module mirrors the RealtimeSession class in the Python port. The broker uses it to provide a single ergonomic entry point.
Summary
Functions
Build the vendor-specific session.update payload from a
vendor-neutral config. Mirrors the GA shape used by mojentic-py /
mojentic-ts: session.type: 'realtime', output modalities, audio
input/output blocks, etc.
Returns a specification to start this module under a supervisor.
Close the session and underlying transport.
Manually commit the input audio buffer (push-to-talk mode).
Send the initial session.update derived from the config. Called by the broker.
Manually cancel the in-flight assistant response.
Append a PCM16 binary frame to the server's audio buffer.
Send a text-mode user message and request a response.
Start a session linked to the calling process.
Subscribe to vendor-neutral events. The subscriber receives {:realtime_event, %Event{}}.
Update instructions for future assistant turns.
Types
@type t() :: pid()
Functions
Build the vendor-specific session.update payload from a
vendor-neutral config. Mirrors the GA shape used by mojentic-py /
mojentic-ts: session.type: 'realtime', output modalities, audio
input/output blocks, etc.
Returns a specification to start this module under a supervisor.
See Supervisor.
Close the session and underlying transport.
Manually commit the input audio buffer (push-to-talk mode).
Send the initial session.update derived from the config. Called by the broker.
Manually cancel the in-flight assistant response.
Append a PCM16 binary frame to the server's audio buffer.
Send a text-mode user message and request a response.
Start a session linked to the calling process.
Required opts:
:transport— pid of an established transport:transport_module— module implementing the Transport behaviour:config— Mojentic.Realtime.Config struct
Subscribe to vendor-neutral events. The subscriber receives {:realtime_event, %Event{}}.
Update instructions for future assistant turns.