broad-painter-9222
12/15/2025, 4:24 PMtall-airline-16756
12/15/2025, 4:24 PMtall-airline-16756
12/15/2025, 4:24 PMbroad-painter-9222
12/15/2025, 4:24 PMtall-airline-16756
12/15/2025, 4:25 PMfrom livekit.agents import Agent, ChatContext, ChatMessage
class MyAgent(Agent):
async def on_user_turn_completed(
self,
turn_ctx: ChatContext,
new_message: ChatMessage,
) -> None:
# Insert a system message after the user's turn
turn_ctx.add_message(
role="system",
content="Always be polite and concise in your response."
)
# Persist the updated chat context so the system message is saved
await self.update_chat_ctx(turn_ctx)
If you want the system message content to vary per user turn, replace the static string with logic that builds the message from new_message or other state. Would you like an example that customizes the system message dynamically?