livekit / agents

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

Room metadata occasionally missing #781

Open sw956 opened 1 month ago

sw956 commented 1 month ago

I am occasionally running into empty room metadata when the agent connects to a room. The code which creates the room looks something like:

Call<LivekitModels.Room> room_create_call = client.createRoom(id, emptyTimeout, null /* maxParticipants */, null /* nodeId */, room_metadata);
Response<LivekitModels.Room> response = room_create_call.execute();
LivekitModels.Room room = response.body();

The log will correctly display the metadata (metadata: \"{\\\"id\\\": \\\"66e040841d9cdd45f4350930\\\"}\") when logging the job request:

{"message": "registered worker", "level": "INFO", "id": "AW_MaW2CtKGRcz4", "server_info": "edition: Cloud\nversion: \"1.7.2\"\nprotocol: 15\nregion: \"UK\"\nnode_id: \"NC_OLONDON1A_H7YCbSveaF7b\"\n", "timestamp": "2024-09-19T10:11:16.446614+00:00"}
{"message": "received job request", "level": "INFO", "job_request": "id: \"AJ_Kt8zXFmF4cNZ\"
room {
  sid: \"RM_ydvT2weubqVX\"
  name: \"66ebf8c884f7033217395090\"
  empty_timeout: 20
  creation_time: 1726740680
  enabled_codecs {
    mime: \"video/H264\"
  }
  enabled_codecs {
    mime: \"video/VP8\"
  }
  enabled_codecs {
    mime: \"video/VP9\"
  }
  enabled_codecs {
    mime: \"video/AV1\"
  }
  enabled_codecs {
    mime: \"audio/red\"
  }
  enabled_codecs {
    mime: \"audio/opus\"
  }
  metadata: \"{\\\"id\\\": \\\"66e040841d9cdd45f4350930\\\"}\"
  version {
    unix_micro: 1726740680392110
  }
  departure_timeout: 20
}
state {
  updated_at: 1726740681359963211
}
", "resuming": false, "agent_name": "", "timestamp": "2024-09-19T10:11:21.362849+00:00"}

The agent code (assistant.py):

def preload(proc: JobProcess):
    proc.userdata["vad"] = silero.VAD.load()

async def entrypoint(ctx: JobContext):
    await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)

    try:
        room_metadata = json.loads(ctx.room.metadata)
    except Exception as e:
        logger.info(ctx.room.metadata) # logs empty string

if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, prewarm_fnc=preload))

Run with

python assistant.py start

Python 3.12.3 with package versions:

livekit                    0.16.2
livekit-agents             0.8.12
livekit-api                0.7.0
livekit-plugins-cartesia   0.4.2
livekit-plugins-deepgram   0.6.7
livekit-plugins-elevenlabs 0.7.4
livekit-plugins-openai     0.8.3
livekit-plugins-silero     0.6.4
livekit-protocol           0.6.0
firattamurlc commented 1 week ago

Is there any update on this issue ?