I am using Python SDK. In `on_enter` hook of an ag...
# ask-ai
b
I am using Python SDK. In
on_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-state
t
Thanks for reaching out, Masayuki. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're right to check — the agent will not see
userdata
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:
Copy code
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:
Copy code
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