Image Agent with Memory
Give a Together vision agent conversation history to answer follow-up questions about a prior image.
Code
import os
from agno.agent import Agent
from agno.db.in_memory import InMemoryDb
from agno.media import Image
from agno.models.together import Together
agent = Agent(
model=Together(id=os.environ["TOGETHER_MODEL_ID"]),
db=InMemoryDb(),
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?")Set TOGETHER_MODEL_ID to a current model that accepts image input. See the Together vision guide and serverless catalog.
InMemoryDb retains these runs for the lifetime of this process. Both calls use the same agent session, so the second call includes the earlier image and response. Use a persistent database to retain sessions across restarts.
Usage
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateSet your API key
export TOGETHER_API_KEY=xxx
export TOGETHER_MODEL_ID=your-model-idInstall dependencies
uv pip install -U openai agnoRun Agent
Save the code above as image_agent_with_memory.py, then run:
python image_agent_with_memory.py