Together Image Agent With Memory

Keep image context across turns with a current Together vision model and an in-memory database.

Together retired the source's meta-llama/Llama-Vision-Free serverless model. Select a current vision model from the Together serverless catalog before running. See Together vision inputs.

image_agent_with_memory.py
"""
Together Image Agent With Memory
================================

Cookbook example for `together/image_agent_with_memory.py`.
"""

from agno.agent import Agent
from agno.media import Image
from agno.models.together import Together

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

agent = Agent(
    model=Together(id="meta-llama/Llama-Vision-Free"),
    markdown=True,
    add_history_to_context=True,
    num_history_runs=3,
)

agent.print_response(
    "Tell me about this image",
    images=[
        Image(
            url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg"
        )
    ],
    stream=True,
)

agent.print_response("Tell me where I can get more images?")

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    pass

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno openai

Export environment variables

export TOGETHER_API_KEY="your_together_api_key_here"
export TOGETHER_VISION_MODEL_ID="your_current_together_vision_model_id_here"

Use the selected vision model

Add import os, then replace Together(id="meta-llama/Llama-Vision-Free") with Together(id=os.environ["TOGETHER_VISION_MODEL_ID"]) in the saved file.

Store the conversation history

Add from agno.db.in_memory import InMemoryDb to the imports and db=InMemoryDb() to Agent(...). Without a database, add_history_to_context=True alone does not retain the first image and answer for the follow-up. This database lasts only for this process; use a persistent database to retain the conversation across restarts.

Run the example

Save the code above as image_agent_with_memory.py, then run:

python image_agent_with_memory.py

Full source: cookbook/90_models/together/image_agent_with_memory.py