how can I get unique ID for each AgentSession?
# ask-ai
f
how can I get unique ID for each AgentSession?
t
Thanks for reaching out, Taras. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I understand you’re looking for a way to have a unique ID for each
AgentSession
since LiveKit doesn’t provide one out of the box. No worries! You can easily create and manage unique IDs yourself using a few handy methods: • Using `shortuuid()`: This is a neat utility that generates a 12-character random string, and you can even add a prefix if you like. For example, in Python:
from livekit.agents.utils import shortuuid; session_id = shortuuid("AS_")
. • Using `guid.New()`: If you’re working with Go-based services,
utils.NewGuid("AS_")
is a great way to create globally unique IDs. • Using standard UUIDs: Another option is Python’s
uuid.uuid4()
, which ensures maximum uniqueness, though it’s a bit more detailed. After you generate the ID, just be sure to store it in your session context or user data so you can easily reference it throughout the session. If you’d like, I’m here to help guide you through the implementation—just let me know! Sources: livekit-agents/livekit/agents/utils/misc.py | livekit/livekit_sip.twirp.go | rpc/rpc_agent.py