Image analysis with memory example using CometAPI

Analyze an image with CometAPI and include SQLite session history in a follow-up request.

image_agent_with_memory.py
"""
Image analysis with memory example using CometAPI.
"""

from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.media import Image
from agno.models.cometapi import CometAPI

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

agent = Agent(
    model=CometAPI(id="gpt-5.6-luna"),  # gpt-5.6-luna has vision capabilities
    db=SqliteDb(db_file="tmp/cometapi_image_agent.db"),
    session_id="cometapi_image_session",
    markdown=True,
)

# First interaction with an image
agent.print_response(
    "Look at this image and remember what you see. Describe the character in detail.",
    images=[
        Image(
            url="https://httpbin.org/image/png"  # Reliable test image
        )
    ],
)

print("\n" + "=" * 50 + "\n")

# Follow-up question using memory
agent.print_response(
    "What was the main color of the character in the image I showed you earlier?"
)

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

if __name__ == "__main__":
    pass

The source saves a session but does not include earlier messages in the next request. Enable history before running to let the follow-up use the original image and answer.

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 sqlalchemy

Export environment variables

export COMETAPI_KEY="your_cometapi_key_here"

Include the previous image turn

Save the source as image_agent_with_memory.py and add add_history_to_context=True to Agent(...), alongside its existing db and session_id. The fixed session ID is for this local example; choose separate session IDs for separate conversations.

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/cometapi/image_agent_with_memory.py