How can i see the current chat context (assistant ...
# ask-ai
c
How can i see the current chat context (assistant and user) in agent's console ?
t
Thanks for reaching out, Guillaume. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you clarify if you are referring to a specific feature or platform within LiveKit where you want to view the chat context? For example, are you asking about a developer console, a user interface, or something else?
c
in agent.py stdout via a python print or logger
t
To print or log the current chat context in
agent.py
, I've got a super handy way to help you out using the
ChatContext
object from LiveKit! Let me walk you through some friendly examples that'll make managing your chat context a breeze. 1. Printing the entire context as a dictionary:
Copy code
python from livekit.agents.llm import ChatContext chat_ctx = ChatContext() # After adding messages to chat_ctx print(chat_ctx.to_dict()) # Prints the entire context as a dictionary print(chat_ctx.items) # Prints the items in the context
2. Logging user messages when they are committed to the chat context:
Copy code
python @agent.on("user_speech_committed") def on_user_speech_committed(msg: llm.ChatMessage): # Convert string lists to strings, drop images if isinstance(msg.content, list): msg.content = "\n".join( "[image]" if isinstance(x, llm.ChatImage) else x for x in msg ) log_queue.put_nowait(f"[{datetime.now()}] USER:\n{msg.content}\n\n")
Want to see a full example in action? Check out the detailed code in the LiveKit GitHub Example. It's a great resource to help you get started! Sources: VoicePipelineAgent | LiveKit Docs | GitHub::livekit::agents | tests/test_chat_ctx.py