glamorous-oil-12326
09/25/2025, 8:26 PMtall-airline-16756
09/25/2025, 8:26 PMtall-airline-16756
09/25/2025, 8:27 PMself.session.userdata and context.userdata both point to the same user data object, but choosing which to use really depends on where you are in your code:
• Use self.session.userdata when you're inside an agent's methods, like on_enter(). This is a great way to access or update user data directly, especially within class methods of agents.
• Use context.userdata when you're working inside function tools that receive a RunContext parameter. This lets your tools independently read and update the user's state smoothly.
This little distinction helps keep user data management clear and effective, depending on whether you're dealing with the agent's internal state or the tool's execution context. I hope this makes things a bit clearer for you!
Sources: agents/src/voice/run_context.ts | examples/drive-thru/drivethru_agent.py | flows/declarative_flow.py | Building Multi-Agent Architectures with LiveKit Agents