enough-football-27052
12/23/2025, 4:26 AMtall-airline-16756
12/23/2025, 4:26 AMtall-airline-16756
12/23/2025, 4:26 AMturn_ctx.messages (includes system instructions) and log/store them.
• Log after the agent responds: listen for conversation events (e.g., conversation_item_added) and inspect session.chat_ctx.messages when an assistant message is added.
• Persist snapshots: write a copy of the full chat_ctx messages into session.userdata (or your own storage) each turn so you can review complete context history later.
• For tests: the run method returns a result with session.chat_ctx.messages you can examine.
Minimal examples
1) Before agent replies (Python-style):
async def on_user_turn_completed(self, turn_ctx: ChatContext, new_message: ChatMessage):
# Full context (system + history + new user message)
snapshot = [{ "role": m.role, "content": m.content } for m in turn_ctx.messages]
print("Context before reply:", snapshot)
# Or store snapshot in persistent storage
2) After agent replies (session event):
@session.on("conversation_item_added")
def on_conversation_item(item):
if item.type == "message" and item.role == "assistant":
# Full context after assistant response
print("Context after reply:", session.chat_ctx.messages)
3) Save snapshot to session.userdata:
self.session.userdata["last_full_context"] = [
{"role": m.role, "content": m.content} for m in session.chat_ctx.messages
]
Notes
• ChatContext / session.chat_ctx.messages contains system instructions, user messages, agent replies, and tool calls — so it gives the complete prompt context.
• Use on_user_turn_completed to capture the prompt the LLM will see next; use conversation events to capture the state after the agent response.
Tell me which option you prefer and whether you want a complete code snippet for Node.js or Python, and I’ll provide it.
Sources: Agents (Node.js) | livekit/livekit_composite | DeepWiki | Testing and evaluation | LiveKit docs | Pipeline nodes and hooks | LiveKit docs