The MentisDB Agent Memory Cookbook

Patterns and recipes for building AI agents that remember

5.3 Python: Custom Agent with pymentisdb

A direct Python client is the right fit when you are not using LangChain or when you want exact control over thought types and metadata.

from pymentisdb import MentisDbClient

client = MentisDbClient("http://127.0.0.1:9472", chain_key="research-agent")

context = client.ranked_search("prior work on websocket retries", limit=5)

client.append(
    agent_id="research-agent",
    thought_type="LessonLearned",
    role="Retrospective",
    content="Retry storms stopped after adding jitter to websocket reconnects.",
    concepts=["websocket", "retries", "jitter"],
    tags=["incident", "lesson"],
    importance=0.85,
)

The important rule is the same in every language: search first, then append only durable information.