enough-match-43171
12/07/2025, 9:15 PMtall-airline-16756
12/07/2025, 9:15 PMtall-airline-16756
12/07/2025, 9:16 PMImageContent message to the chat context.
To do this:
1. Create or copy the current ChatContext.
2. Use chat_ctx.add_message() with role "assistant" and include an ImageContent object whose image is a data URL (e.g., data:image/png;base64,...) or an external image URL.
3. Update the agent with the modified chat context so the image appears in the conversation.
Example (Python):
from livekit.agents.llm import ImageContent, ChatContext
chat_ctx = self.chat_ctx.copy()
chat_ctx.add_message(
role="assistant",
content=[
"Here is an image:",
ImageContent(image=f"data:image/png;base64,{base64_encoded_image}")
]
)
await self.update_chat_ctx(chat_ctx)
Would you like an example for returning an externally hosted image URL instead of a base64 data URL?
Sources: Vision | LiveKit Docsenough-match-43171
12/07/2025, 9:20 PMtall-airline-16756
12/07/2025, 9:20 PMFunctionCallOutput (stringified if needed) and is automatically appended to the chat context. The LLM receives that output and can use it for its next reply or to trigger further tool calls.
If a tool returns None or nothing, it completes silently and no FunctionCallOutput is added. Would you like an example of how a dictionary or image-returning tool appears in the chat context?
Sources: Tool definition and use | LiveKit docsenough-match-43171
12/07/2025, 9:21 PMtall-airline-16756
12/07/2025, 9:21 PMreturn {"weather": "sunny", "temperature_f": 70}
• The agent runtime converts that return to a FunctionCallOutput (stringified) and appends it to the chat history, e.g.:
Assistant (tool output): "{'weather': 'sunny', 'temperature_f': 70}" The LLM then sees that output and can generate a follow-up reply referencing those values.
2) Tool returns image content visible to the user
• Return value can be any string/structure, but to show an actual image in the conversation you must add an ImageContent message to the chat context:
from livekit.agents.llm import ImageContent, ChatContext
# inside the tool/agent code after producing the image bytes/base64
base64_image = "<base64_encoded_png>"
chat_ctx = self.chat_ctx.copy()
chat_ctx.add_message(
role="assistant",
content=[
"Here is the generated image:",
ImageContent(image=f"data:image/png;base64,{base64_image}")
]
)
await self.update_chat_ctx(chat_ctx)
# You can still return structured data if you want:
return {"image_id": "img_123", "note": "image added to chat context"}
• Result in chat:
Assistant (tool output): "{'image_id': 'img_123', 'note': 'image added to chat context'}" Assistant (message with image): [renders the image from ImageContent]
Notes:
• The tool return is always added to the chat as a FunctionCallOutput (stringified) unless it returns None.
• To display an image to the user, explicitly add an ImageContent message to the chat context (data URL or external URL).
Would you like a variant that uses an external image URL instead of base64?