livekit / agents

Build real-time multimodal AI applications 🤖🎙️📹
https://docs.livekit.io/agents
Apache License 2.0
4.07k stars 427 forks source link

Running agents with connect --room causes worker to receive sometimes two job requests instead of one #1063

Open tpapaj opened 2 weeks ago

tpapaj commented 2 weeks ago

Hello! I am running simple livekit worker with command python main.py connect --room tpapaj-room (where tpapaj-room can be anything) using function

from livekit.agents import AutoSubscribe, JobContext, WorkerOptions, cli, llm
(...)
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))

where entrypoint is my function where I create VoiceAssistant etc.

Sometimes it works correctly and one job request is received:

2024-11-09 17:33:47,917 - INFO livekit.agents - starting worker {"version": "0.10.1", "rtc-version": "0.18.0"}
2024-11-09 17:33:48,258 - INFO livekit.agents - registered worker {"id": "AW_xxxWY4", "region": "Germany", "protocol": 15, "node_id": "NC_xxxF3R"}
2024-11-09 17:33:48,259 - INFO livekit.agents - connecting to room tpapaj-room 
2024-11-09 17:33:48,526 - INFO livekit.agents - received job request {"job_id": "AJ_xxxiSW", "dispatch_id": "", "room_name": "tpapaj-room", "agent_name": "", "resuming": false}

Sometimes on startup worker receives two job requests:

2024-11-09 17:34:15,144 - INFO livekit.agents - starting worker {"version": "0.10.1", "rtc-version": "0.18.0"}
2024-11-09 17:34:15,505 - INFO livekit.agents - registered worker {"id": "AW_yxxxWiS", "region": "Germany", "protocol": 15, "node_id": "NC_xxx39j"}
2024-11-09 17:34:15,507 - INFO livekit.agents - connecting to room tpapaj-room 
2024-11-09 17:34:16,473 - INFO livekit.agents - received job request {"job_id": "AJ_xxxvAt", "dispatch_id": "", "room_name": "tpapaj-room", "agent_name": "", "resuming": false}
2024-11-09 17:34:16,581 - INFO livekit.agents - received job request {"job_id": "AJ_xxxPpE", "dispatch_id": "", "room_name": "tpapaj-room", "agent_name": "", "resuming": false}

This causes application to create two agents(entrypoint function is called twice) who then start talk to each other in a room. As you can see, received job requests have different ids(I masked parts of ids with xxx strings, just in case). It looks like it has tendency to create two agents when --room argument uses a room name that was not used for a while and restarting the worker with the same room usually works correctly and creates a single agent.

I expected to see just one job request being sent to the worker.

It seems to be similar issue to https://github.com/livekit/agents/issues/759 but it is claimed there that the problem was fixed, but I still see the problem. I tried livekit-agent versions 0.10.1, 0.10.2, 0.11.1 without success.

Current livekit packages in pip freeze:

livekit==0.18.0
livekit-agents==0.11.1
livekit-api==0.7.1
livekit-plugins-elevenlabs==0.7.7
livekit-plugins-openai==0.10.5
livekit-plugins-silero==0.7.3
livekit-protocol==0.6.0