refined-hydrogen-81988
11/07/2025, 8:33 PMtall-airline-16756
11/07/2025, 8:33 PMtall-airline-16756
11/07/2025, 8:34 PMon_enter hook. This hook is a great place to run custom logic when an agent becomes active in a session, so it’s perfect for dynamically setting or updating the agent’s behavior.
Here’s how you can do it:
1. First, access the chat context using self.chat_ctx.
2. Then, add a system message with the add_message() method, making sure to use role="system".
3. Finally, call self.update_chat_ctx() to save your changes.
For example:
async def on_enter(self) -> None:
agent_name = self.__class__.__name__
chat_ctx = self.chat_ctx.copy()
chat_ctx.add_message(
role="system",
content=f"You are the {agent_name}. {userdata.summarize()}"
)
await self.update_chat_ctx(chat_ctx)
self.session.generate_reply()
If you have any questions or need a hand with this, please don’t hesitate to reach out—I’m here to help!
Sources: pipeline-llm/large_context.py | Company directory phone assistant | LiveKit Docs | delay-handling/agent.py | Pipeline nodes and hooks | LiveKit docs