Examples
Agent patterns
Tool using loops, isolated memory per agent and coding assistants.
The memory integration is always the same one call. These are the common shapes it takes in real agents: a tool-using loop, isolated memory per agent, and a coding assistant that remembers across sessions.
Tool-using agent (hosted API)
Recall feeds the plan; the final answer and what was learned get stored. Your tool calls and planning are unchanged.
Python
import os, requests
API = "https://api.mentedb.com/v1/process_turn"
HEADERS = {"Authorization": f"Bearer {os.environ['MENTEDB_API_KEY']}"}
def run_agent(user_message, turn_id, history):
memories = "\n".join(m["content"] for m in history)
# your agent: plan, call tools, produce a final answer with memory in context
reply = agent_step(system=f"What you remember:\n{memories}", user=user_message)
result = requests.post(API, headers=HEADERS, json={
"user_message": user_message,
"assistant_response": reply,
"turn_id": turn_id,
}).json()
return reply, result["context"] # context feeds the next turnMulti-agent, isolated memory (agent_id)
Pass an agent_id (a stable UUID per agent) and recall is scoped to that agent, so a planner and a coder keep separate memory. Share a lane by giving them the same project_context instead.
Python
PLANNER = "3f2a2c10-0000-4000-8000-000000000001" # stable UUID per agent
CODER = "9b7c5d20-0000-4000-8000-000000000002"
def turn(agent_id, user_message, turn_id):
return requests.post(API, headers=HEADERS, json={
"user_message": user_message,
"assistant_response": "",
"turn_id": turn_id,
"agent_id": agent_id, # recall is scoped to this agent
}).json()["context"]
planner_ctx = turn(PLANNER, "Break the migration into steps", 0)
coder_ctx = turn(CODER, "Implement step 1", 0) # does not see planner's private memoryCoding assistant (self-hosted)
Embed the engine so memory stays on the developer's disk. One call recalls prior decisions and preferences, including from past sessions, before the model answers.
Python
from mentedb import MenteDB
db = MenteDB("./coding-assistant-memory") # stays on the dev's disk
def assist(user_message, turn_id):
# One call: store the message + recall prior decisions (including past sessions).
result = db.process_turn(user_message=user_message, turn_id=turn_id)
context = "\n".join(m.content for m in result.context)
return call_your_llm(
system=f"Prior decisions & preferences:\n{context}",
user=user_message,
)