Usage

In-Memory Storage for Agents

Store agent sessions and run history in the current Python process with InMemoryDb.

InMemoryDb stores an Agent's sessions and run history in the current Python process. Data is lost when the process exits.

Usage

Start in a virtual environment and set the model key before running the example.

Set OpenAI Key

Set your OPENAI_API_KEY as an environment variable. You can get one from OpenAI.

export OPENAI_API_KEY=sk-***

Install dependencies:

uv pip install agno openai
from agno.agent import Agent
from agno.db.in_memory import InMemoryDb

db = InMemoryDb()

agent = Agent(db=db, add_history_to_context=True)

agent.print_response("Give me an easy dinner recipe")
agent.print_response("Which ingredients did you just recommend?")

Run the Example

Save the code as in_memory_for_agent.py, complete the prerequisites above, then run:

python in_memory_for_agent.py