Octoroom.Agent.OpenAILive.Protocol (octoroom_agents v0.1.0)

Copy Markdown View Source

OpenAI Live API (wss://api.openai.com/v1/live/sessions, gpt-live-1.1 / gpt-live-1) wire format: client events sent to OpenAI and the events server frames decode to. Pure, so it's tested without a socket.

Summary

Functions

Decodes one incoming WebSocket frame into {:ok, [event]} or {:error, reason}.

Builds and validates the session.delegation object from :delegation and optional agent tools.

Validates idle_timeout_s (nil or an integer in 5..60).

The model name without any openai: prefix.

Validates a PCM sample rate supported by OpenAI Live (16_000 or 24_000).

The session.start frame, the first event sent on a primary WebSocket.

Validates :transport (:webrtc or :websocket).

Builds and validates session.wake_policy (nil/false, :speech, [type: :speech, vad_threshold: 0.5], or a raw map).

The JSON request body for POST /v1/live/sessions over WebRTC.

Functions

audio_input_frame(audio)

commentary_append_frame(content, opts \\ [])

decode_frame(frame, opts \\ [])

Decodes one incoming WebSocket frame into {:ok, [event]} or {:error, reason}.

default_sample_rate()

default_transport()

default_voice()

delegation(config, tools \\ [])

Builds and validates the session.delegation object from :delegation and optional agent tools.

idle_timeout_s(seconds)

Validates idle_timeout_s (nil or an integer in 5..60).

input_audio_mute_frame()

input_audio_unmute_frame()

instructions_append_frame(content, opts \\ [])

model_name(model)

The model name without any openai: prefix.

response_create_frame()

sample_rate(rate)

Validates a PCM sample rate supported by OpenAI Live (16_000 or 24_000).

session_close_frame()

session_start_frame(opts)

The session.start frame, the first event sent on a primary WebSocket.

Options:

  • :model (needed, e.g. "gpt-live-1.1")
  • :voice (default "marin")
  • :sample_rate (16_000 or 24_000, default 24_000)
  • :instructions (system prompt)
  • :delegation (:client, [type: :client], [model: "...", ...] for Responses delegation, or a raw delegation map)
  • :tools (%Octoroom.Agent.Tool{} structs or OpenAI tool maps, merged into Responses delegation when configured)
  • :idle_timeout_s (integer in 5..60, seconds of inactivity before standby; WebRTC only)
  • :wake_policy (:speech, [type: :speech, vad_threshold: 0.5], or a raw wake policy map; WebRTC only)
  • :initial_items (list of initial conversation item maps)
  • :event_id (optional client event id)

session_update_frame(session)

supported_sample_rates()

thinking_append_frame(content, opts \\ [])

tool_output_frame(call_id, output, opts \\ [])

transport(value)

Validates :transport (:webrtc or :websocket).

wake_policy(type)

Builds and validates session.wake_policy (nil/false, :speech, [type: :speech, vad_threshold: 0.5], or a raw map).

webrtc_session_request(opts, sdp)

The JSON request body for POST /v1/live/sessions over WebRTC.

Omits audio.format because WebRTC negotiates media format in SDP.