big-school-62939
12/19/2025, 1:49 AMtall-airline-16756
12/19/2025, 1:49 AMtall-airline-16756
12/19/2025, 1:49 AMusing System.Collections;
using UnityEngine;
using LiveKit; // your LiveKit Unity SDK namespace
public class LiveKitConnector : MonoBehaviour
{
IEnumerator Start()
{
var room = new Room();
// use your LiveKit wss url and the participant token returned by your backend
var connOp = room.Connect("wss://<your-project>.livekit.cloud", "<participant-token>");
yield return connOp;
if (!connOp.IsError)
{
Debug.Log("Connected to room");
// now room exists and participants are present
}
else
{
Debug.LogError("Connect error: " + connOp.Error);
}
}
}
2) Backend (server) — generate a token that requests agent dispatch
• The Unity client must receive a participant token generated by your backend.
• When creating that token, include room join permission for the room name and add a RoomConfiguration that dispatches the agent. Example (Node.js/TypeScript style):
import { AccessToken, VideoGrant } from "livekit-server-sdk";
import { RoomConfiguration, RoomAgentDispatch } from "@livekit/protocol";
const at = new AccessToken(API_KEY, API_SECRET, { identity: "user-id" });
const grant: VideoGrant = { room: "my-room", roomJoin: true };
at.addGrant(grant);
// request agent dispatch when this token is used to connect
at.roomConfig = new RoomConfiguration({
agents: [
new RoomAgentDispatch({ agentName: "my-agent", metadata: "optional" })
],
});
const token = at.toJwt();
// return `token` to the Unity client
What happens when Unity connects with that token
• The first client connection creates the room.
• LiveKit sees the token includes roomConfig and dispatches the specified agent to join the room automatically.
• The agent itself runs as a separate service and joins via its own SDK; you do not write agent-join code in Unity.
If you want, I can:
• Provide a concrete backend snippet for your language (Node/Python/Go).
• Show an example agent service connection snippet.
Which would you like?
Sources: Unity quickstart (WebGL) | LiveKit docs | Agent-assisted warm transfer | LiveKit docs | Agent dispatch | LiveKit docsbig-school-62939
12/19/2025, 1:53 AMtall-airline-16756
12/19/2025, 1:53 AMwinget install LiveKit.LiveKitCLI
◦ or download from https://github.com/livekit/livekit-cli/releases
• Authenticate to your project: lk cloud auth
• Ensure your agent is deployed/registered (you can deploy with lk agent create ./agent-directory if you need to).
A — Dispatch an agent to a room now (creates room if needed)
1. Run:
lk dispatch create --agent-name test-agent --room my-room --metadata '{"user_id":"12345"}'
1. Verify dispatch / agent status:
lk agent list
lk agent status --id <agent-id>
lk agent logs --id <agent-id>
B — Generate a participant token that triggers agent dispatch when the participant connects
1. Create a token that includes dispatch:
lk token create --api-key <livekit_api_key> --api-secret <livekit_api_secret> --room my-room --identity test-participant --join --dispatch-agent test-agent --dispatch-metadata '{"user_id":"12345"}' --valid-for 24h
This prints a token you can use in your Unity app.
1. Use that token in your Unity room.Connect(wssUrl, token) call — when the participant connects, LiveKit will dispatch test-agent automatically.
Notes
• lk dispatch create is useful for ad-hoc testing; lk token create --dispatch-agent simulates the real flow where the token causes dispatch on participant join.
• Use lk agent logs to watch the agent join events and debug any issues.
Would you like a ready-made Unity snippet that uses the token printed by lk token create, or a specific CLI command tailored to your project name and agent name?
Sources: LiveKit CLI Setup | LiveKit Docs | Agent dispatch | LiveKit docs | livekit/livekit_composite | DeepWiki