AutoGen builds conversational and multi-agent systems in Python. SurrealDB Agent Memory gives those agents long-term memory: recall relevant facts before a turn and store new ones after. There is no dedicated adapter. The Python SDK (surrealdb) exposes the memory operations you register as agent tools.
This is an integration guide. It wires the SurrealDB Agent Memory SDK into AutoGen's tool interface; adapt the function-registration calls to your installed AutoGen version.
Installation
pip install autogen-agentchat 'autogen-ext[openai]'
pip install --pre 'surrealdb[memory]'export AGENT_MEMORY_ENDPOINT="https://api.spectron.example"
export AGENT_MEMORY_CONTEXT="acme-prod"
export AGENT_MEMORY_API_KEY="sk-spec-..."Memory as agent tools
Wrap the SurrealDB Agent Memory client in plain functions and pass them to the agent. AutoGen calls them like any other tool:
import os
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
from surrealdb.memory import Memory
memory = Memory(
endpoint=os.environ["AGENT_MEMORY_ENDPOINT"],
context=os.environ["AGENT_MEMORY_CONTEXT"],
api_key=os.environ["AGENT_MEMORY_API_KEY"],
)
scope = ["org/acme/user/alice"]
def remember(text: str) -> str:
"""Store a durable fact for later recall."""
memory.remember(text, scopes=scope)
return "stored"
def recall(query: str) -> str:
"""Retrieve relevant memory for a query."""
return memory.query_context(query, k=8, lens=scope)
agent = AssistantAgent(
name="assistant",
model_client=OpenAIChatCompletionClient(model="gpt-4o"),
tools=[remember, recall],
system_message="Use recall before answering and remember anything worth keeping.",
)Recall around a run
To keep memory out of the agent's tool list, recall before the run and inject the context into the system message, then store the exchange yourself:
block = memory.query_context(user_message, k=8, lens=scope)
agent = AssistantAgent(
name="assistant",
model_client=OpenAIChatCompletionClient(model="gpt-4o"),
system_message=f"You are a helpful assistant.\n\n## Memory\n{block}",
)
# after the run
memory.remember_many(
[{"role": "user", "content": user_message}, {"role": "assistant", "content": reply}],
scopes=scope,
)Scope per user
Pass a scope on every call to isolate memory. A scope is a slash path or an array of paths, for example ["org/acme/user/alice"]. Register paths with agent-memory scopes create before first use.
Next steps
Python SDK: the full client surface
MCP server: if your host speaks MCP instead