Image Agent With Memory

Code

1from kern.agent import Agent
2from kern.media import Image
3from kern.models.openai import OpenAIResponses
4from kern.tools.hackernews import HackerNewsTools
5
6agent = Agent(
7 model=OpenAIResponses(id="gpt-5-mini"),
8 tools=[HackerNewsTools()],
9 markdown=True,
10 add_history_to_context=True,
11 num_history_runs=3,
12)
13
14agent.print_response(
15 "Tell me about this image and give me the latest news about it.",
16 images=[
17 Image(
18 url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg"
19 )
20 ],
21)
22
23agent.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 OPENAI_API_KEY=xxx

Install dependencies

1uv pip install -U openai kern-ai

Run Agent

1python cookbook/11_models/openai/responses/image_agent_with_memory.py