Memory with MongoDB
Code
1from kern.agent import Agent2from kern.db.mongo import MongoDb34# Setup MongoDb5db_url = "mongodb://localhost:27017"67db = MongoDb(db_url=db_url)89agent = Agent(10 db=db,11 update_memory_on_run=True,12)1314agent.print_response("My name is John Doe and I like to play basketball on the weekends.")15agent.print_response("What's do I do in weekends?")Usage
Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateSet environment variables
1export OPENAI_API_KEY=xxxInstall dependencies
1uv pip install -U kern-ai openai pymongoRun Example
1python mem-mongodb-memory.py1python mem-mongodb-memory.py