From 23b5bce98327791e84c641fcf0f9c4f0b32d1e64 Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 28 Feb 2026 11:04:02 -0800 Subject: [PATCH] fix: extract auth header from job.metadata instead of agent_dispatch LiveKit passes RoomAgentDispatch metadata through as job.metadata (protobuf field), not via a separate agent_dispatch object. Also use room_io.RoomInputOptions for participant targeting (livekit-agents 1.x). Co-Authored-By: Claude Opus 4.6 --- packages/services/voice-agent/src/agent.py | 28 +++++++--------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/packages/services/voice-agent/src/agent.py b/packages/services/voice-agent/src/agent.py index 8051a81..56a5003 100644 --- a/packages/services/voice-agent/src/agent.py +++ b/packages/services/voice-agent/src/agent.py @@ -102,28 +102,16 @@ async def entrypoint(ctx: JobContext) -> None: participant.name, ) - # Extract auth header from room agent dispatch metadata - # The token endpoint embeds {"auth_header": "Bearer ..."} in dispatch metadata + # Extract auth header from job metadata + # The token endpoint embeds {"auth_header": "Bearer ..."} via RoomAgentDispatch metadata, + # which LiveKit passes through as job.metadata to the agent worker. auth_header = "" - dispatch_metadata = ctx.room.name # fallback try: - # Try to get metadata from the agent dispatch - job = ctx.job - if job and hasattr(job, "agent_dispatch") and job.agent_dispatch: - meta_str = job.agent_dispatch.metadata or "{}" - meta = json.loads(meta_str) - auth_header = meta.get("auth_header", "") - except Exception: - pass - - # Fallback: try participant metadata - if not auth_header: - try: - meta_str = participant.metadata or "{}" - meta = json.loads(meta_str) - auth_header = meta.get("auth_header", "") - except Exception: - pass + meta_str = ctx.job.metadata or "{}" + meta = json.loads(meta_str) + auth_header = meta.get("auth_header", "") + except Exception as e: + logger.warning("Failed to parse job metadata: %s", e) logger.info("Auth header present: %s", bool(auth_header))