agent

package
v1.13.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnabledCacheTTL         = 1 * time.Minute
	RoomAgentTopic          = "room"
	PublisherAgentTopic     = "publisher"
	ParticipantAgentTopic   = "participant"
	DefaultHandlerNamespace = ""

	CheckEnabledTimeout = 5 * time.Second
)
View Source
const (
	RegisterTimeout  = 10 * time.Second
	AssignJobTimeout = 10 * time.Second
)
View Source
const AgentNameAttributeKey = "lk.agent_name"
View Source
const CurrentProtocol = 1
View Source
const DefaultTargetLoad = 0.7

Variables

View Source
var (
	ErrUnimplementedWrorkerSignal = errors.New("unimplemented worker signal")
	ErrUnknownWorkerSignal        = errors.New("unknown worker signal")
	ErrUnknownJobType             = errors.New("unknown job type")
	ErrJobNotFound                = psrpc.NewErrorf(psrpc.NotFound, "no running job for given jobID")
	ErrWorkerClosed               = errors.New("worker closed")
	ErrWorkerNotAvailable         = errors.New("worker not available")
	ErrAvailabilityTimeout        = errors.New("agent worker availability timeout")
	ErrDuplicateJobAssignment     = errors.New("duplicate job assignment")
)

Functions

func DispatchWorkerSignal added in v1.8.0

func DispatchWorkerSignal(req *livekit.WorkerMessage, h WorkerSignalHandler) error

func EndpointRegisterHandler added in v1.13.8

func EndpointRegisterHandler(req *livekit.RegisterWorkerRequest, res *livekit.RegisterWorkerResponse, reg *WorkerRegistration) error

EndpointRegisterHandler owns a worker's endpoint declaration: it validates the declaration and negotiates the data-plane settings. A registration declaring no endpoints passes through untouched.

func GetAgentTopic added in v1.7.1

func GetAgentTopic(agentName, namespace, deployment string) string

func JobStatusIsEnded added in v1.7.1

func JobStatusIsEnded(s livekit.JobStatus) bool

Types

type AssignmentHook added in v1.12.0

type AssignmentHook func(next func(*livekit.JobAssignment) error) func(*livekit.JobAssignment) error

type Client

type Client interface {
	// LaunchJob starts a room or participant job on an agent.
	// it will launch a job once for each worker in each namespace
	LaunchJob(ctx context.Context, desc *JobRequest) *serverutils.IncrementalDispatcher[*livekit.Job]
	TerminateJob(ctx context.Context, jobID string, reason rpc.JobTerminateReason) (*livekit.JobState, error)
	Stop() error
}

func NewAgentClient

func NewAgentClient(bus psrpc.MessageBus, config Config) (Client, error)

type Config added in v1.9.2

type Config struct {
	EnableUserDataRecording bool    `yaml:"enable_user_data_recording"`
	EnableUserDataRedaction bool    `yaml:"enable_user_data_redaction"`
	TargetLoad              float32 `yaml:"target_load,omitempty"`

	// agent HTTP endpoints data plane; zero values take the endpoint package
	// defaults
	Endpoints EndpointsConfig `yaml:"endpoints,omitempty"`
}

type EndpointsConfig added in v1.13.8

type EndpointsConfig struct {
	// Disabled turns off the /agents/{agent_name}/{deployment}/... front and
	// rejects registrations that declare endpoints.
	Disabled bool `yaml:"disabled,omitempty"`

	// MaxStreams is the soft per-session concurrent-stream cap used for capacity
	// weighting; 0 takes the endpoint package default.
	MaxStreams uint32 `yaml:"max_streams,omitempty"`

	// MaxTunnels caps one worker's concurrent WebSocket tunnels, reserving the
	// rest of its streams for HTTP routes; 0 takes half of MaxStreams.
	MaxTunnels uint32 `yaml:"max_tunnels,omitempty"`

	// TunnelDrainTimeout is how long a WebSocket tunnel outlives its worker or
	// this node starting to drain; 0 takes the endpoint package default.
	TunnelDrainTimeout time.Duration `yaml:"tunnel_drain_timeout,omitempty"`
}

type JobRequest added in v1.7.1

type JobRequest struct {
	DispatchId string
	JobType    livekit.JobType
	Room       *livekit.Room
	// only set for participant jobs
	Participant *livekit.ParticipantInfo
	Metadata    string
	AgentName   string
	Deployment  string
	Attributes  map[string]string
}

type SignalConn added in v1.7.1

type SignalConn interface {
	WriteServerMessage(msg *livekit.ServerMessage) (int, error)
	ReadWorkerMessage() (*livekit.WorkerMessage, int, error)
	SetReadDeadline(time.Time) error
	Close() error
	CloseWithReason(reason string) error
}

type UnimplementedWorkerSignalHandler added in v1.8.0

type UnimplementedWorkerSignalHandler struct{}

func (UnimplementedWorkerSignalHandler) HandleAvailability added in v1.8.0

func (UnimplementedWorkerSignalHandler) HandleMigrateJob added in v1.8.0

func (UnimplementedWorkerSignalHandler) HandlePing added in v1.8.0

func (UnimplementedWorkerSignalHandler) HandleRegister added in v1.8.0

func (UnimplementedWorkerSignalHandler) HandleSimulateJob added in v1.8.0

func (UnimplementedWorkerSignalHandler) HandleUpdateJob added in v1.8.0

func (UnimplementedWorkerSignalHandler) HandleUpdateWorker added in v1.8.0

type Worker

type Worker struct {
	WorkerPingHandler
	WorkerRegistration
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker(
	registration WorkerRegistration,
	apiKey string,
	apiSecret string,
	conn SignalConn,
	logger logger.Logger,
) *Worker

func (*Worker) APIKey added in v1.11.0

func (w *Worker) APIKey() string

func (*Worker) AssignJob

func (w *Worker) AssignJob(ctx context.Context, job *livekit.Job, hook AssignmentHook) (*livekit.JobState, error)

func (*Worker) Close

func (w *Worker) Close()

func (*Worker) Draining added in v1.13.8

func (w *Worker) Draining() bool

func (*Worker) GetJobState added in v1.8.0

func (w *Worker) GetJobState(jobID livekit.JobID) (*livekit.JobState, error)

func (*Worker) HandleAvailability added in v1.8.0

func (w *Worker) HandleAvailability(res *livekit.AvailabilityResponse) error

func (*Worker) HandleMigrateJob added in v1.8.0

func (w *Worker) HandleMigrateJob(req *livekit.MigrateJobRequest) error

func (*Worker) HandleSimulateJob added in v1.8.0

func (w *Worker) HandleSimulateJob(simulate *livekit.SimulateJobRequest) error

func (*Worker) HandleUpdateJob added in v1.8.0

func (w *Worker) HandleUpdateJob(update *livekit.UpdateJobStatus) error

func (*Worker) HandleUpdateWorker added in v1.8.0

func (w *Worker) HandleUpdateWorker(update *livekit.UpdateWorkerStatus) error

func (*Worker) IsClosed

func (w *Worker) IsClosed() bool

func (*Worker) Load

func (w *Worker) Load() float32

func (*Worker) Logger

func (w *Worker) Logger() logger.Logger

func (*Worker) RunningJobCount added in v1.8.0

func (w *Worker) RunningJobCount() int

func (*Worker) RunningJobs

func (w *Worker) RunningJobs() map[livekit.JobID]*livekit.Job

func (*Worker) Status

func (w *Worker) Status() livekit.WorkerStatus

func (*Worker) TerminateJob added in v1.7.1

func (w *Worker) TerminateJob(jobID livekit.JobID, reason rpc.JobTerminateReason) (*livekit.JobState, error)

func (*Worker) UpdateJobStatus added in v1.8.0

func (w *Worker) UpdateJobStatus(update *livekit.UpdateJobStatus) (*livekit.JobState, error)

func (*Worker) UpdateMetadata

func (w *Worker) UpdateMetadata(metadata string)

type WorkerPingHandler added in v1.8.0

type WorkerPingHandler struct {
	UnimplementedWorkerSignalHandler
	// contains filtered or unexported fields
}

func (WorkerPingHandler) HandlePing added in v1.8.0

func (h WorkerPingHandler) HandlePing(ping *livekit.WorkerPing) error

type WorkerProtocolVersion

type WorkerProtocolVersion int

type WorkerRegisterHandler added in v1.13.8

type WorkerRegisterHandler func(req *livekit.RegisterWorkerRequest, res *livekit.RegisterWorkerResponse, reg *WorkerRegistration) error

WorkerRegisterHandler takes a turn during a worker's registration: it reads the request, validates the part it owns, and fills in its part of the response and the registration. Returning an error fails the registration.

type WorkerRegisterer added in v1.8.0

type WorkerRegisterer struct {
	WorkerPingHandler
	// contains filtered or unexported fields
}

func NewWorkerRegisterer added in v1.8.0

func NewWorkerRegisterer(conn SignalConn, serverInfo *livekit.ServerInfo, base WorkerRegistration, handlers ...WorkerRegisterHandler) *WorkerRegisterer

func (*WorkerRegisterer) Deadline added in v1.8.0

func (h *WorkerRegisterer) Deadline() time.Time

func (*WorkerRegisterer) HandleRegister added in v1.8.0

func (h *WorkerRegisterer) HandleRegister(req *livekit.RegisterWorkerRequest) error

func (*WorkerRegisterer) Registered added in v1.8.0

func (h *WorkerRegisterer) Registered() bool

func (*WorkerRegisterer) Registration added in v1.8.0

func (h *WorkerRegisterer) Registration() WorkerRegistration

type WorkerRegistration added in v1.8.0

type WorkerRegistration struct {
	Protocol    WorkerProtocolVersion
	ID          string
	Version     string
	AgentID     string
	AgentName   string
	Namespace   string
	JobType     livekit.JobType
	Permissions *livekit.ParticipantPermission
	ClientIP    string
	Deployment  string

	// agent HTTP endpoints data plane
	Endpoints        []*livekit.AgentHttp_AgentEndpoint
	InstanceID       string
	EndpointSettings *livekit.AgentHttp_AgentEndpointSettings

	// KindDetails, when set by the server, are stamped onto the participant
	// join token minted for every job assigned to this worker (e.g. marking
	// hosted/cloud agents so they can be distinguished from self-hosted ones in
	// observability). This is server-controlled and never populated from the
	// worker's register request.
	KindDetails []livekit.ParticipantInfo_KindDetail
}

func MakeWorkerRegistration added in v1.9.0

func MakeWorkerRegistration() WorkerRegistration

type WorkerSignalHandler added in v1.8.0

type WorkerSignalHandler interface {
	HandleRegister(*livekit.RegisterWorkerRequest) error
	HandleAvailability(*livekit.AvailabilityResponse) error
	HandleUpdateJob(*livekit.UpdateJobStatus) error
	HandleSimulateJob(*livekit.SimulateJobRequest) error
	HandlePing(*livekit.WorkerPing) error
	HandleUpdateWorker(*livekit.UpdateWorkerStatus) error
	HandleMigrateJob(*livekit.MigrateJobRequest) error
}

Directories

Path Synopsis
router
Package router matches request paths against an ordered table of starlette-style path templates.
Package router matches request paths against an ordered table of starlette-style path templates.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL