Is it possible to set references to agents like th...
# ask-ai
e
Is it possible to set references to agents like this
Copy code
# Create agents - they will access state via self.session.userdata
        intro_agent = IntroAgent()
        roleplay_agent = RoleplayAgent()
        quiz_agent = QuizAgent()
        case_study_agent = CaseStudyAgent()

        # Store agent references in userdata
        userdata.intro_agent = intro_agent
        userdata.roleplay_agent = roleplay_agent
        userdata.quiz_agent = quiz_agent
        userdata.case_study_agent = case_study_agent
or is there a better way?
t
Thanks for reaching out, Brian. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Regarding storing agent references on `userdata`: it’s possible, but not recommended. Userdata is intended for session context (small, serializable state) accessible via
session.userdata
and within tools through
RunContext
, while agents themselves should remain stateless. A better approach: • Keep only identifiers/config in
userdata
(e.g., which module to use next, params). • Expose each agent’s capabilities as callable tools and let the LLM invoke them to delegate or hand off work. Helpful references: • Userdata and access via
RunContext
Tool definition and use | LiveKit docs • Agent/session architecture Building voice agents | LiveKit Docs • Multi-agent design and delegating via tools/workflows Building Multi-Agent Architectures with LiveKit Agents Would you like a minimal example showing how to register tools for
IntroAgent
,
RoleplayAgent
, etc., and route using
userdata
? Sources: Workflows | LiveKit Docs | Tool definition and use | LiveKit docs | Building voice agents | LiveKit Docs | Building Multi-Agent Architectures with LiveKit Agents
e
no
t
Understood. To directly answer your original question: yes, you can set references on
userdata
, but the recommended pattern is to keep agents stateless and store only lightweight session context in
userdata
, using tools for delegation between agents. If you want, I can review a snippet of your current setup and suggest minimal changes to align with that pattern.