I am testing my agent with multiple concurrent cal...
# ask-ai
r
I am testing my agent with multiple concurrent calls. I need to access teh worker number inside the while doing agent Session initialisation so initalise some components based on worked id. how can I achieve this?
t
Thanks for reaching out, Taresh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To access the worker ID during agent session initialization in LiveKit, you can use the
JobContext
object. Each worker is assigned a unique string-based
worker_id
when it registers with the LiveKit server. Here's how you can access it:
Copy code
async def entrypoint(ctx: JobContext):
    # Access the worker ID
    worker_id = ctx.worker_id
    print(f"Agent running on worker: {worker_id}")

    # Your agent logic here
    await ctx.connect()
The
worker_id
is a string identifier, not a numeric value. If you need a numeric representation, you can hash or convert the string ID in your application code. Sources: livekit-agents/livekit/agents/worker.py | livekit/livekit_agent.pb.go