abundant-father-33863
09/25/2025, 8:41 AMtall-airline-16756
09/25/2025, 8:41 AMtall-airline-16756
09/25/2025, 8:41 AMsession.history but want to exclude system instructions, you can easily do this by using the copy() method from the ChatContext class with the exclude_instructions=True parameter. Let me show you an example:
# Get chat history excluding system instructions
filtered_history = session.history.copy(exclude_instructions=True)
# Iterate through the filtered messages
for item in filtered_history.items:
if item.type == "message":
print(f"{item.role}: {item.content}")
This way, you'll filter out messages coming from roles like "system" or "developer," while keeping all the user and assistant messages intact. I hope this helps! If you have any more questions, feel free to ask.
Sources: examples/voice_agents/session_close_callback.py | agents/src/llm/chat_context.test.ts | Workflows | LiveKit Docs | Agent-assisted warm transfer | LiveKit Docsabundant-father-33863
09/25/2025, 9:22 AMtall-airline-16756
09/25/2025, 9:23 AMcontent field in session.history messages! It’s designed as an array to comfortably support multimodal content, which means a single message can include different parts like text and images all together. Here’s how it works:
• Text parts come through as simple strings.
• Image parts show up as objects containing important details like type and URL.
This setup really helps create rich, flexible interactions, especially when you’re working with both text and visuals. If you’d like to handle the content as one single string, you can easily combine the array elements like this:
# Convert array content to a single string
if isinstance(msg.content, list):
msg.content = "\n".join(
"[image]" if isinstance(x, dict) and x.get("type") == "image_url" else x
for x in msg.content
)
This way, you keep everything compatible while still enjoying the benefits of multimodal content. If you have any more questions or want to dive deeper, I’m here to help!
Sources: tools/server/themes/wild/index.html | VoicePipelineAgent | LiveKit Docs | Working with the MultimodalAgent class | LiveKit Docsabundant-father-33863
09/25/2025, 9:24 AMtall-airline-16756
09/25/2025, 9:24 AMsession.history while skipping other content types. You can do this by checking if the content is a string. Here's a simple example for you:
# Filter and process only text messages
for item in session.history.items:
if isinstance(item.content, list):
for content in item.content:
if isinstance(content, str):
print(f"Text: {content}")
This way, you'll make sure to process only the text parts of the messages and gently skip over other types like images or metadata. If you have any questions or need further assistance, feel free to ask!
Sources: Events and error handling | LiveKit Docs | Agent-assisted warm transfer | LiveKit Docsabundant-father-33863
09/25/2025, 9:59 AMtall-airline-16756
09/25/2025, 9:59 AMcontent field's value from a list to text content while keeping the entire object list intact. You can do this by iterating through session.history.items and updating the content field as needed. Here's a simple example to guide you:
# Replace list content with text while keeping the object list intact
for item in session.history.items:
if isinstance(item.content, list):
# Convert list to a single string
item.content = "\n".join(
"[image]" if isinstance(x, dict) and x.get("type") == "image_url" else str(x)
for x in item.content
)
This approach will help transform the content field into a more readable text format, while still preserving the rest of the object structure.
Also, if you'd like these changes to be saved across agent turns, don't forget to call update_chat_ctx() to sync the modifications back to the active chat context.
Sources: Workflows | LiveKit Docs | VoicePipelineAgent | LiveKit Docs | VoicePipelineAgent | LiveKit Docs | Working with the MultimodalAgent class | LiveKit Docs | Working with the MultimodalAgent class | LiveKit Docs