I’m using `session.history.add_message(role="syste...
# ask-ai
c
I’m using `session.history.add_message(role="system", content=[ImageContent(image=image_url)])`to add an image to the chat history but when I look at the logs, it doesn’t seem like it worked, the content section of the message is an empty array. What am I missing?
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.
Hi there! I wanted to let you know that the method
session.history.add_message
isn’t available in LiveKit. But no worries—you can add an image to the chat history using the
ChatContext.add_message
method, which is great because it supports multimodal content like images. Here’s a little example to help you get started:
Copy code
from livekit.agents import llm

# Create image content from a URL
image_content = llm.ImageContent(
    image="https://example.com/image.jpg",
    inference_detail="auto"
)

# Create or use existing chat context
chat_ctx = llm.ChatContext()

# Add message with image
chat_ctx.add_message(
    role="system",
    content=[image_content]
)
Just make sure your image source is either a base64-encoded data URL, an external URL, or a
VideoFrame
object. If you have any questions or need a hand with anything else, feel free to reach out—I’m here to help! Sources: Pipeline nodes and hooks | LiveKit Docs | livekit-agents/livekit/agents/llm/_provider_format/aws.py | Vision | LiveKit Docs