Image Agent with Memory

Code

1from kern.agent import Agent
2from kern.media import Image
3from kern.models.together import Together
4
5agent = Agent(
6 model=Together(id="meta-llama/Llama-Vision-Free"),
7 markdown=True,
8 add_history_to_context=True,
9 num_history_runs=3,
10)
11
12agent.print_response(
13 "Tell me about this image",
14 images=[
15 Image(
16 url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg"
17 )
18 ],
19 stream=True,
20)
21
22agent.print_response("Tell me where I can get more images?")

Usage

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Set your API key

1export TOGETHER_API_KEY=xxx

Install dependencies

1uv pip install -U openai kern-ai

Run Agent

1python cookbook/11_models/together/image_agent_memory.py