Skip to main content

AgentDispatchService API

Use LiveKit's AgentDispatchService API to explicitly dispatch agents to rooms from your backend.

Overview

Use this API to control which agents join which rooms and when, rather than relying on automatic dispatch.

These APIs are available via server SDKs and the LiveKit CLI:

To learn more about how agent dispatch works, see Agent dispatch.

Implementation details

LiveKit provides server SDKs that make it easy to use these APIs. You can also implement your own client using the details in the following sections.

Endpoints

The AgentDispatchService API is built with Twirp. Arguments are passed as JSON to an endpoint using the POST method.

The AgentDispatchService API is accessible via /twirp/livekit.AgentDispatchService/<MethodName>. For example:

https://<your LiveKit URL domain>/twirp/livekit.AgentDispatchService/CreateDispatch

Authorization header

All endpoints require a signed access token with roomAdmin permission. Set the token via HTTP header:

Authorization: Bearer <token>

LiveKit server SDKs automatically include the above header.

To generate a token using the LiveKit CLI:

export TOKEN=$(lk token create \
--api-key "$LIVEKIT_API_KEY" \
--api-secret "$LIVEKIT_API_SECRET" \
--room "my-room" \
--admin | grep "Access token:" | awk '{print $3}')
Extract only the JWT

The lk token create command outputs human-readable grant information alongside the token. Pipe through grep and awk as shown above to capture only the JWT.

Omit --room to generate a token with server-wide roomAdmin access, which allows dispatching to any room.

Post body

Twirp expects an HTTP POST request. The body must be a JSON object (application/json) containing parameters specific to that request.

For example, the following creates a dispatch for agent my-agent in room my-room:

curl -X POST https://<your LiveKit URL domain>/twirp/livekit.AgentDispatchService/CreateDispatch \
-H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: application/json' \
-d '{ "agent_name": "my-agent", "room": "my-room" }'

When passing in parameters, the server accepts either snake_case or camelCase for keys.

AgentDispatchService APIs

The AgentDispatchService API allows you to create, delete, and list agent dispatches.

Tip

All RPC definitions can be found in livekit_agent_dispatch.proto.

CreateDispatch

Explicitly dispatch a named agent to a room. Requires roomAdmin permission.

If the room doesn't exist, it's created automatically.

Returns AgentDispatch.

ParameterTypeRequiredDescription
agent_namestringyesName of the agent to dispatch. Must match the agent_name set in the agent server.
roomstringyesName of the room to dispatch the agent to.
metadatastringOptional metadata to pass to the agent. Opaque to LiveKit.
restart_policyJobRestartPolicyControls whether the job is restarted if it fails. Cloud only. Defaults to JRP_ON_FAILURE.

DeleteDispatch

Delete an existing agent dispatch. Requires roomAdmin permission.

Returns AgentDispatch.

ParameterTypeRequiredDescription
dispatch_idstringyesID of the dispatch to delete.
roomstringyesName of the room the dispatch belongs to.

ListDispatch

List agent dispatches for a room. Requires roomAdmin permission.

Returns ListAgentDispatchResponse.

ParameterTypeRequiredDescription
roomstringyesName of the room to list dispatches for.
dispatch_idstringIf set, only the dispatch with this ID is returned.

Types

The AgentDispatchService API includes the following types.

AgentDispatch

Represents a single agent dispatch.

FieldTypeDescription
idstringUnique identifier for this dispatch.
agent_namestringName of the dispatched agent.
roomstringName of the room the agent is dispatched to.
metadatastringUser-specified metadata, opaque to LiveKit.
stateAgentDispatchStateCurrent state of the dispatch.
restart_policyJobRestartPolicyRestart policy for this dispatch. Cloud only.

AgentDispatchState

The current state of an agent dispatch.

FieldTypeDescription
jobsList<Job>Jobs associated with this dispatch. For room-type dispatches, there is at most one job. For publisher-type dispatches, there is one job per publisher.
created_atint64Unix timestamp (seconds) when the dispatch was created.
deleted_atint64Unix timestamp (seconds) when the dispatch was deleted. Zero if not yet deleted.

ListAgentDispatchResponse

Returned by ListDispatch, containing all dispatches matching the request.

FieldTypeDescription
agent_dispatchesList<AgentDispatch>List of agent dispatches matching the request.

Job

Represents a single agent job. Defined in livekit_agent.proto. Nested types Room and ParticipantInfo are defined in livekit_models.proto.

FieldTypeDescription
idstringUnique identifier for this job.
dispatch_idstringID of the dispatch that created this job.
typeJobTypeWhether this job is assigned to the room (JT_ROOM) or per publisher (JT_PUBLISHER).
roomRoomRoom the job is running in.
participantParticipantInfoParticipant associated with the job. Only set for publisher-type jobs.
metadatastringMetadata passed during dispatch.
agent_namestringName of the agent handling this job.
stateJobStateCurrent state of the job.
enable_recordingboolWhether Egress recording is enabled for this job.

JobState

Tracks the runtime status and timing of a job from assignment through completion. Defined in livekit_agent.proto.

FieldTypeDescription
statusJobStatusCurrent status of the job.
errorstringError message if the job failed.
started_atint64Unix timestamp (seconds) when the job started.
ended_atint64Unix timestamp (seconds) when the job ended. Zero if still running.
updated_atint64Unix timestamp (seconds) when the job state was last updated.
participant_identitystringIdentity of the participant associated with this job.
worker_idstringID of the worker handling this job.
agent_idstringID of the agent instance handling this job.

JobType

The type of a job, determining how agents are assigned to participants. Defined in livekit_agent.proto.

ValueDescription
JT_ROOMThe agent is assigned to the room. At most one job per dispatch.
JT_PUBLISHERThe agent is assigned per publisher. One job is created for each participant who publishes a track.

JobStatus

The current execution status of a job. Defined in livekit_agent.proto.

ValueDescription
JS_PENDINGThe job has been created but not yet started.
JS_RUNNINGThe job is actively running.
JS_SUCCESSThe job completed successfully.
JS_FAILEDThe job failed.

JobRestartPolicy

Controls whether a failed job is restarted. Cloud only.

ValueDescription
JRP_ON_FAILURERestart the job if it fails. This is the default.
JRP_NEVERNever restart the job, even if it fails.