Loading...
Loading...
Send images, audio, video, or documents into an AG2 `Agent` alongside text. Pass `ImageInput`, `AudioInput`, `VideoInput`, or `DocumentInput` as positional args to `agent.ask(...)`. Use when the user wants the agent to process non-text input — describe a photo, transcribe audio, summarise a PDF, analyse a video. Covers per-provider support matrix, the four ways to source data (URL / path / bytes / file_id), Gemini-specific YouTube + media-resolution + clipping, OpenAI image-detail, Anthropic prompt-caching on attachments, and `FilesAPI` for upload lifecycle.
npx skill4agent add ag2ai/ag2-skills ag2-multimodal-inputfrom ag2 import Agent
from ag2.config import GeminiConfig
from ag2.events import ImageInput
agent = Agent(
"vision",
"You describe images.",
config=GeminiConfig(model="gemini-3-flash-preview"),
)
image = ImageInput("https://example.com/photo.jpg")
reply = await agent.ask("Describe this image in detail.", image)
print(reply.body)reply = await agent.ask(
"Compare these two images.",
ImageInput("https://example.com/before.jpg"),
ImageInput("https://example.com/after.jpg"),
)| Factory | Formats |
|---|---|
| JPEG, PNG, GIF, WebP |
| WAV, MP3, OGG, FLAC, AAC |
| MP4, WebM, MOV, MKV, MPEG |
| PDF, TXT, HTML, Markdown, CSV, JSON, Office formats |
from ag2.events import ImageInput
ImageInput("https://example.com/photo.jpg") # URL
ImageInput(path="photo.jpg") # local file
ImageInput(data=raw_bytes, media_type="image/png") # bytes
ImageInput(file_id="file-abc123") # provider-uploaded| Input type | OpenAI | OpenAI Responses | Gemini | Anthropic |
|---|---|---|---|---|
| Text | ✓ | ✓ | ✓ | ✓ |
| Image (URL) | ✓ | ✓ | ✓ | ✓ |
| Image (binary) | ✓ | ✓ | ✓ | ✓ |
| Audio (URL) | – | – | ✓ | – |
| Audio (binary) | ✓ | – | ✓ | – |
| Video (URL) | – | – | ✓ | – |
| Video (binary) | – | – | ✓ | – |
| Document (URL) | – | ✓ | ✓ | ✓ |
| Document (binary) | ✓ | ✓ | ✓ | ✓ |
| File ID | ✓ | ✓ | ✓ | ✓ |
UnsupportedInputErrorfrom ag2.events import VideoInput
video = VideoInput("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
reply = await agent.ask("Summarize this video.", video)from google import genai
from ag2.events import VideoInput
import time
client = genai.Client()
uploaded = client.files.upload(file="large_video.mp4")
while uploaded.state.name == "PROCESSING":
time.sleep(2)
uploaded = client.files.get(name=uploaded.name)
video = VideoInput(uploaded.uri)vendor_metadata| Key | Purpose |
|---|---|
| |
| Clipping ( |
| Display name for the file |
ImageInput(data=raw, media_type="image/jpeg", vendor_metadata={"media_resolution": "MEDIA_RESOLUTION_LOW"})
VideoInput(path="lecture.mp4", vendor_metadata={
"video_metadata": {"start_offset": "60s", "end_offset": "120s", "fps": 0.5},
})ImageInput(data=raw, media_type="image/png", vendor_metadata={"detail": "low"}) # "low" | "high" | "auto"import anthropic
from ag2.events import ImageInput, DocumentInput
client = anthropic.Anthropic()
uploaded = client.beta.files.upload(file=("photo.jpg", open("photo.jpg", "rb"), "image/jpeg"))
# filename determines block type (image vs document)
image = ImageInput(file_id=uploaded.id, filename="photo.jpg")
# Cache an attachment so subsequent turns skip re-uploading
doc = DocumentInput(path="report.pdf", vendor_metadata={"cache_control": {"type": "ephemeral"}})FilesAPIOpenAIConfigOpenAIResponsesConfigAnthropicConfigGeminiConfigfrom ag2 import FilesAPI
from ag2.config import OpenAIResponsesConfig
files = FilesAPI(OpenAIResponsesConfig(model="gpt-5-mini"))
uploaded = await files.upload(path="report.pdf", purpose="assistants")
print(uploaded.file_id)
# Or from bytes (filename required)
uploaded = await files.upload(data=b"...", filename="hello.txt", purpose="assistants")
# List, read, delete
all_files = await files.list()
data = await files.read(uploaded.file_id) # NotImplementedError on Gemini
await files.delete(uploaded.file_id)file_idDocumentInputImageInputfrom ag2.events import DocumentInput
doc = DocumentInput(file_id=uploaded.file_id)
reply = await agent.ask("Summarize this report.", doc)website/docs/user-guide/multimodal/inputs.mdxvendor_metadatawebsite/docs/user-guide/advanced/files.mdxFilesAPIag2-add-custom-toolImageInputBinaryInputToolResultUnsupportedInputErrorFilesAPI.read()NotImplementedErrorfiles.upload(data=...)filename=ValueErrorurlfile_idpathdataValueErrorImageInput(file_id=...)filename=vendor_metadatavideo_metadataPROCESSINGclient.files.get(name=...)