worried-petabyte-38885
08/27/2025, 12:32 PMtall-airline-16756
08/27/2025, 12:32 PMtall-airline-16756
08/27/2025, 12:33 PM<livekit.agents.llm.chat_context.ChatContext object at 0x1278dc750> in a way that’s easy to read, a handy trick is to use the to_dict() method from the ChatContext class. This method turns the object into a dictionary, making it super simple to print out or work with.
Here’s a quick example to get you started:
from livekit.agents.llm import ChatContext
# Create a ChatContext object
chat_ctx = ChatContext()
chat_ctx.add_message(
role="user",
content="Hello, world!",
)
chat_ctx.add_message(
role="assistant",
content="Hello, world!",
)
# Convert and print the ChatContext object in a readable format
print(chat_ctx.to_dict())
Also, the to_dict() method lets you tweak what gets included in the output with some optional parameters:
• `exclude_image`: Skip image content (default: True)
• `exclude_audio`: Skip audio content (default: True)
• `exclude_timestamp`: Skip timestamp info (default: True)
• `exclude_function_call`: Skip function call info (default: False)
Feel free to adjust these to fit what you need!
Sources: livekit-agents/livekit/agents/llm/_provider_format/mistralai.py