Documentation
¶
Index ¶
- Constants
- Variables
- func AreLanguagesEquivalent(left, right string) bool
- func BaseLanguage(language string) string
- func CalculateAudioDuration(frames []AudioFrame) time.Duration
- func CalculateAudioDurationSeconds(frame AudioFrame) float64
- func ConfigureFFmpeg() string
- func Dedent(value string) string
- func FFmpegCommand(ctx context.Context, args ...string) *exec.Cmd
- func ISOLanguage(language string) string
- func InferenceExecutorFromContext(ctx context.Context) (ipc.InferenceExecutor, bool)
- func InitializeLogger(options LoggerOptions) (*slog.Logger, error)
- func IsAPIError(err error) bool
- func IsAgent(value any) bool
- func IsCloud(rawURL string) bool
- func IsDevMode() bool
- func IsHosted() bool
- func LanguageName(language string) (string, bool)
- func LanguageRegion(language string) (string, bool)
- func Log() *slog.Logger
- func MustRegisterInferenceRunner(method string, factory InferenceRunnerFactory)
- func OnPluginRegistered(fn func(PluginRegisteredEvent)) func()
- func ParseLogLevel(value string) (slog.Level, error)
- func PutResource[T any](bag *ResourceBag, key string, value T) error
- func RegisterInferenceRunner(method string, factory InferenceRunnerFactory) error
- func RegisterPlugin(plugin Plugin) error
- func RegisteredInferenceRunners() map[string]InferenceRunnerFactory
- func ResolveFFmpegPath() string
- func Resource[T any](bag *ResourceBag, key string) (T, bool)
- func Run[T any](ctx context.Context, options WorkerOptions[T]) error
- func RunConsoleJob[UserData any](ctx context.Context, options ConsoleJobOptions[UserData]) (resultErr error)
- func SetLogger(logger *slog.Logger) error
- func ShortUUID(prefix string) string
- func WaitForParticipantAttribute(ctx context.Context, room *lksdk.Room, bridge *rtcbridge.RTCBridge, ...) error
- func WaitForTrackPublication(ctx context.Context, room *lksdk.Room, bridge *rtcbridge.RTCBridge, ...) (lksdk.TrackPublication, error)
- func WithConnectionResult[T comparable, R any](ctx context.Context, pool *ConnectionPool[T], ...) (R, error)
- func WithInferenceExecutor(ctx context.Context, executor ipc.InferenceExecutor) context.Context
- type APIConnectOptions
- type APIConnectionError
- type APIError
- type APIStatusError
- type APITimeoutError
- type AgentDefinition
- type AgentDefinitionOptions
- type AgentServer
- func (s *AgentServer[T]) ActiveJobs() []RunningJobInfo
- func (s *AgentServer[T]) Close(contexts ...context.Context) error
- func (s *AgentServer[T]) Drain(ctx context.Context) error
- func (s *AgentServer[T]) Draining() bool
- func (s *AgentServer[T]) Events() *EventEmitter[WorkerEvent]
- func (s *AgentServer[T]) HTTPAddress() string
- func (s *AgentServer[T]) ID() string
- func (s *AgentServer[T]) RegisterAgent(name string, entrypoint JobEntrypoint[T]) error
- func (s *AgentServer[T]) RegisterRTCSession(name string, entrypoint JobEntrypoint[T]) error
- func (s *AgentServer[T]) Registered() bool
- func (s *AgentServer[T]) Run(ctx context.Context) error
- func (s *AgentServer[T]) SimulateJob(ctx context.Context, roomName, participantIdentity string) error
- type AssignmentTimeoutError
- type AudioByteStream
- type AudioDecodeError
- type AudioDecodeOptions
- type AudioEnergyFilter
- type AudioFrame
- type AudioFrameStream
- type AutoSubscribe
- type CGroupV1CPUMonitor
- type CGroupV2CPUMonitor
- type CPUMonitor
- type ConnectOptions
- type ConnectionPool
- func (p *ConnectionPool[T]) Close(ctx context.Context) error
- func (p *ConnectionPool[T]) Get(ctx context.Context) (T, error)
- func (p *ConnectionPool[T]) Invalidate()
- func (p *ConnectionPool[T]) Len() int
- func (p *ConnectionPool[T]) Prewarm(ctx context.Context)
- func (p *ConnectionPool[T]) Put(conn T) bool
- func (p *ConnectionPool[T]) Remove(ctx context.Context, conn T) error
- func (p *ConnectionPool[T]) WithConnection(ctx context.Context, fn func(context.Context, T) error) error
- type ConnectionPoolOptions
- type ConsoleJobOptions
- type Entrypoint
- type EventEmitter
- type ExecutorMode
- type ExpFilter
- type ExpFilterOptions
- type FlushSentinel
- type FunctionExistsError
- type IdleTimeoutError
- type InferenceProcessError
- type InferenceRunner
- type InferenceRunnerFactory
- type InferenceRunnerFuncs
- type JobAcceptArguments
- type JobAcceptOptions
- type JobContext
- func (j *JobContext[T]) AddParticipantEntrypoint(callback ParticipantEntrypoint[T]) error
- func (j *JobContext[T]) AddShutdownCallback(callback ShutdownCallback) error
- func (j *JobContext[T]) Agent() *lksdk.LocalParticipant
- func (j *JobContext[T]) Connect(ctx context.Context, opts ConnectOptions) error
- func (j *JobContext[T]) Context() context.Context
- func (j *JobContext[T]) DeleteRoom(ctx context.Context, name string) error
- func (j *JobContext[T]) Done() <-chan struct{}
- func (j *JobContext[T]) InferenceExecutor() ipc.InferenceExecutor
- func (j *JobContext[T]) Info() RunningJobInfo
- func (j *JobContext[T]) IsConnected() bool
- func (j *JobContext[T]) IsFakeJob() bool
- func (j *JobContext[T]) Job() *livekit.Job
- func (j *JobContext[T]) Process() *JobProcess[T]
- func (j *JobContext[T]) RTCBridge() *rtcbridge.RTCBridge
- func (j *JobContext[T]) RegisterSession(options JobSessionRegistrationOptions) (*JobSessionRegistration, error)
- func (j *JobContext[T]) Room() *lksdk.Room
- func (j *JobContext[T]) SessionDirectory() string
- func (j *JobContext[T]) Shutdown(reason string)
- func (j *JobContext[T]) ShutdownReason() string
- func (j *JobContext[T]) SimulationContext() (*SimulationContext[T], bool)
- func (j *JobContext[T]) State() *T
- func (j *JobContext[T]) WaitForParticipant(ctx context.Context, identity string, kinds ...lksdk.ParticipantKind) (*lksdk.RemoteParticipant, error)
- func (j *JobContext[T]) WaitForParticipantAttribute(ctx context.Context, identity, attribute, value string) error
- func (j *JobContext[T]) WaitForTrackPublication(ctx context.Context, options WaitForTrackPublicationOptions) (lksdk.TrackPublication, error)
- func (j *JobContext[T]) WorkerID() string
- type JobEntrypoint
- type JobProcess
- type JobRejectOptions
- type JobRequest
- func (r *JobRequest) Accept(ctx context.Context, opts JobAcceptOptions) error
- func (r *JobRequest) AgentName() string
- func (r *JobRequest) Answered() bool
- func (r *JobRequest) ID() string
- func (r *JobRequest) Job() *livekit.Job
- func (r *JobRequest) Publisher() *livekit.ParticipantInfo
- func (r *JobRequest) Reject(ctx context.Context, opts JobRejectOptions) error
- func (r *JobRequest) Resuming() bool
- func (r *JobRequest) Room() *livekit.Room
- type JobSessionLifecycle
- type JobSessionLifecycleFuncs
- type JobSessionRegistration
- type JobSessionRegistrationOptions
- type LanguageCode
- type LoadFunc
- type LocalInferenceExecutor
- func (e *LocalInferenceExecutor) Close(ctx context.Context) error
- func (e *LocalInferenceExecutor) DoInference(ctx context.Context, method string, data any) (result any, err error)
- func (e *LocalInferenceExecutor) HasInferenceRunners() bool
- func (e *LocalInferenceExecutor) Healthy() error
- func (e *LocalInferenceExecutor) Initialize(ctx context.Context) error
- type LogFormat
- type LoggerOptions
- type MissingCredentialsError
- type Override
- type ParticipantEntrypoint
- type ParticipantNotFoundError
- type ParticipantWaitDisconnectedError
- type Plugin
- type PluginRegisteredEvent
- type PrewarmFunc
- type RequestHandler
- type ResolvedLoggerOptions
- type ResourceBag
- type RunningJobInfo
- type RuntimeCPUMonitor
- type Scenario
- type ScenarioGroup
- type ScenarioUserdata
- type SecretString
- type ServerOptions
- type ServerType
- type SessionConnectOptions
- type ShutdownCallback
- type SimulationContext
- func (s *SimulationContext[T]) BeginFinalize(verdict SimulationVerdict, run *SimulationRun)
- func (s *SimulationContext[T]) Dispatch() *SimulationDispatch
- func (s *SimulationContext[T]) EffectiveVerdict() (SimulationVerdict, error)
- func (s *SimulationContext[T]) Fail(reason string)
- func (s *SimulationContext[T]) JobContext() *JobContext[T]
- func (s *SimulationContext[T]) JobID() string
- func (s *SimulationContext[T]) Mode() SimulationMode
- func (s *SimulationContext[T]) Run() (*SimulationRun, bool)
- func (s *SimulationContext[T]) RunID() string
- func (s *SimulationContext[T]) Scenario() *Scenario
- func (s *SimulationContext[T]) SimulatorVerdict() (SimulationVerdict, error)
- func (s *SimulationContext[T]) UserVerdict() (SimulationVerdict, bool)
- func (s *SimulationContext[T]) Userdata() (ScenarioUserdata, error)
- type SimulationDispatch
- type SimulationEndFunc
- type SimulationMode
- type SimulationRun
- type SimulationRunJob
- type SimulationVerdict
- type TimedString
- type TimedStringOptions
- type UnexpectedModelBehavior
- type WaitForTrackPublicationOptions
- type Worker
- type WorkerError
- type WorkerEvent
- type WorkerEventType
- type WorkerOptions
- type WorkerPermissions
Constants ¶
const ( // UserdataTimedTranscript stores timed transcripts on an AudioFrame. UserdataTimedTranscript = "lk.timed_transcripts" // UserdataTTSStartedTime stores when text was first sent to TTS. UserdataTTSStartedTime = "lk.tts_started_time" AttributeSimulator = "lk.simulator" AttributeSimulatorDispatch = "lk.simulator.dispatch" AttributeSimulationEnabled = "lk.simulation.enabled" AttributeSimulationRunID = "lk.simulation.run_id" AttributeSimulationJobID = "lk.simulation.job_id" AttributeRedactionEnabled = "lk.redaction.enabled" AttributeTranscriptionExpression = "lk.expression" )
const ( CPUCountEnvironment = "NUM_CPUS" DefaultCPUSampleInterval = 500 * time.Millisecond DefaultCGroupV1CPUCount = 2.0 )
const ( // FFmpegPathEnvironment is the TypeScript-compatible executable override. FFmpegPathEnvironment = "LIVEKIT_FFMPEG_PATH" // FFmpegPathEnv is retained as the shorter compatibility spelling. FFmpegPathEnv = FFmpegPathEnvironment )
const ( SubscribeAll AutoSubscribe = iota SubscribeNone SubscribeVideoOnly SubscribeAudioOnly // Upper-case aliases make mechanical TypeScript/Python migrations easier. SUBSCRIBE_ALL = SubscribeAll SUBSCRIBE_NONE = SubscribeNone VIDEO_ONLY = SubscribeVideoOnly AUDIO_ONLY = SubscribeAudioOnly )
const ( LogFormatJSON LogFormat = "json" LogFormatText LogFormat = "text" LogLevelTrace slog.Level = slog.LevelDebug - 4 LogLevelSilent slog.Level = slog.LevelError + 100 )
const ( SimulationModeUnspecified = livekit.SimulationMode_SIMULATION_MODE_UNSPECIFIED SimulationModeText = livekit.SimulationMode_SIMULATION_MODE_TEXT SimulationModeAudio = livekit.SimulationMode_SIMULATION_MODE_AUDIO // Upper-case aliases ease mechanical TypeScript/protobuf migrations. SIMULATION_MODE_UNSPECIFIED = SimulationModeUnspecified SIMULATION_MODE_TEXT = SimulationModeText SIMULATION_MODE_AUDIO = SimulationModeAudio )
const ( DefaultMaxReconnects = 10 DefaultAssignmentTimeout = 7500 * time.Millisecond DefaultStatusUpdateInterval = 2500 * time.Millisecond DefaultDrainTimeout = time.Hour DefaultShutdownProcessTimeout = time.Minute DefaultInitializeTimeout = 10 * time.Second DefaultJobMemoryWarnMB = 1000 DefaultWorkerPort = 8081 AttributeAgentName = "lk.agent.name" )
const ( ServerTypeRoom = livekit.JobType_JT_ROOM ServerTypePublisher = livekit.JobType_JT_PUBLISHER )
const DefaultAudioEnergyThreshold = 0.004
const DefaultInferenceInitializeTimeout = 5 * time.Minute
Variables ¶
var ( ErrInvalidAudioFormat = errors.New("invalid audio format") ErrIncompletePCMFrame = errors.New("incomplete PCM16 frame") )
var ( // cannot accept a request. It is safe to use with errors.Is. ErrInferenceProcessUnavailable = errors.New("agents: inference process is unavailable") // ErrInferenceProcessCrashed reports an unexpected runner-child exit. ErrInferenceProcessCrashed = errors.New("agents: inference process crashed") // ErrInferenceConcurrencyLimit reports that the fixed-size subprocess // request budget is exhausted. Requests are not placed on an unbounded queue. ErrInferenceConcurrencyLimit = errors.New("agents: inference concurrency limit reached") // ErrInferenceRegistrationMismatch means the parent and same-binary child // did not execute the same startup registration path. ErrInferenceRegistrationMismatch = errors.New("agents: inference runner registrations differ in child process") )
var ( ErrInferenceRunnerExists = errors.New("agents: inference runner is already registered") ErrInferenceRunnerUnknown = errors.New("agents: inference runner is not registered") )
var ( ErrJobRequestAnswered = errors.New("agents: job request has already been answered") ErrRoomNotConnected = errors.New("agents: room is not connected") ErrFunctionExists = errors.New("agents: function has already been registered") )
var ( // ErrPrimarySessionRecording is returned when a secondary session // explicitly enables recording. Exactly one session owns recording and the // automatic shutdown/report lifecycle for a job. ErrPrimarySessionRecording = errors.New("agents: only the primary session may enable recording") ErrJobSessionFinishing = errors.New("agents: job session lifecycle is already finishing") )
var ( ErrNoJobCapacity = errors.New("agents: worker has no available job capacity") ErrJobNotFound = errors.New("agents: job was not found") ErrReservationReleased = errors.New("agents: job reservation was released") ErrExecutorClosed = errors.New("agents: job executor is closed") )
var DefaultAPIConnectOptions = APIConnectOptions{ MaxRetries: 3, RetryInterval: 2 * time.Second, Timeout: 10 * time.Second, }
var DefaultSessionConnectOptions = SessionConnectOptions{ STT: DefaultAPIConnectOptions, LLM: DefaultAPIConnectOptions, TTS: DefaultAPIConnectOptions, MaxUnrecoverableErrors: 3, }
var ErrInferenceExecutorClosed = errors.New("agents: inference executor is closed")
var ErrRTCBridgeRequired = errors.New("agents: a construction-time RTCBridge is required for event-driven room waits")
var KnownLanguageCodes = []LanguageCode{
"af", "am", "ar", "as", "az", "be", "bg", "bn", "bs", "ca", "cs", "cy", "da", "de",
"el", "en", "es", "et", "eu", "fa", "ff", "fi", "fr", "ga", "gl", "gu", "ha", "he",
"hi", "hr", "hu", "hy", "id", "ig", "is", "it", "ja", "jv", "ka", "kk", "km", "kn",
"ko", "ku", "ky", "lb", "lg", "ln", "lo", "lt", "lv", "mi", "mk", "ml", "mn", "mr",
"ms", "mt", "my", "ne", "nl", "no", "ny", "oc", "or", "pa", "pl", "ps", "pt", "ro",
"ru", "sd", "sk", "sl", "sn", "so", "sq", "sr", "sv", "sw", "ta", "te", "tg", "th",
"tl", "tr", "uk", "ur", "uz", "vi", "wo", "xh", "yo", "zh", "zu",
}
var Version = "v0.1.0"
Version is the semantic version of this SDK. Downstream development builds may override it with -ldflags "-X github.com/infinityscroll/livekit-agents-go.Version=vX.Y.Z".
Functions ¶
func AreLanguagesEquivalent ¶
func BaseLanguage ¶
func CalculateAudioDuration ¶
func CalculateAudioDuration(frames []AudioFrame) time.Duration
func CalculateAudioDurationSeconds ¶
func CalculateAudioDurationSeconds(frame AudioFrame) float64
func ConfigureFFmpeg ¶
func ConfigureFFmpeg() string
ConfigureFFmpeg mirrors agents-js's explicit setup hook. Go callers do not need process-global configuration, so the resolved executable is returned for dependency injection instead.
func Dedent ¶
Dedent strips a common leading run of spaces/tabs from non-empty lines, removes one initial newline, and trims trailing Unicode whitespace. It is the Go string equivalent of the agents-js dedent tagged template helper.
func FFmpegCommand ¶
FFmpegCommand constructs a cancellation-aware command using the standard SDK resolution rules. Starting the command reports the usual exec error if no executable is installed.
func ISOLanguage ¶
func InferenceExecutorFromContext ¶
func InferenceExecutorFromContext(ctx context.Context) (ipc.InferenceExecutor, bool)
InferenceExecutorFromContext returns the worker-global executor propagated to a job entrypoint without requiring the caller to know JobContext's user-data type. Model adapters use this to share native runners across isolated jobs.
func InitializeLogger ¶
func InitializeLogger(options LoggerOptions) (*slog.Logger, error)
InitializeLogger installs the logger returned by Log. It performs no work until called and never changes slog.Default unless SetDefault is true.
func IsAPIError ¶
func IsAgent ¶
IsAgent reports whether value was produced as a Go AgentDefinition. The private marker deliberately rejects look-alike structs.
func IsCloud ¶
IsCloud reports whether rawURL is hosted on a LiveKit Cloud production or run domain. Malformed and hostname-less URLs return false.
func IsDevMode ¶
func IsDevMode() bool
IsDevMode reports whether the process was launched in a LiveKit development mode such as dev, connect, or console.
func IsHosted ¶
func IsHosted() bool
IsHosted reports whether the worker is hosted by LiveKit Cloud. Presence is significant even when the environment variable is explicitly empty.
func LanguageName ¶
func LanguageRegion ¶
func Log ¶
Log returns the framework logger or slog.Default when the application has not initialized one. This makes library use safe outside the CLI.
func MustRegisterInferenceRunner ¶
func MustRegisterInferenceRunner(method string, factory InferenceRunnerFactory)
MustRegisterInferenceRunner is intended for package-level plugin registration before the executor pool starts and panics on a duplicate or invalid method. Package initialization naturally runs in the same-binary inference child required by process mode.
func OnPluginRegistered ¶
func OnPluginRegistered(fn func(PluginRegisteredEvent)) func()
func PutResource ¶
func PutResource[T any](bag *ResourceBag, key string, value T) error
func RegisterInferenceRunner ¶
func RegisterInferenceRunner(method string, factory InferenceRunnerFactory) error
RegisterInferenceRunner registers a local inference method. Registration is concurrency-safe, rejects duplicates, and allocates the registry only after the first feature package is actually imported.
Register every production method before the worker executor pool starts. Process mode re-executes the same binary and requires the factory to be linked and registered along the child startup path as well; a runtime-only closure cannot be serialized into that process. ExecutorModeInProcess is the explicit development escape hatch for parent-only dynamic registrations.
func RegisterPlugin ¶
func RegisteredInferenceRunners ¶
func RegisteredInferenceRunners() map[string]InferenceRunnerFactory
RegisteredInferenceRunners returns a defensive snapshot. An empty registry returns nil without allocating, keeping core-only process startup lean.
func ResolveFFmpegPath ¶
func ResolveFFmpegPath() string
ResolveFFmpegPath resolves LIVEKIT_FFMPEG_PATH first and then ffmpeg on PATH. It performs no work at package initialization and returns an empty string when no executable can be found.
func Run ¶
func Run[T any](ctx context.Context, options WorkerOptions[T]) error
Run constructs a worker, handles SIGINT/SIGTERM, drains, and closes it.
func RunConsoleJob ¶
func RunConsoleJob[UserData any](ctx context.Context, options ConsoleJobOptions[UserData]) (resultErr error)
RunConsoleJob executes the normal prewarm, entrypoint, job-context, and shutdown-callback lifecycle in-process. Cancellation is the console lifetime signal and is treated as a clean shutdown.
func SetLogger ¶
SetLogger installs an application-owned logger without mutating the global slog default. Passing nil is rejected instead of creating a latent panic.
func ShortUUID ¶
ShortUUID returns a URL-safe, process-independent identifier with at least 100 bits of randomness. crypto/rand.Text panics only if OS entropy fails.
func WaitForParticipantAttribute ¶
func WaitForParticipantAttribute( ctx context.Context, room *lksdk.Room, bridge *rtcbridge.RTCBridge, identity, attribute, value string, ) error
WaitForParticipantAttribute waits without polling until a remote participant's attribute equals value. bridge must be the callback bridge installed when room was constructed; server-sdk-go v2.18.1 has no safe post-construction callback registration API.
func WaitForTrackPublication ¶
func WaitForTrackPublication( ctx context.Context, room *lksdk.Room, bridge *rtcbridge.RTCBridge, options WaitForTrackPublicationOptions, ) (lksdk.TrackPublication, error)
WaitForTrackPublication waits without polling for a matching local or remote publication and returns the SDK-owned publication handle.
func WithConnectionResult ¶
func WithConnectionResult[T comparable, R any](ctx context.Context, pool *ConnectionPool[T], fn func(context.Context, T) (R, error)) (R, error)
func WithInferenceExecutor ¶
WithInferenceExecutor explicitly propagates an executor to model/session constructors outside a worker entrypoint. It is useful for console hosts and tests; a typed nil executor leaves the context unchanged.
Types ¶
type APIConnectOptions ¶
APIConnectOptions controls timeout and retry behavior for provider calls. Zero fields resolve to DefaultAPIConnectOptions. Set MaxRetries to a negative value to explicitly disable retries.
func (APIConnectOptions) Resolve ¶
func (o APIConnectOptions) Resolve() APIConnectOptions
Resolve returns a validated, fully populated copy.
func (APIConnectOptions) RetryDelay ¶
func (o APIConnectOptions) RetryDelay(n int) time.Duration
RetryDelay returns the delay before retry number n. The first retry is fast, matching the Python and TypeScript SDKs.
type APIConnectionError ¶
type APIConnectionError struct{ *APIError }
func NewAPIConnectionError ¶
func NewAPIConnectionError(message string, retryable bool, cause error) *APIConnectionError
func (*APIConnectionError) Unwrap ¶
func (e *APIConnectionError) Unwrap() error
type APIError ¶
APIError is returned by STT, LLM, TTS, VAD, and inference providers.
func NewAPIError ¶
type APIStatusError ¶
func NewAPIStatusError ¶
func (*APIStatusError) Error ¶
func (e *APIStatusError) Error() string
func (*APIStatusError) Unwrap ¶
func (e *APIStatusError) Unwrap() error
type APITimeoutError ¶
type APITimeoutError struct{ *APIConnectionError }
func NewAPITimeoutError ¶
func NewAPITimeoutError(message string, retryable bool, cause error) *APITimeoutError
func (*APITimeoutError) Unwrap ¶
func (e *APITimeoutError) Unwrap() error
type AgentDefinition ¶
type AgentDefinition[T any] struct { // contains filtered or unexported fields }
AgentDefinition is the validated worker module used by agents-js defineAgent. Its fields are immutable after construction so it can be shared safely between server setup and process executors.
func DefineAgent ¶
func DefineAgent[T any](options AgentDefinitionOptions[T]) (*AgentDefinition[T], error)
func MustDefineAgent ¶
func MustDefineAgent[T any](options AgentDefinitionOptions[T]) *AgentDefinition[T]
func (*AgentDefinition[T]) Entrypoint ¶
func (d *AgentDefinition[T]) Entrypoint() JobEntrypoint[T]
func (*AgentDefinition[T]) Prewarm ¶
func (d *AgentDefinition[T]) Prewarm() PrewarmFunc[T]
func (*AgentDefinition[T]) SimulationEnd ¶
func (d *AgentDefinition[T]) SimulationEnd() SimulationEndFunc[T]
type AgentDefinitionOptions ¶
type AgentDefinitionOptions[T any] struct { Entrypoint JobEntrypoint[T] Prewarm PrewarmFunc[T] OnSimulationEnd SimulationEndFunc[T] }
type AgentServer ¶
type AgentServer[T any] struct { // contains filtered or unexported fields }
AgentServer owns worker registration, job reservations, executors, health serving, reconnection, and graceful draining.
func NewAgentServer ¶
func NewAgentServer[T any](options ServerOptions[T]) (*AgentServer[T], error)
func (*AgentServer[T]) ActiveJobs ¶
func (s *AgentServer[T]) ActiveJobs() []RunningJobInfo
func (*AgentServer[T]) Close ¶
func (s *AgentServer[T]) Close(contexts ...context.Context) error
Close stops registration, the health server, and all remaining executors. It is idempotent. With no context argument it uses a background context.
func (*AgentServer[T]) Drain ¶
func (s *AgentServer[T]) Drain(ctx context.Context) error
Drain immediately advertises FULL and waits for accepted jobs to finish.
func (*AgentServer[T]) Draining ¶
func (s *AgentServer[T]) Draining() bool
func (*AgentServer[T]) Events ¶
func (s *AgentServer[T]) Events() *EventEmitter[WorkerEvent]
func (*AgentServer[T]) HTTPAddress ¶
func (s *AgentServer[T]) HTTPAddress() string
HTTPAddress returns the bound health endpoint after Run has started it.
func (*AgentServer[T]) ID ¶
func (s *AgentServer[T]) ID() string
func (*AgentServer[T]) RegisterAgent ¶
func (s *AgentServer[T]) RegisterAgent(name string, entrypoint JobEntrypoint[T]) error
RegisterAgent mirrors Python's pre-run AgentServer registration style.
func (*AgentServer[T]) RegisterRTCSession ¶
func (s *AgentServer[T]) RegisterRTCSession(name string, entrypoint JobEntrypoint[T]) error
RegisterRTCSession is the Python-compatible name for RegisterAgent.
func (*AgentServer[T]) Registered ¶
func (s *AgentServer[T]) Registered() bool
func (*AgentServer[T]) Run ¶
func (s *AgentServer[T]) Run(ctx context.Context) error
Run blocks until the worker is closed, its context is canceled, or a fatal registration/reconnection error occurs. A canceled context triggers a drain.
func (*AgentServer[T]) SimulateJob ¶
func (s *AgentServer[T]) SimulateJob(ctx context.Context, roomName, participantIdentity string) error
SimulateJob asks the connected server to synthesize a job request.
type AssignmentTimeoutError ¶
type AssignmentTimeoutError struct{ Message string }
func (*AssignmentTimeoutError) Error ¶
func (e *AssignmentTimeoutError) Error() string
type AudioByteStream ¶
type AudioByteStream struct {
// contains filtered or unexported fields
}
AudioByteStream packetizes little-endian PCM16 without repeatedly copying the accumulated input. It is not safe for concurrent use.
func NewAudioByteStream ¶
func NewAudioByteStream(sampleRate, channels, samplesPerChannel int) (*AudioByteStream, error)
func (*AudioByteStream) Flush ¶
func (s *AudioByteStream) Flush() ([]AudioFrame, error)
func (*AudioByteStream) Reset ¶
func (s *AudioByteStream) Reset()
func (*AudioByteStream) Write ¶
func (s *AudioByteStream) Write(data []byte) []AudioFrame
type AudioDecodeError ¶
func (*AudioDecodeError) Error ¶
func (e *AudioDecodeError) Error() string
func (*AudioDecodeError) Unwrap ¶
func (e *AudioDecodeError) Unwrap() error
type AudioDecodeOptions ¶
type AudioDecodeOptions struct {
SampleRate int
Channels int
// NumChannels is the agents-js compatibility name for Channels.
NumChannels int
Format string
FrameDuration time.Duration
StreamCapacity int
// FFmpegPath overrides the lazily discovered ffmpeg executable. Native
// matching-format PCM16 WAV decoding does not start or require ffmpeg.
FFmpegPath string
}
type AudioEnergyFilter ¶
type AudioEnergyFilter struct {
Cooldown time.Duration
Threshold float64
// contains filtered or unexported fields
}
AudioEnergyFilter holds speech-active state for Cooldown after the most recent frame whose normalized PCM RMS exceeds Threshold. PushFrame performs no allocations and is intended for one audio actor/goroutine.
func NewAudioEnergyFilter ¶
func NewAudioEnergyFilter(cooldown time.Duration) *AudioEnergyFilter
func (*AudioEnergyFilter) PushFrame ¶
func (f *AudioEnergyFilter) PushFrame(frame AudioFrame) bool
func (*AudioEnergyFilter) Reset ¶
func (f *AudioEnergyFilter) Reset()
type AudioFrame ¶
type AudioFrame struct {
Data []int16
SampleRate int
Channels int
SamplesPerChannel int
UserData map[string]any
}
AudioFrame is interleaved signed 16-bit PCM. Data is owned by the frame and remains valid until the frame is discarded.
func MergeFrames ¶
func MergeFrames(frames []AudioFrame) (AudioFrame, error)
MergeFrames combines same-format frames with one allocation.
func NewAudioFrame ¶
func NewAudioFrame(data []int16, sampleRate, channels int) (AudioFrame, error)
func (AudioFrame) Duration ¶
func (f AudioFrame) Duration() time.Duration
type AudioFrameStream ¶
type AudioFrameStream interface {
stream.Reader[AudioFrame]
Close() error
Wait(context.Context) error
}
func AudioFramesFromFile ¶
func AudioFramesFromFile(ctx context.Context, path string, options AudioDecodeOptions) (AudioFrameStream, error)
AudioFramesFromFile decodes a file to bounded 16-bit PCM frames. Matching PCM16 WAV files use the native streaming parser (fast startup, no subprocess); other formats and resampling use ffmpeg, matching agents-js's codec surface.
func LoopAudioFramesFromFile ¶
func LoopAudioFramesFromFile(ctx context.Context, path string, options AudioDecodeOptions) (AudioFrameStream, error)
LoopAudioFramesFromFile repeatedly decodes a file without retaining the entire file in memory. An empty file terminates with io.ErrUnexpectedEOF instead of spinning at 100% CPU.
type AutoSubscribe ¶
type AutoSubscribe uint8
AutoSubscribe controls which remote tracks JobContext.Connect subscribes to. The values intentionally follow the TypeScript and Python SDK ordering.
type CGroupV1CPUMonitor ¶
type CGroupV1CPUMonitor struct {
// contains filtered or unexported fields
}
CGroupV1CPUMonitor reads the legacy cpu/cpuacct controllers.
func NewCGroupV1CPUMonitor ¶
func NewCGroupV1CPUMonitor(root string) *CGroupV1CPUMonitor
func (*CGroupV1CPUMonitor) CPUCount ¶
func (m *CGroupV1CPUMonitor) CPUCount() float64
func (*CGroupV1CPUMonitor) CPUPercent ¶
type CGroupV2CPUMonitor ¶
type CGroupV2CPUMonitor struct {
// contains filtered or unexported fields
}
CGroupV2CPUMonitor reads unified-hierarchy CPU quota and usage.
func NewCGroupV2CPUMonitor ¶
func NewCGroupV2CPUMonitor(root string) *CGroupV2CPUMonitor
func (*CGroupV2CPUMonitor) CPUCount ¶
func (m *CGroupV2CPUMonitor) CPUCount() float64
func (*CGroupV2CPUMonitor) CPUPercent ¶
type CPUMonitor ¶
type CPUMonitor interface {
CPUCount() float64
CPUPercent(context.Context, time.Duration) (float64, error)
}
CPUMonitor reports normalized load in [0,1] and the effective CPU quota. CPUPercent uses no helper goroutine and always honors ctx cancellation.
func GetCPUMonitor ¶
func GetCPUMonitor() CPUMonitor
GetCPUMonitor selects Linux cgroup accounting when available, then falls back to Go runtime CPU-class metrics. Detection is explicit and lazy.
type ConnectOptions ¶
type ConnectOptions struct {
AutoSubscribe AutoSubscribe
RoomOptions []lksdk.ConnectOption
}
ConnectOptions controls room connection and automatic subscription.
type ConnectionPool ¶
type ConnectionPool[T comparable] struct { // contains filtered or unexported fields }
ConnectionPool serializes establishment, reuses connections in insertion order, and never returns an expired/failed connection.
func NewConnectionPool ¶
func NewConnectionPool[T comparable](options ConnectionPoolOptions[T]) (*ConnectionPool[T], error)
func (*ConnectionPool[T]) Invalidate ¶
func (p *ConnectionPool[T]) Invalidate()
func (*ConnectionPool[T]) Len ¶
func (p *ConnectionPool[T]) Len() int
func (*ConnectionPool[T]) Prewarm ¶
func (p *ConnectionPool[T]) Prewarm(ctx context.Context)
func (*ConnectionPool[T]) Put ¶
func (p *ConnectionPool[T]) Put(conn T) bool
func (*ConnectionPool[T]) Remove ¶
func (p *ConnectionPool[T]) Remove(ctx context.Context, conn T) error
func (*ConnectionPool[T]) WithConnection ¶
type ConnectionPoolOptions ¶
type ConsoleJobOptions ¶
type ConsoleJobOptions[UserData any] struct { Server ServerOptions[UserData] Record bool // SessionDirectory is shared with AgentSession recording/report lifecycle. // An empty value uses the normal traversal-safe temporary job directory. SessionDirectory string ShutdownTimeout time.Duration // Setup runs after prewarm and before the entrypoint. The CLI uses it to // bind process-local console IO without introducing a root-package import // cycle with voice. Setup func(context.Context, *JobContext[UserData], SimulationEndFunc[UserData]) error }
ConsoleJobOptions configures the in-process fake job used by the console command. It deliberately does not require LiveKit credentials or initialize a worker websocket.
type Entrypoint ¶
type Entrypoint[T any] = JobEntrypoint[T]
type EventEmitter ¶
type EventEmitter[T any] struct { // contains filtered or unexported fields }
EventEmitter is a small synchronous typed emitter. Callbacks execute in registration order and outside the emitter lock. Subscribe and unsubscribe are safe to call concurrently with Emit.
func (*EventEmitter[T]) Emit ¶
func (e *EventEmitter[T]) Emit(event T)
func (*EventEmitter[T]) Len ¶
func (e *EventEmitter[T]) Len() int
func (*EventEmitter[T]) Subscribe ¶
func (e *EventEmitter[T]) Subscribe(fn func(T)) (unsubscribe func())
type ExecutorMode ¶
type ExecutorMode uint8
ExecutorMode selects job isolation. Process isolation is the production default and preserves the Python/TypeScript crash and memory boundary.
const ( ExecutorModeProcess ExecutorMode = iota ExecutorModeInProcess )
type ExpFilter ¶
type ExpFilter struct {
// contains filtered or unexported fields
}
ExpFilter performs exponentially weighted smoothing. It is intended to be owned by one actor/goroutine, avoiding a lock on load/audio hot paths.
func NewExpFilter ¶
func NewExpFilter(options ExpFilterOptions) (*ExpFilter, error)
type ExpFilterOptions ¶
type FlushSentinel ¶
type FlushSentinel struct{}
FlushSentinel is the Go equivalent of the JS FlushSentinel symbol. A model stream emits a value with Flush=true instead of relying on an untyped marker.
type FunctionExistsError ¶
type FunctionExistsError struct{ Message string }
FunctionExistsError reports duplicate callback registration.
func (*FunctionExistsError) Error ¶
func (e *FunctionExistsError) Error() string
func (*FunctionExistsError) Unwrap ¶
func (e *FunctionExistsError) Unwrap() error
type IdleTimeoutError ¶
type IdleTimeoutError struct{ Message string }
func (*IdleTimeoutError) Error ¶
func (e *IdleTimeoutError) Error() string
type InferenceProcessError ¶
InferenceProcessError is a stable error category returned by a supervised inference subprocess. Arbitrary native errors cannot preserve their concrete Go type across an OS process boundary, but their message and category do.
func (*InferenceProcessError) Error ¶
func (e *InferenceProcessError) Error() string
func (*InferenceProcessError) Is ¶
func (e *InferenceProcessError) Is(target error) bool
type InferenceRunner ¶
type InferenceRunner interface {
Initialize(context.Context) error
Run(context.Context, any) (any, error)
Close(context.Context) error
}
InferenceRunner is the context-aware Go contract for a local model runner. A runner instance is owned by one inference executor and must tolerate an Initialize/Close pair even when no Run call succeeds.
func NewInferenceRunner ¶
func NewInferenceRunner(method string) (InferenceRunner, error)
NewInferenceRunner creates one registered runner without holding the registry lock across user code.
type InferenceRunnerFactory ¶
type InferenceRunnerFactory func() (InferenceRunner, error)
InferenceRunnerFactory constructs a fresh runner in the process that will execute it. Factories replace JavaScript import paths because Go links the implementation into both the parent and supervised child binary.
type InferenceRunnerFuncs ¶
type InferenceRunnerFuncs struct {
InitializeFunc func(context.Context) error
RunFunc func(context.Context, any) (any, error)
CloseFunc func(context.Context) error
}
InferenceRunnerFuncs adapts three functions to InferenceRunner.
func (InferenceRunnerFuncs) Initialize ¶
func (r InferenceRunnerFuncs) Initialize(ctx context.Context) error
type JobAcceptArguments ¶
type JobAcceptArguments = JobAcceptOptions
type JobAcceptOptions ¶
type JobAcceptOptions struct {
Name string
Identity string
Metadata string
Attributes map[string]string
}
JobAcceptOptions controls the participant created for an accepted job.
type JobContext ¶
type JobContext[T any] struct { // contains filtered or unexported fields }
JobContext is the job and room environment passed to an entrypoint.
func JobFromContext ¶
func JobFromContext[T any](ctx context.Context) (*JobContext[T], bool)
JobFromContext returns the typed job explicitly propagated by the executor.
func (*JobContext[T]) AddParticipantEntrypoint ¶
func (j *JobContext[T]) AddParticipantEntrypoint(callback ParticipantEntrypoint[T]) error
AddParticipantEntrypoint registers a bounded, asynchronous participant hook. The same function cannot be added twice.
func (*JobContext[T]) AddShutdownCallback ¶
func (j *JobContext[T]) AddShutdownCallback(callback ShutdownCallback) error
func (*JobContext[T]) Agent ¶
func (j *JobContext[T]) Agent() *lksdk.LocalParticipant
func (*JobContext[T]) Connect ¶
func (j *JobContext[T]) Connect(ctx context.Context, opts ConnectOptions) error
Connect joins the assigned room. It is idempotent, safe for concurrent use, and applies audio/video-only subscription rules to existing and future tracks.
func (*JobContext[T]) Context ¶
func (j *JobContext[T]) Context() context.Context
func (*JobContext[T]) DeleteRoom ¶
func (j *JobContext[T]) DeleteRoom(ctx context.Context, name string) error
DeleteRoom deletes the assigned room, or name when provided. Fake jobs are deliberately a no-op.
func (*JobContext[T]) Done ¶
func (j *JobContext[T]) Done() <-chan struct{}
func (*JobContext[T]) InferenceExecutor ¶
func (j *JobContext[T]) InferenceExecutor() ipc.InferenceExecutor
InferenceExecutor returns the worker-global local inference executor. In process-isolated jobs this is a cancellation-aware IPC client backed by the same shared runner instances as every other job.
func (*JobContext[T]) Info ¶
func (j *JobContext[T]) Info() RunningJobInfo
func (*JobContext[T]) IsConnected ¶
func (j *JobContext[T]) IsConnected() bool
func (*JobContext[T]) IsFakeJob ¶
func (j *JobContext[T]) IsFakeJob() bool
func (*JobContext[T]) Job ¶
func (j *JobContext[T]) Job() *livekit.Job
func (*JobContext[T]) Process ¶
func (j *JobContext[T]) Process() *JobProcess[T]
func (*JobContext[T]) RTCBridge ¶
func (j *JobContext[T]) RTCBridge() *rtcbridge.RTCBridge
RTCBridge returns the construction-time callback bridge installed on Room. Higher-level RoomIO uses it to subscribe without polling or unsafe callback replacement. The JobContext owns and closes the bridge.
func (*JobContext[T]) RegisterSession ¶
func (j *JobContext[T]) RegisterSession(options JobSessionRegistrationOptions) (*JobSessionRegistration, error)
RegisterSession claims the primary session slot atomically. An omitted recording choice inherits the dispatch setting. A secondary omitted choice is silently demoted to recording-off; an explicit recording-on choice fails.
func (*JobContext[T]) Room ¶
func (j *JobContext[T]) Room() *lksdk.Room
func (*JobContext[T]) SessionDirectory ¶
func (j *JobContext[T]) SessionDirectory() string
SessionDirectory is the traversal-safe per-job location for recordings and session artifacts. The directory is created lazily by the component that writes an artifact.
func (*JobContext[T]) Shutdown ¶
func (j *JobContext[T]) Shutdown(reason string)
Shutdown requests graceful job termination. Calling it more than once is a no-op and preserves the first reason.
func (*JobContext[T]) ShutdownReason ¶
func (j *JobContext[T]) ShutdownReason() string
func (*JobContext[T]) SimulationContext ¶
func (j *JobContext[T]) SimulationContext() (*SimulationContext[T], bool)
SimulationContext resolves and caches the simulation dispatch carried on the assigned job. Malformed or incomplete attributes are ignored after one warning, matching the TypeScript/Python entrypoint behavior.
func (*JobContext[T]) State ¶
func (j *JobContext[T]) State() *T
func (*JobContext[T]) WaitForParticipant ¶
func (j *JobContext[T]) WaitForParticipant(ctx context.Context, identity string, kinds ...lksdk.ParticipantKind) (*lksdk.RemoteParticipant, error)
WaitForParticipant waits for a non-agent remote participant. If kinds is empty, every participant kind except agent is accepted.
func (*JobContext[T]) WaitForParticipantAttribute ¶
func (j *JobContext[T]) WaitForParticipantAttribute(ctx context.Context, identity, attribute, value string) error
WaitForParticipantAttribute uses the JobContext's construction-time bridge.
func (*JobContext[T]) WaitForTrackPublication ¶
func (j *JobContext[T]) WaitForTrackPublication(ctx context.Context, options WaitForTrackPublicationOptions) (lksdk.TrackPublication, error)
WaitForTrackPublication uses the JobContext's construction-time bridge.
func (*JobContext[T]) WorkerID ¶
func (j *JobContext[T]) WorkerID() string
type JobEntrypoint ¶
type JobEntrypoint[T any] func(context.Context, *JobContext[T]) error
type JobProcess ¶
type JobProcess[T any] struct { // contains filtered or unexported fields }
JobProcess is process-local state initialized by a prewarm callback. In process-executor mode PID is the child PID; in explicit in-process mode it is the current process PID.
func (*JobProcess[T]) PID ¶
func (p *JobProcess[T]) PID() int
func (*JobProcess[T]) State ¶
func (p *JobProcess[T]) State() *T
State returns the typed, process-local value shared by Prewarm and the job.
func (*JobProcess[T]) UserData ¶
func (p *JobProcess[T]) UserData() *T
UserData is a compatibility alias for State.
type JobRejectOptions ¶
type JobRejectOptions struct{}
JobRejectOptions is reserved for protocol-compatible rejection metadata. The current worker protocol carries only the availability decision.
type JobRequest ¶
type JobRequest struct {
// contains filtered or unexported fields
}
JobRequest is the immutable view given to the request handler. Exactly one Accept or Reject call succeeds.
func (*JobRequest) Accept ¶
func (r *JobRequest) Accept(ctx context.Context, opts JobAcceptOptions) error
func (*JobRequest) AgentName ¶
func (r *JobRequest) AgentName() string
func (*JobRequest) Answered ¶
func (r *JobRequest) Answered() bool
func (*JobRequest) ID ¶
func (r *JobRequest) ID() string
func (*JobRequest) Job ¶
func (r *JobRequest) Job() *livekit.Job
func (*JobRequest) Publisher ¶
func (r *JobRequest) Publisher() *livekit.ParticipantInfo
func (*JobRequest) Reject ¶
func (r *JobRequest) Reject(ctx context.Context, opts JobRejectOptions) error
func (*JobRequest) Resuming ¶
func (r *JobRequest) Resuming() bool
func (*JobRequest) Room ¶
func (r *JobRequest) Room() *livekit.Room
type JobSessionLifecycle ¶
type JobSessionLifecycle interface {
CloseSession(context.Context) error
FinalizeSession(context.Context) error
}
JobSessionLifecycle is the import-cycle-free bridge between JobContext and a high-level agent session. CloseSession runs before the room disconnects; FinalizeSession then persists/uploads its report. A finalization failure is logged and does not turn an otherwise successful agent job into a failed assignment, matching the TypeScript/Python lifecycle.
type JobSessionLifecycleFuncs ¶
type JobSessionLifecycleFuncs struct {
Close func(context.Context) error
Finalize func(context.Context) error
}
JobSessionLifecycleFuncs adapts functions without requiring a wrapper type.
func (JobSessionLifecycleFuncs) CloseSession ¶
func (f JobSessionLifecycleFuncs) CloseSession(ctx context.Context) error
func (JobSessionLifecycleFuncs) FinalizeSession ¶
func (f JobSessionLifecycleFuncs) FinalizeSession(ctx context.Context) error
type JobSessionRegistration ¶
type JobSessionRegistration struct {
Primary bool
RecordingEnabled bool
RedactionEnabled bool
// contains filtered or unexported fields
}
JobSessionRegistration is the resolved claim returned to a session. Release rolls back a primary claim when Start fails; it is idempotent.
func (*JobSessionRegistration) Release ¶
func (r *JobSessionRegistration) Release()
Release rolls back this registration. Successful primary sessions normally remain registered until JobContext shutdown so the job runner can close and finalize them in the correct order.
type JobSessionRegistrationOptions ¶
type JobSessionRegistrationOptions struct {
Lifecycle JobSessionLifecycle
Recording Override[bool]
}
JobSessionRegistrationOptions controls the primary-session claim. Recording inherits livekit.Job.enable_recording when Recording is zero-valued. Use Use(false) or Disable[bool]() to explicitly disable it.
type LanguageCode ¶
type LanguageCode string
func AsLanguageCode ¶
func AsLanguageCode(language string) LanguageCode
func NormalizeLanguage ¶
func NormalizeLanguage(language string) LanguageCode
type LocalInferenceExecutor ¶
type LocalInferenceExecutor struct {
// contains filtered or unexported fields
}
LocalInferenceExecutor owns one instance of every registered inference runner. A worker shares this executor across jobs so a native model is loaded once per worker host rather than once per job process.
Initialize eagerly constructs all registered runners. DoInference also initializes a runner lazily, which keeps standalone and console use useful without imposing import-time work. Close is idempotent and waits for accepted initialization and inference calls before closing runners.
func NewLocalInferenceExecutor ¶
func NewLocalInferenceExecutor(factories map[string]InferenceRunnerFactory) (*LocalInferenceExecutor, error)
NewLocalInferenceExecutor snapshots factories. A nil map uses the process registry; an explicitly empty map creates a valid executor that reports unknown methods without allocating runner state.
func (*LocalInferenceExecutor) Close ¶
func (e *LocalInferenceExecutor) Close(ctx context.Context) error
Close rejects new work, cancels initialization waiters, waits for accepted calls, then closes initialized runners concurrently. A caller deadline is reported, while cleanup continues and a later Close observes the final error.
func (*LocalInferenceExecutor) DoInference ¶
func (e *LocalInferenceExecutor) DoInference(ctx context.Context, method string, data any) (result any, err error)
DoInference dispatches one request to a registered runner. Runner calls may execute concurrently, matching the TypeScript/Python shared executor. The request context is propagated through initialization and Run.
func (*LocalInferenceExecutor) HasInferenceRunners ¶
func (e *LocalInferenceExecutor) HasInferenceRunners() bool
HasInferenceRunners reports whether the executor has any configured method without initializing it.
func (*LocalInferenceExecutor) Healthy ¶
func (e *LocalInferenceExecutor) Healthy() error
Healthy reports deterministic initialization/closure failures without triggering lazy initialization. Workers include it in readiness checks.
func (*LocalInferenceExecutor) Initialize ¶
func (e *LocalInferenceExecutor) Initialize(ctx context.Context) error
Initialize eagerly initializes all runners concurrently. It is safe to call repeatedly and concurrently. Partial initialization is retained so Close can release every successfully initialized runner; callers should close the executor when Initialize returns an error.
type LoggerOptions ¶
type LoggerOptions struct {
Level slog.Leveler
Format LogFormat
Writer io.Writer
Handler slog.Handler
AddSource bool
SetDefault bool
ReplaceAttr func([]string, slog.Attr) slog.Attr
}
LoggerOptions configures the process-local framework logger. Handler wins over Writer/Format/Level. The zero value creates JSON logs on stdout without replacing slog.Default.
type MissingCredentialsError ¶
type MissingCredentialsError struct{ Name string }
func (*MissingCredentialsError) Error ¶
func (e *MissingCredentialsError) Error() string
type Override ¶
type Override[T any] struct { // contains filtered or unexported fields }
Override models the Python/TypeScript inherit/use/disable tri-state. Its zero value inherits.
func (Override[T]) IsDisabled ¶
func (Override[T]) IsInherited ¶
type ParticipantEntrypoint ¶
type ParticipantEntrypoint[T any] func(context.Context, *JobContext[T], *lksdk.RemoteParticipant) error
type ParticipantNotFoundError ¶
type ParticipantNotFoundError struct{ Identity string }
ParticipantNotFoundError reports a participant that was absent before an attribute wait could be armed.
func (*ParticipantNotFoundError) Error ¶
func (e *ParticipantNotFoundError) Error() string
type ParticipantWaitDisconnectedError ¶
ParticipantWaitDisconnectedError reports a requested participant or the room disappearing before a wait condition was satisfied.
func (*ParticipantWaitDisconnectedError) Error ¶
func (e *ParticipantWaitDisconnectedError) Error() string
type Plugin ¶
type Plugin interface {
Title() string
Version() string
Package() string
DownloadFiles(context.Context) error
}
func RegisteredPlugins ¶
func RegisteredPlugins() []Plugin
type PluginRegisteredEvent ¶
type PluginRegisteredEvent struct{ Plugin Plugin }
type PrewarmFunc ¶
type PrewarmFunc[T any] func(context.Context, *JobProcess[T]) error
type RequestHandler ¶
type RequestHandler func(context.Context, *JobRequest) error
type ResolvedLoggerOptions ¶
type ResolvedLoggerOptions struct {
Level slog.Level
Format LogFormat
AddSource bool
SetDefault bool
}
func CurrentLoggerOptions ¶
func CurrentLoggerOptions() (ResolvedLoggerOptions, bool)
type ResourceBag ¶
type ResourceBag struct {
// contains filtered or unexported fields
}
ResourceBag carries process-prewarmed dependencies without serialization or reflection on access. It is safe for concurrent jobs in in-process mode.
func NewResourceBag ¶
func NewResourceBag() *ResourceBag
func (*ResourceBag) Delete ¶
func (b *ResourceBag) Delete(key string)
type RunningJobInfo ¶
type RunningJobInfo struct {
AcceptArguments JobAcceptOptions
Job *livekit.Job
URL string
Token SecretString
WorkerID string
APIKey SecretString
APISecret SecretString
FakeJob bool
// SessionDirectory overrides the per-job directory used for recordings and
// reports. Production assignments normally leave this empty and receive a
// traversal-safe directory below os.TempDir. Console runners set it to their
// user-visible session directory.
SessionDirectory string
}
RunningJobInfo is the complete, immutable assignment passed to an executor. API credentials are redacted when formatted or marshaled.
func (RunningJobInfo) Clone ¶
func (i RunningJobInfo) Clone() RunningJobInfo
Clone returns a deep copy suitable for crossing ownership boundaries.
type RuntimeCPUMonitor ¶
type RuntimeCPUMonitor struct{}
RuntimeCPUMonitor uses the stable runtime/metrics CPU classes. It measures this Go process rather than unrelated host work and is portable without cgo.
func NewRuntimeCPUMonitor ¶
func NewRuntimeCPUMonitor() *RuntimeCPUMonitor
func (*RuntimeCPUMonitor) CPUCount ¶
func (*RuntimeCPUMonitor) CPUCount() float64
func (*RuntimeCPUMonitor) CPUPercent ¶
type ScenarioGroup ¶
type ScenarioGroup = livekit.ScenarioGroup
type ScenarioUserdata ¶
type SecretString ¶
type SecretString string
func NewSecretString ¶
func NewSecretString(value string) SecretString
func (SecretString) GoString ¶
func (SecretString) GoString() string
func (SecretString) MarshalJSON ¶
func (SecretString) MarshalJSON() ([]byte, error)
func (SecretString) MarshalText ¶
func (SecretString) MarshalText() ([]byte, error)
func (SecretString) Reveal ¶
func (s SecretString) Reveal() string
func (SecretString) String ¶
func (SecretString) String() string
type ServerOptions ¶
type ServerOptions[T any] struct { // Agent is the defineAgent-compatible immutable module. Direct entrypoint // fields remain supported for idiomatic Go construction. Agent *AgentDefinition[T] JobEntrypoint JobEntrypoint[T] // Entrypoint is the legacy compatibility name. JobEntrypoint is canonical. Entrypoint JobEntrypoint[T] RequestHandler RequestHandler // RequestFunc is the TypeScript-compatible alias for RequestHandler. RequestFunc RequestHandler Prewarm PrewarmFunc[T] OnSimulationEnd SimulationEndFunc[T] AgentName string AgentNameIsEnv bool ServerType ServerType Deployment string ExecutorMode ExecutorMode MaxConcurrentJobs int NumIdleProcesses int LoadFunc LoadFunc[T] LoadThreshold float64 Production bool Simulation bool DrainTimeout time.Duration ShutdownProcessTimeout time.Duration InitializeProcessTimeout time.Duration AssignmentTimeout time.Duration StatusUpdateInterval time.Duration MaxReconnects int MaxReconnectsSet bool Permissions WorkerPermissions PermissionsSet bool URL string WSURL string APIKey SecretString APISecret SecretString WorkerToken SecretString Host string Port int JobMemoryWarnMB int JobMemoryWarnMBSet bool JobMemoryLimitMB int Logger *slog.Logger }
ServerOptions configures the worker runtime. Zero-valued optional fields use the same production/development defaults as the Python and TypeScript SDKs.
type ServerType ¶
type SessionConnectOptions ¶
type SessionConnectOptions struct {
STT APIConnectOptions
LLM APIConnectOptions
TTS APIConnectOptions
MaxUnrecoverableErrors int
}
func (SessionConnectOptions) Resolve ¶
func (o SessionConnectOptions) Resolve() SessionConnectOptions
type SimulationContext ¶
type SimulationContext[T any] struct { // contains filtered or unexported fields }
SimulationContext carries the immutable dispatch plus final verdict state for one simulated job. The user verdict can veto a simulator success but cannot turn a simulator failure into a success.
func NewSimulationContext ¶
func NewSimulationContext[T any](dispatch *SimulationDispatch, job *JobContext[T]) (*SimulationContext[T], error)
func (*SimulationContext[T]) BeginFinalize ¶
func (s *SimulationContext[T]) BeginFinalize(verdict SimulationVerdict, run *SimulationRun)
BeginFinalize is called by the session host before the on-simulation-end hook. It makes the simulator verdict and run visible atomically.
func (*SimulationContext[T]) Dispatch ¶
func (s *SimulationContext[T]) Dispatch() *SimulationDispatch
func (*SimulationContext[T]) EffectiveVerdict ¶
func (s *SimulationContext[T]) EffectiveVerdict() (SimulationVerdict, error)
func (*SimulationContext[T]) Fail ¶
func (s *SimulationContext[T]) Fail(reason string)
Fail records the user's veto. The last call wins.
func (*SimulationContext[T]) JobContext ¶
func (s *SimulationContext[T]) JobContext() *JobContext[T]
func (*SimulationContext[T]) JobID ¶
func (s *SimulationContext[T]) JobID() string
func (*SimulationContext[T]) Mode ¶
func (s *SimulationContext[T]) Mode() SimulationMode
func (*SimulationContext[T]) Run ¶
func (s *SimulationContext[T]) Run() (*SimulationRun, bool)
func (*SimulationContext[T]) RunID ¶
func (s *SimulationContext[T]) RunID() string
func (*SimulationContext[T]) Scenario ¶
func (s *SimulationContext[T]) Scenario() *Scenario
func (*SimulationContext[T]) SimulatorVerdict ¶
func (s *SimulationContext[T]) SimulatorVerdict() (SimulationVerdict, error)
func (*SimulationContext[T]) UserVerdict ¶
func (s *SimulationContext[T]) UserVerdict() (SimulationVerdict, bool)
func (*SimulationContext[T]) Userdata ¶
func (s *SimulationContext[T]) Userdata() (ScenarioUserdata, error)
Userdata decodes the scenario's JSON object. It returns an empty map for an empty field and preserves integer tokens as json.Number.
type SimulationDispatch ¶
type SimulationDispatch = livekit.SimulationDispatch
func ParseSimulationDispatch ¶
func ParseSimulationDispatch(raw string) (*SimulationDispatch, error)
ParseSimulationDispatch decodes the proto-JSON job attribute. Unknown fields are discarded so a newer LiveKit server can extend the message without breaking an older agent binary.
type SimulationEndFunc ¶
type SimulationEndFunc[T any] func(context.Context, *SimulationContext[T]) error
type SimulationMode ¶
type SimulationMode = livekit.SimulationMode
type SimulationRun ¶
type SimulationRun = livekit.SimulationRun
type SimulationRunJob ¶
type SimulationRunJob = livekit.SimulationRun_Job
type SimulationVerdict ¶
SimulationVerdict is a pass/fail result with a human-readable reason.
type TimedString ¶
type TimedString struct {
Text string
StartTime *time.Duration
EndTime *time.Duration
Confidence *float64
StartTimeOffset *time.Duration
SpeakerID *string
}
func CreateTimedString ¶
func CreateTimedString(options TimedStringOptions) TimedString
func NewTimedString ¶
func NewTimedString(text string, start, end time.Duration) TimedString
type TimedStringOptions ¶
type UnexpectedModelBehavior ¶
func (*UnexpectedModelBehavior) Error ¶
func (e *UnexpectedModelBehavior) Error() string
func (*UnexpectedModelBehavior) Unwrap ¶
func (e *UnexpectedModelBehavior) Unwrap() error
type WaitForTrackPublicationOptions ¶
type WaitForTrackPublicationOptions struct {
Identity string
Kind lksdk.TrackKind
IncludeLocal bool
WaitForSubscription bool
EventCapacity int
}
WaitForTrackPublicationOptions matches the TypeScript/Python helper. Empty Identity and Kind values mean any participant and any kind respectively. Local publications resolve when published and ignore WaitForSubscription.
type WorkerError ¶
func (*WorkerError) Error ¶
func (e *WorkerError) Error() string
func (*WorkerError) Unwrap ¶
func (e *WorkerError) Unwrap() error
type WorkerEvent ¶
type WorkerEvent struct {
Type WorkerEventType
WorkerID string
ServerInfo *livekit.ServerInfo
Message *livekit.WorkerMessage
Error error
}
type WorkerEventType ¶
type WorkerEventType string
const ( WorkerEventRegistered WorkerEventType = "worker_registered" WorkerEventMessage WorkerEventType = "worker_msg" WorkerEventClosed WorkerEventType = "worker_closed" )
type WorkerOptions ¶
type WorkerOptions[T any] = ServerOptions[T]
WorkerOptions is retained as a source-compatible alias.
type WorkerPermissions ¶
type WorkerPermissions struct {
CanPublish bool
CanSubscribe bool
CanPublishData bool
CanUpdateMetadata bool
CanPublishSources []livekit.TrackSource
Hidden bool
CanSubscribeMetrics bool
CanManageAgentSession bool
}
WorkerPermissions are applied to every agent participant created by this worker. Use DefaultWorkerPermissions when modifying individual fields.
func DefaultWorkerPermissions ¶
func DefaultWorkerPermissions() WorkerPermissions
Source Files
¶
- audio.go
- audio_file.go
- connection_pool.go
- console.go
- constants.go
- cpu.go
- errors.go
- events.go
- ffmpeg.go
- filters.go
- generator.go
- id.go
- inference_executor.go
- inference_process.go
- inference_runner.go
- job.go
- job_session.go
- language.go
- log.go
- options.go
- override.go
- plugin.go
- process.go
- process_command_unix.go
- process_inference.go
- process_memory_linux.go
- resource.go
- secret.go
- server_http.go
- simulation.go
- timed_string.go
- utils.go
- version.go
- worker.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package agentscli provides the embedded LiveKit Agents command-line runtime.
|
Package agentscli provides the embedded LiveKit Agents command-line runtime. |
|
benchmarks
|
|
|
coldstart/core
command
|
|
|
coldstart/elevenlabs
command
|
|
|
coldstart/measure
command
|
|
|
coldstart/voice
command
|
|
|
Package beta retains the temporary agents-js compatibility surface.
|
Package beta retains the temporary agents-js compatibility surface. |
|
tools
Package tools contains the beta LiveKit agent tools.
|
Package tools contains the beta LiveKit agent tools. |
|
workflows
Package workflows contains deprecated compatibility aliases.
|
Package workflows contains deprecated compatibility aliases. |
|
Package inference implements the LiveKit Cloud Inference adapters.
|
Package inference implements the LiveKit Cloud Inference adapters. |
|
internal
|
|
|
apimanifest
Package apimanifest produces the deterministic public-API snapshot used by release checks.
|
Package apimanifest produces the deterministic public-API snapshot used by release checks. |
|
cmd/apimanifest
command
|
|
|
cmd/depaudit
command
Command depaudit verifies the reviewed dependency and licensing policy for this module.
|
Command depaudit verifies the reviewed dependency and licensing policy for this module. |
|
paritymanifest
Package paritymanifest validates the checked-in cross-language API parity ledger.
|
Package paritymanifest validates the checked-in cross-language API parity ledger. |
|
releaseversion
command
Command releaseversion prints the SDK version without a leading v.
|
Command releaseversion prints the SDK version without a leading v. |
|
workerprotocol
Package workerprotocol implements the LiveKit agent worker WebSocket wire protocol.
|
Package workerprotocol implements the LiveKit agent worker WebSocket wire protocol. |
|
Package ipc contains the public cross-process inference contract.
|
Package ipc contains the public cross-process inference contract. |
|
providerformat
Package providerformat converts LiveKit chat contexts into the wire-neutral request shapes consumed by OpenAI-compatible, Google Gemini, and Mistral APIs.
|
Package providerformat converts LiveKit chat contexts into the wire-neutral request shapes consumed by OpenAI-compatible, Google Gemini, and Mistral APIs. |
|
plugins
|
|
|
elevenlabs
Package elevenlabs provides production ElevenLabs speech-to-text and text-to-speech clients for LiveKit Agents.
|
Package elevenlabs provides production ElevenLabs speech-to-text and text-to-speech clients for LiveKit Agents. |
|
Package rtcbridge multiplexes one LiveKit RoomCallback into bounded, context-first subscriptions.
|
Package rtcbridge multiplexes one LiveKit RoomCallback into bounded, context-first subscriptions. |
|
Package stream provides cancellation-aware, bounded streams used throughout the SDK.
|
Package stream provides cancellation-aware, bounded streams used throughout the SDK. |
|
testing
Package stttest contains deterministic STT test doubles.
|
Package stttest contains deterministic STT test doubles. |
|
Package tokenize provides the sentence, word, paragraph, and English hyphenation primitives used by streaming transcription and TTS.
|
Package tokenize provides the sentence, word, paragraph, and English hyphenation primitives used by streaming transcription and TTS. |
|
Package transcription contains the legacy public text/audio synchronizer.
|
Package transcription contains the legacy public text/audio synchronizer. |
|
Package voice implements LiveKit's agent-session state machine and media pipeline.
|
Package voice implements LiveKit's agent-session state machine and media pipeline. |
|
avatar
Package avatar implements provider-independent LiveKit avatar sessions and bounded PCM transports.
|
Package avatar implements provider-independent LiveKit avatar sessions and bounded PCM transports. |
|
avatar/roomioadapter
Package roomioadapter connects avatar readiness waits to a roomio RTCBridge.
|
Package roomioadapter connects avatar readiness waits to a roomio RTCBridge. |
|
backgroundaudio
Package backgroundaudio provides the background-audio player shipped by the LiveKit Agents TypeScript SDK, adapted to context-first Go APIs.
|
Package backgroundaudio provides the background-audio player shipped by the LiveKit Agents TypeScript SDK, adapted to context-first Go APIs. |
|
livekit
Package livekit binds a voice.AgentSession to the current job's LiveKit room, recording, observability, report, and primary-session lifecycle.
|
Package livekit binds a voice.AgentSession to the current job's LiveKit room, recording, observability, report, and primary-session lifecycle. |
|
recorderio
Package recorderio records the user input and agent output sides of a voice session into a synchronized stereo Ogg/Opus file.
|
Package recorderio records the user input and agent output sides of a voice session into a synchronized stereo Ogg/Opus file. |
|
testing
Package voicetest provides deterministic model doubles and assertion helpers for voice-agent tests.
|
Package voicetest provides deterministic model doubles and assertion helpers for voice-agent tests. |
|
transcription
Package transcription provides streaming transcript synchronization and text transforms for voice sessions.
|
Package transcription provides streaming transcript synchronization and text transforms for voice sessions. |
|
Package workflows contains reusable, context-first agent workflows.
|
Package workflows contains reusable, context-first agent workflows. |
|
livekit
Package livekit provides the optional server-sdk-go/RoomIO backend for the stable warm-transfer workflow.
|
Package livekit provides the optional server-sdk-go/RoomIO backend for the stable warm-transfer workflow. |