DeewanDocs
API keys

Voice agents and avatars

Bring your own AI agent into a meeting: agent tokens, end-to-end encryption, the agent's state, and an avatar that speaks for it.

An AI voice agent (LiveKit Agents, or your own) joins a Deewan meeting like a person, with one difference: its token says it's an agent. Deewan then keeps it out of attendance and people counts, lets it send captions and its state whatever the room's chat setting, and never makes it a host. Its minutes are billed like a participant's.

1. An agent token, and joining encrypted

python
# pip install "deewan[rtc]"
from deewan import Deewan
from deewan.rtc import connect

deewan = Deewan(api_key=os.environ["DEEWAN_API_KEY"])
token = deewan.rooms.create_token(room_id, name="Nour", kind="agent", max_duration_seconds=3600)

room = await connect(token)   # applies the meeting's end-to-end encryption key
# LiveKit Agents:
# await session.start(agent, room=room, room_options=RoomOptions(participant_identity=person_identity))

Deewan meetings are end-to-end encrypted. A bot that connects without the meeting key hears and sends only noise, with no error — connect applies it for you. Strict rooms keep their key on participants' devices only, so server-side agents can't join them; use standard rooms for AI calls.

2. The agent's state

Agents set their own attributes through Deewan, with their own room token: lk.agent.* (LiveKit Agents' keys, such as lk.agent.state) and your app.* keys. No connection can set attributes directly on the media server, because clients trust attributes like role to know who is a host.

python
from deewan import ParticipantClient

me = ParticipantClient(token)   # the agent's own room token, not your API key

def on_state(ev):  # off the event loop: it's an HTTPS call
    asyncio.create_task(asyncio.to_thread(me.set_attributes, {"lk.agent.state": str(ev.new_state)}))

session.on("agent_state_changed", on_state)
await asyncio.to_thread(me.set_attributes, {"app.ends_at": str(ends_at_ms)})

3. An avatar that speaks for the agent

An avatar renderer joins with its own agent token and publish_on_behalf set to the agent's identity. Clients then show its video and audio as the agent's. It may only name an agent that is in the room, never a person.

python
avatar = deewan.rooms.create_token(room_id, name="Nour", kind="agent", max_duration_seconds=3600,
                                   publish_on_behalf=token["identity"])
# Give the avatar server only this response: one room, one meeting key, never your API key.

4. In the person's browser

ts
import { joinMeeting } from "@deewanio/sdk/client";

const meeting = await joinMeeting(tokenFromYourServer, { publish: { microphone: true } });
meeting.on("agents", (agents) => {
  const coach = agents.find((a) => !a.speaksFor);
  statusLabel.textContent = coach?.state ?? "connecting";   // listening · thinking · speaking
});
meeting.on("trackSubscribed", ({ participantId, onBehalfOf, kind, attach }) => {
  // An avatar's video belongs to the agent it speaks for.
  if (kind === "video" && onBehalfOf) attach(coachVideo);
});

Rules that keep it safe

  • max_duration_seconds is required for agent tokens, so a stuck bot ends on its own.
  • Agents are never hosts and can't rewrite role, cohost or their time limit.
  • publish_on_behalf only names an agent in the same room, never a person.
  • Agent minutes are billed like a participant's, and count against your balance while they run.
  • Keep your API key on your server. Agents and avatars only ever get their own room token.