Hi everyone, I'm new to livekit but managed to dep...
# agents
a
Hi everyone, I'm new to livekit but managed to deploy my first agent. now I want to provide agent context related to the user. How would I be able to do this? All the examples and demos that I have seen so far just hardcode the values.
l
Welcome, we have the concept of userdata, https://docs.livekit.io/agents/build/agents-handoffs/#passing-state. It's used by a few of our examples, for example the drive thru agent uses it to build the user's menu items: https://github.com/livekit-examples/python-agents-examples/blob/main/complex-agents/drive-thru/drivethru_agent.py
a
Hi @lively-winter-88668 thank you - I had already taken a look at that example and the referred docs. Aren't both using hardcoded values though. Let's say I deployed this agent on livekit cloud and am starting a new call - how do I change say the user's name?
Please let me know if that makes sense
l
If you need to persist data across different sessions, then you would need to store that data externally and retrieve it. We have this example, https://github.com/livekit-examples/python-agents-examples/tree/main/complex-agents/personal_shopper, which persists customer orders in a database. That same example also shows how to use a function tool to retrieve the user's name, https://github.com/livekit/livekit_composite/blob/cd1a2500/livekit-examples/python[…]ts-examples/complex-agents/personal_shopper/personal_shopper.py. You
a
Hi @lively-winter-88668 - thanks, my issue for that is resolved
s
I think the summary is to add those values into the prompt created in
on_enter
no? @lively-winter-88668. We also do
Copy code
async def on_user_turn_completed(self, turn_ctx: ChatContext, new_message: ChatMessage):
        """
        Called when the user has finished their turn - or before the agent starts its first turn
        """
        # we need to update instructions in case the context slots were updated since entering
        # the given agent
        confidence = new_message.transcript_confidence or -1.0
        confidence = round(confidence, 2)
        logger.info(f"User: {new_message.text_content} ({confidence})")
        await self.update_instructions(self.create_prompt())
which helps add things to the context if collected during the last turn. This also helps us to log what the user said and what's the confidence. Is this good practice? (calling
update_instructions
in
on_user_turn_completed
)