straight-judge-10526
12/16/2025, 5:42 AMtall-airline-16756
12/16/2025, 5:42 AMtall-airline-16756
12/16/2025, 5:42 AMChatContext using an ImageContent object (accepts base64 data URL, external URL, or a video frame).
2. Include that ImageContent in a chat message during test setup (either at initialization or uploaded dynamically from the frontend).
3. Use a vision-capable LLM plugin (for example OpenAI or Gemini) so the agent can interpret the image and produce multimodal responses.
4. Write behavioral tests that include image-containing messages to validate the agent's understanding and responses.
If you'd like, tell me which LLM/plugin you're using and whether you want an example in code (initialization vs. dynamic upload), and I’ll provide the specific snippet.
Sources: Vision | LiveKit Docs | Testing and evaluation | LiveKit docsstraight-judge-10526
12/16/2025, 5:43 AMtall-airline-16756
12/16/2025, 5:44 AMChatContext with an ImageContent at initialization, and one that shows uploading/sending image data dynamically. Replace placeholders (API keys, agent IDs, image URLs/base64) with your values.
1) Initialization — include an external image URL or base64 in `ImageContent`:
// Node.js / JavaScript example (pseudo-API shape)
import { AgentsClient, ChatContext, ChatMessage, ImageContent } from 'livekit-agents-sdk';
const client = new AgentsClient({ apiKey: 'YOUR_API_KEY' });
async function testWithImageInit() {
const image = new ImageContent({
// Use either a remote URL:
url: '<https://example.com/test-image.jpg>',
// Or a base64 data URL:
// dataUrl: 'data:image/png;base64,iVBORw0K...'
mimeType: 'image/jpeg',
});
const ctx = new ChatContext({
messages: [
new ChatMessage({
role: 'user',
content: [
{ type: 'text', text: "What's in this image?" },
image,
],
}),
],
});
const resp = await client.runAgent({
agentId: 'YOUR_AGENT_ID',
context: ctx,
// optional: specify model/plugin that supports vision
model: 'openai-vision-model',
});
console.log('Agent response:', resp);
}
testWithImageInit().catch(console.error);
2) Dynamic upload — send image bytes from a frontend or buffer during a session:
// Node.js / JavaScript example (pseudo-API shape)
import fs from 'fs';
import { AgentsClient, ChatContext, ChatMessage, ImageContent } from 'livekit-agents-sdk';
const client = new AgentsClient({ apiKey: 'YOUR_API_KEY' });
async function testWithImageUpload() {
// Read image bytes and convert to data URL
const buffer = fs.readFileSync('./local-image.png');
const b64 = buffer.toString('base64');
const dataUrl = `data:image/png;base64,${b64}`;
const image = new ImageContent({
dataUrl,
mimeType: 'image/png',
});
const ctx = new ChatContext({
messages: [
new ChatMessage({
role: 'user',
content: [
{ type: 'text', text: "Please describe this image." },
image,
],
}),
],
});
const resp = await client.runAgent({
agentId: 'YOUR_AGENT_ID',
context: ctx,
model: 'openai-vision-model',
});
console.log('Agent response:', resp);
}
testWithImageUpload().catch(console.error);
Notes:
• Ensure the agent is configured with a vision-capable LLM/plugin (e.g., OpenAI/Gemini vision) so it can interpret image content.
• Use mimeType that matches the image format.
• For large images prefer remote URLs or streaming rather than embedding huge base64 strings.
Want the same examples in Python or a frontend (browser) flavor? Which model/plugin are you testing with?straight-judge-10526
12/16/2025, 5:44 AMtall-airline-16756
12/16/2025, 5:44 AM# Python (pseudo-API shape)
from livekit_agents import AgentsClient, ChatContext, ChatMessage, ImageContent
client = AgentsClient(api_key="YOUR_API_KEY")
def test_with_image_init():
image = ImageContent(
url="<https://example.com/test-image.jpg>",
mime_type="image/jpeg",
)
msg = ChatMessage(
role="user",
content=[
{"type": "text", "text": "What's in this image?"},
image,
],
)
ctx = ChatContext(messages=[msg])
resp = client.run_agent(
agent_id="YOUR_AGENT_ID",
context=ctx,
model="openai-vision-model", # use a vision-capable model/plugin
)
print("Agent response:", resp)
if __name__ == "__main__":
test_with_image_init()
2) Dynamic upload — embed a local image as a base64 data URL:
# Python (pseudo-API shape)
import base64
from livekit_agents import AgentsClient, ChatContext, ChatMessage, ImageContent
client = AgentsClient(api_key="YOUR_API_KEY")
def test_with_image_upload():
with open("local-image.png", "rb") as f:
b64 = base64.b64encode(f.read()).decode("utf-8")
data_url = f"data:image/png;base64,{b64}"
image = ImageContent(
data_url=data_url,
mime_type="image/png",
)
msg = ChatMessage(
role="user",
content=[
{"type": "text", "text": "Please describe this image."},
image,
],
)
ctx = ChatContext(messages=[msg])
resp = client.run_agent(
agent_id="YOUR_AGENT_ID",
context=ctx,
model="openai-vision-model",
)
print("Agent response:", resp)
if __name__ == "__main__":
test_with_image_upload()
Notes:
• Ensure your agent uses a vision-capable LLM/plugin (e.g., OpenAI/Gemini vision).
• Use the correct mime_type and reasonable image sizes (remote URLs or streaming are preferable for large files).
Would you like this adapted for a specific SDK version or a real example using a particular model/plugin?straight-judge-10526
12/16/2025, 5:45 AMimport pytest
from livekit.agents import AgentSession
from livekit.plugins import openai
from dapagent import Assistant
@pytest.mark.asyncio
async def test_assistant_response() -> None:
"""
Test that the agent responds helpfully to a user greeting.
"""
async with (
openai.LLM(model="gpt-4o-mini") as llm,
AgentSession(llm=llm) as session,
):
await session.start(Assistant())
result = await session.run(user_input="Hello")
await result.expect.next_event().is_message(role="assistant").judge(
llm, intent="Makes a friendly introduction and offers assistance."
)tall-airline-16756
12/16/2025, 5:45 AMImageContent to the chat message so the agent can be tested for multimodal responses. Replace placeholders (agent class, model, image path/URL, and assertion intent) with your values.
import base64
import pytest
from livekit.agents import AgentSession, ChatMessage, ImageContent, ChatContext
from livekit.plugins import openai
from dapagent import Assistant # your agent implementation
@pytest.mark.asyncio
async def test_assistant_handles_image() -> None:
"""
Test that the agent can process an image included in the chat context
and respond appropriately.
"""
# Prepare image as data URL (alternatively use external URL in ImageContent)
with open("tests/fixtures/test-image.png", "rb") as f:
b64 = base64.b64encode(f.read()).decode("utf-8")
data_url = f"data:image/png;base64,{b64}"
image_content = ImageContent(
data_url=data_url,
mime_type="image/png",
)
user_msg = ChatMessage(
role="user",
content=[
{"type": "text", "text": "Please describe what's shown in this image."},
image_content,
],
)
ctx = ChatContext(messages=[user_msg])
async with (
openai.LLM(model="gpt-4o-mini") as llm,
AgentSession(llm=llm, context=ctx) as session,
):
await session.start(Assistant())
result = await session.run(user_input=None) # context already contains the user message
# Expect the next event to be an assistant message that demonstrates understanding of image
await result.expect.next_event().is_message(role="assistant").judge(
llm, intent="Describes the contents of the provided image and offers assistance."
)
If you prefer using an external image URL instead of embedding base64, replace the ImageContent creation with:
image_content = ImageContent(url="<https://example.com/test-image.jpg>", mime_type="image/jpeg")
Want this adapted for a different model/plugin or to test multiple image cases?