Vision Agent
Specialized agent for image analysis, description, comparison, and text extraction using AI vision models.
Analyse, describe, compare, and read text from images with the VisionAgent and its dedicated methods.
from praisonaiagents import VisionAgent
agent = VisionAgent()
result = agent.analyze("https://example.com/image.jpg")
print(result)How It Works
Quick Start
- Install
bash pip install praisonaiagents litellm export OPENAI_API_KEY="your-key" - Create Agent
python from praisonaiagents import VisionAgent agent = VisionAgent() - Analyze Image
python result = agent.analyze("https://example.com/image.jpg") print(result)
Methods
analyze()
Analyze an image with optional custom prompt.
from praisonaiagents import VisionAgent
agent = VisionAgent()
# Basic analysis
result = agent.analyze("image.jpg")
# With custom prompt
result = agent.analyze(
"chart.png",
prompt="What data does this chart show?"
)strImage URL or local file path
strCustom analysis prompt
strDetail level: low, high, or auto
describe()
Generate detailed description of an image.
description = agent.describe("photo.jpg")
print(description)Returns comprehensive description including: – Main subject and composition – Colors, lighting, mood – Background and setting – Text, symbols, notable details
compare()
Compare multiple images.
comparison = agent.compare([
"before.jpg",
"after.jpg"
], prompt="What changed?")List[str]List of image URLs or paths (minimum 2)
extract_text()
Extract text from images (OCR-like).
text = agent.extract_text("document.png", detail="high")
print(text)Configuration
Basic
from praisonaiagents import VisionAgent
agent = VisionAgent(
name="MyVision",
llm="gpt-4o",
verbose=True
)With Config
from praisonaiagents import VisionAgent, VisionConfig
config = VisionConfig(
detail="high",
max_tokens=8192,
timeout=120
)
agent = VisionAgent(vision=config)Dict Config
agent = VisionAgent(
vision={
"detail": "high",
"max_tokens": 4096
}
)VisionConfig Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
detail | str | "auto" | Detail level: low, high, auto |
max_tokens | int | 4096 | Maximum response tokens |
timeout | int | 60 | Request timeout in seconds |
Supported Models
gpt-4o(default)gpt-4o-minigpt-4-turbo
claude-3-5-sonnet-20241022claude-3-opus-20240229
gemini/gemini-1.5-progemini/gemini-1.5-flash
Examples
Analyze Chart Data
from praisonaiagents import VisionAgent
agent = VisionAgent(llm="gpt-4o")
result = agent.analyze(
"https://example.com/sales-chart.png",
prompt="Extract all data points and trends from this chart"
)
print(result)Compare Product Images
agent = VisionAgent()
comparison = agent.compare([
"product_v1.jpg",
"product_v2.jpg",
"product_v3.jpg"
], prompt="Describe the design evolution across these versions")Extract Document Text
agent = VisionAgent()
# High detail for better OCR
text = agent.extract_text(
"scanned_document.png",
detail="high"
)
print(text)Async Usage
import asyncio
from praisonaiagents import VisionAgent
async def main():
agent = VisionAgent()
result = await agent.aanalyze("image.jpg")
print(result)
asyncio.run(main())Comparison with ImageAgent
| Feature | VisionAgent | ImageAgent |
|---|---|---|
| Purpose | Analyze images | Generate images |
| Input | Image URL/path | Text prompt |
| Output | Text description | Image file/URL |
| Models | GPT-4o, Claude, Gemini | DALL-E, Stable Diffusion |
Best Practices
Pick the method that matches the task
Use analyze for open-ended questions, describe for captions, compare for two images, and text extraction for OCR. The dedicated methods prompt the model more precisely than a raw call.
Use a vision-capable model
VisionAgent needs a multimodal model (GPT-4o, Claude, Gemini). Point it at a text-only model and it cannot see the image.
Give a specific prompt for analysis
analyze(image, prompt="Count the people") beats a bare analyze(image). A focused question yields a focused, useful answer.
Reach for ImageAgent to generate, not analyse
VisionAgent understands existing images. To create new images from a text prompt, use the ImageAgent instead.