Skip to main content
Tasks can include image attachments for processing. The framework automatically handles image loading and provides them to the model for analysis.

Single Image Attachment

from upsonic import Agent, Task

agent = Agent(model="openai/gpt-4o")

# Task with single image
task = Task(
    description="Describe what you see in the attached image",
    context=["image.png"]
)

result = agent.do(task)
print(result)

Multiple Image Attachments

from upsonic import Agent, Task

agent = Agent(model="openai/gpt-4o")

# Task with multiple images
task = Task(
    description="Compare the two attached images and identify similarities and differences",
    context=["image1.jpg", "image2.jpg"]
)

result = agent.do(task)
print(result)

Images with Other Context

from upsonic import Agent, Task

agent = Agent(model="openai/gpt-4o")

# Task with images and other context
task = Task(
    description="Analyze the attached chart and provide insights based on the market data",
    context=["chart.png", market_data_task],
)

result = agent.do(task)
print(result)

Supported Image Formats

The framework supports various image formats including:
  • PNG (.png)
  • JPEG (.jpg, .jpeg)
  • GIF (.gif)
  • BMP (.bmp)
  • TIFF (.tiff)
from upsonic import Agent, Task

agent = Agent(model="openai/gpt-4o")

# Example with different image formats
task = Task(
    description="Analyze all the attached images",
    context=["photo.jpg", "diagram.png", "chart.tiff"]
)

result = agent.do(task)
print(result)

Image Processing with Tools

from upsonic import Agent, Task
from upsonic.tools import tool

@tool
def image_analyzer(image_path: str) -> str:
    """Analyze image content and return description."""
    # Your image analysis logic here
    return f"Analysis of {image_path}"

agent = Agent(model="openai/gpt-4o")

# Task combining image attachments with image analysis tools
task = Task(
    description="Analyze the attached images using the image analyzer tool",
    context=["image1.jpg", "image2.png"],
    tools=[image_analyzer]
)

result = agent.do(task)
print(result)

Best Practices

  • File Paths: Use absolute or relative paths that are accessible to your application
  • Image Size: Consider image file sizes for performance optimization
  • Format Selection: Choose appropriate formats based on your analysis needs
  • Error Handling: Handle cases where image files might not be accessible
  • Context Integration: Combine images with relevant text context for better analysis
  • Tool Integration: Use specialized image analysis tools when available