bulky-wall-61623
11/05/2025, 8:29 AMself.session in the agent is session: AgentSession[Unknown], but I want it to be AgentSession[UserData].tall-airline-16756
11/05/2025, 8:29 AMtall-airline-16756
11/05/2025, 8:30 AMsession to carry a typed userdata so it’s AgentSession[UserData] instead of AgentSession[Unknown].
You can do this by:
• Defining your userdata type, then
• Passing it when constructing the session and annotating the session with that type. Userdata is then available as session.userdata and in tools via RunContext.
Could you share:
• Which SDK you’re using (Python or TypeScript)?
• The snippet where you construct or store self.session?
I’ll provide the exact annotation/constructor syntax for your SDK. For reference on userdata with sessions, see the docs: Workflows | LiveKit Docs and Building voice agents | LiveKit Docs.
Sources: Workflows | LiveKit Docs | Building voice agents | LiveKit Docsbulky-wall-61623
11/05/2025, 8:32 AMclass ChatAgent(BaseAgent):
@override
async def on_enter(_self_) -> None:
@self.session.on("agent_state_changed") _# pyright: ignore[reportUntypedFunctionDecorator, reportUnknownMemberType]_
def _on_agent_state_changed(_event_: AgentStateChangedEvent) -> None: _# pyright: ignore[reportUnusedFunction]_
asyncio.create_task(self.on_agent_state_changed(event)) _# pyright: ignore[reportUnusedCallResult]_
return _await_ super().on_enter()
async def on_agent_state_changed(_self_, _ev_: AgentStateChangedEvent) -> None:
ss: AgentSession[UserData] = self.session
_if_ ev.new_state == "listening"
ctx = get_job_context()
_ = _await_ ctx.api.room.delete_room(DeleteRoomRequest(_room_=ctx.room.name))tall-airline-16756
11/05/2025, 8:33 AM