clean-autumn-36199
07/14/2025, 9:43 AMChatMessage
objects from the AgentSession.history
object? The log proves that simply accessing the .messages
attribute is not correct. It might be a method call like history.get_messages()
or the ChatContext
object itself might be iterable (e.g., for msg in history:
).tall-airline-16756
07/14/2025, 9:43 AMtall-airline-16756
07/14/2025, 9:43 AMChatMessage
objects from an AgentSession.history
(which is a ChatContext
instance) is to use the .items
property, not .messages
. The .items
attribute contains all chat items, including messages and other types (like function calls), so you should filter for the specific type you want:
chat_items = session.history.items # List of all ChatItem objects
chat_messages = [item for item in chat_items if item.type == "message"]
• There is no .messages
attribute or get_messages()
method.
• If you use direct iteration, you need to filter for message types explicitly.
For more details on working with ChatContext
and filtering, see the above pattern and the available properties and methods such as get_by_id
and copy
.
Sources: livekit-agents/livekit/agents/llm/chat_context.py