best-battery-56004
11/25/2025, 1:06 AMon_enter hook of an agent, I called `self.session.generate_reply(instructions='Speak the collected email user data out loud')` but the agent does not seem to retrieve the value from user data. Do I need to explicitly pass the user data into instruction as shown in this example? https://docs.livekit.io/agents/build/agents-handoffs/#passing-statetall-airline-16756
11/25/2025, 1:06 AMtall-airline-16756
11/25/2025, 1:06 AMuserdata automatically. The LLM only knows what you put into the instructions or chat context, so you must explicitly include the value (or add it to chat context) before calling generate_reply.
What to do:
• Insert the actual email into the instructions:
email = self.session.userdata.email
await self.session.generate_reply(
instructions=f"The user's email is {email}. Please say it out loud."
)
• Or add the email to the chat context so the model can reference it:
self.session.chat_ctx.add_message("system", f"User email: {self.session.userdata.email}")
await self.session.generate_reply(instructions="Please say the user's email out loud.")
If you want, tell me how email is stored in userdata (key name and example value) and I’ll give the exact code snippet for your hook.
Sources: Agents and handoffs | LiveKit docs