Agent frameworks

AutoGen

Adding Spectron memory to Microsoft AutoGen agents with the Spectron SDK.

AutoGen builds conversational and multi-agent systems in Python. Spectron 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.

Note

This is an integration guide. It wires the Spectron SDK into AutoGen's tool interface; adapt the function-registration calls to your installed AutoGen version.

pip install autogen-agentchat autogen-ext[openai] surrealdb
export SPECTRON_ENDPOINT="https://api.spectron.example"
export SPECTRON_CONTEXT="acme-prod"
export SPECTRON_API_KEY="sk-spec-..."

Wrap the Spectron 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 import Spectron

memory = Spectron(
    endpoint=os.environ["SPECTRON_ENDPOINT"],
    context=os.environ["SPECTRON_CONTEXT"],
    api_key=os.environ["SPECTRON_API_KEY"],
)
scope = ["org/acme/user/alice"]

def remember(text: str) -> str:
    """Store a durable fact for later recall."""
    memory.remember(text, scope=scope)
    return "stored"

def recall(query: str) -> str:
    """Retrieve relevant memory for a query."""
    return memory.query_context(query, k=8, scope=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.",
)

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, scope=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}],
    scope=scope,
)

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 spectron scopes create before first use.

Was this page helpful?