Documentation
¶
Overview ¶
Package livekit binds a voice.AgentSession to the current job's LiveKit room, recording, observability, report, and primary-session lifecycle.
Start is the one-step production path corresponding to AgentSession.start in the TypeScript and Python SDKs. The lower-level voice, roomio, recorderio, and telemetry packages remain available when an application needs explicit ownership of individual components.
Index ¶
- Constants
- Variables
- type ReportStats
- type Runtime
- func (r *Runtime[UserData]) Close(ctx context.Context) error
- func (r *Runtime[UserData]) CloseSession(ctx context.Context) error
- func (r *Runtime[UserData]) FinalizeSession(ctx context.Context) error
- func (r *Runtime[UserData]) Logger() *slog.Logger
- func (r *Runtime[UserData]) Primary() bool
- func (r *Runtime[UserData]) RecorderIO() *recorderio.RecorderIO
- func (r *Runtime[UserData]) RecordingOptions() voice.RecordingOptions
- func (r *Runtime[UserData]) Report() *voice.SessionReport
- func (r *Runtime[UserData]) ReportStats() ReportStats
- func (r *Runtime[UserData]) RoomIO() *roomio.RoomIO
- type StartOptions
Constants ¶
const ( DefaultEventCapacity = 256 DefaultMaxReportEvents = 4096 DefaultMaxReportBytes = 8 << 20 DefaultCloseTimeout = 30 * time.Second DefaultFinalizeTimeout = 15 * time.Minute )
Variables ¶
var ( ErrJobContextRequired = errors.New("voice/livekit: a job context is required") ErrReportEventLimit = errors.New("voice/livekit: session report event retention limit reached") )
Functions ¶
This section is empty.
Types ¶
type ReportStats ¶
type ReportStats struct {
RetainedEvents uint64
RetainedBytes uint64
DroppedEvents uint64
CaptureError error
}
ReportStats makes bounded-retention loss explicit. RetainedBytes counts the immutable canonical event bytes stored at the time of the snapshot.
type Runtime ¶
type Runtime[UserData any] struct { // contains filtered or unexported fields }
Runtime owns the components started by Start and implements agents.JobSessionLifecycle. Primary runtimes are closed and finalized by the job runner; a secondary runtime must be closed by its caller.
func Start ¶
func Start[UserData any](ctx context.Context, session *voice.AgentSession[UserData], agent *voice.Agent[UserData], options StartOptions[UserData]) (_ *Runtime[UserData], resultErr error)
Start connects the current job if needed, atomically claims the primary session role, installs bounded event capture and media IO, configures lazy Cloud telemetry when applicable, and starts the AgentSession. Every partial start is rolled back in reverse ownership order.
func (*Runtime[UserData]) Close ¶
Close performs both lifecycle stages. The job runner calls the two explicit methods itself to preserve room-disconnect ordering.
func (*Runtime[UserData]) CloseSession ¶
CloseSession implements agents.JobSessionLifecycle. Cleanup continues under an internal deadline if the caller stops waiting.
func (*Runtime[UserData]) FinalizeSession ¶
FinalizeSession creates the immutable report, persists console reports, uploads Cloud observability data when configured, and drains telemetry.
func (*Runtime[UserData]) RecorderIO ¶
func (r *Runtime[UserData]) RecorderIO() *recorderio.RecorderIO
func (*Runtime[UserData]) RecordingOptions ¶
func (r *Runtime[UserData]) RecordingOptions() voice.RecordingOptions
func (*Runtime[UserData]) Report ¶
func (r *Runtime[UserData]) Report() *voice.SessionReport
func (*Runtime[UserData]) ReportStats ¶
func (r *Runtime[UserData]) ReportStats() ReportStats
type StartOptions ¶
type StartOptions[UserData any] struct { Job *agents.JobContext[UserData] ConnectOptions agents.ConnectOptions RoomInput *roomio.RoomInputOptions RoomOutput *roomio.RoomOutputOptions RoomIO *roomio.RoomIO // Recording inherits livekit.Job.enable_recording when zero-valued. A // concrete sparse update explicitly selects its granular policy. Recording agents.Override[voice.RecordingOptionsUpdate] Recorder *recorderio.RecorderIO RecorderOptions recorderio.RecorderOptions EventCapacity int MaxReportEvents int MaxReportBytes int CloseTimeout time.Duration FinalizeTimeout time.Duration Logger *slog.Logger HTTPClient *http.Client Metadata map[string]any UploadGate *telemetry.UploadGate // ObservabilityURL overrides Cloud endpoint discovery. It must be an // origin URL; LIVEKIT_OBSERVABILITY_URL is used when this field is empty. ObservabilityURL string RecordingEndpoint string LogEndpoint string DisableCloudTelemetry bool // OnReport runs after the immutable report is assembled and before local // persistence or Cloud upload. It must honor ctx. OnReport func(context.Context, *voice.SessionReport) error // OnError receives asynchronous RoomIO and report-capture errors. Panics are // isolated. The Runtime also exposes the first capture error in ReportStats. OnError func(error) }
StartOptions controls the high-level LiveKit binding. Zero values select the production defaults. After compatibility validation succeeds, supplying RoomIO or Recorder transfers ownership to the Start transaction: the returned Runtime closes them on success and partial-start rollback closes them on failure. Callers that need borrowed ownership should compose the lower-level roomio/recorderio packages directly.