Spectron for the OpenAI Agents SDK
Give agents built with the OpenAI Agents SDK a durable, shared memory backed by Spectron, SurrealDB's memory and knowledge layer.
Spectron stores facts, past turns, preferences, and knowledge as a graph with temporal awareness, and lets several agents read and write the same memory. This package wires that into the Agents SDK so an agent can remember across runs and recall what it needs before it answers.
How it works
There are two ways to use memory, and they compose:
- Function tools the agent calls itself. The agent decides when to
remember,recall,context,reflect, orforget. This is the pattern used by the mem0 and cognee integrations. - Automatic memory around a run.
run_with_memoryrecalls memory relevant to the input, injects it into the prompt, runs the agent, and stores the result. The agent needs no memory tools of its own.
Both talk to Spectron through a single SpectronClient, scoped by a MemoryScope
(agent_id, session_id, user_id).
Installation
pip install spectron-openai-agents-sdk
This pulls in the Spectron SDK (surrealdb), which the integration
uses to reach a deployment.
Set the connection and model credentials:
export OPENAI_API_KEY="your-openai-api-key"
export SPECTRON_ENDPOINT="https://your-spectron-endpoint"
export SPECTRON_CONTEXT="your-memory-context"
export SPECTRON_API_KEY="your-api-key" # optional for local, unsecured instances
Usage
Memory as function tools
from agents import Agent, Runner
from spectron_openai_agents_sdk import get_spectron_tools
agent = Agent(
name="assistant",
instructions=(
"You are a helpful assistant. Use recall to check memory before you "
"answer, and use remember to store anything worth keeping."
),
tools=get_spectron_tools(session_id="user-123"),
)
Runner.run_sync(agent, "My name is Ada and I work on databases.")
result = Runner.run_sync(agent, "What do you know about me?")
print(result.final_output)
get_spectron_tools builds the tools from SPECTRON_* environment variables by default. Pass a
client= to use an explicit SpectronClient, and include= to choose a subset of operations.
Automatic memory around a run
import asyncio
from agents import Agent
from spectron_openai_agents_sdk import MemoryScope, run_with_memory
agent = Agent(name="assistant", instructions="You are a helpful assistant.")
scope = MemoryScope(session_id="user-123")
async def main():
await run_with_memory(agent, "My name is Ada.", scope=scope)
result = await run_with_memory(agent, "What is my name?", scope=scope)
print(result.final_output)
asyncio.run(main())
Persisting output with hooks
To save an agent's output while running it yourself, attach SpectronMemoryHooks:
from agents import Runner
from spectron_openai_agents_sdk import SpectronClient, SpectronMemoryHooks, MemoryScope
client = SpectronClient.from_env()
hooks = SpectronMemoryHooks(client, MemoryScope(session_id="user-123"))
await Runner.run(agent, "Summarize our project decisions.", hooks=hooks)
Operations
| Operation | Purpose |
|---|---|
remember |
Store a fact, preference, or event. |
recall |
Search memory for content relevant to a query. |
context |
Assemble a single ranked context block for a query. |
reflect |
Synthesize stored memory into a higher-level summary. |
forget |
Remove matching memory. |
Multi-agent shared memory
Agents that share a MemoryScope read and write the same Spectron memory, so knowledge one agent
stores is available to another. See
examples/04_multi_agent_shared_memory.py.
Examples
Runnable scripts live in examples/:
01_quickstart.pystores a fact and recalls it with the memory tools.02_function_tools.pyexercises the full tool set.03_automatic_memory.pyusesrun_with_memorywith no memory tools on the agent.04_multi_agent_shared_memory.pyshares one memory across two agents.
Configuration notes
This integration targets the Spectron client in surrealdb 3.x, which exposes Spectron and
AsyncSpectron. The SDK is imported lazily, only when a client is built from settings or the
environment, and all SDK calls live in src/spectron_openai_agents_sdk/client.py. If a future SDK
release changes a method name or constructor argument, that file is the single place to adjust; the
tools, hooks, and examples do not change.
The five operations map onto SDK methods as remember, recall, context (the SDK's
query_context), reflect, and forget. Scope is applied per call: session_id maps to the SDK
session_id, user_id to on_behalf_of, and agent_id to scopes on writes and lens on reads.
License
Licensed under the Apache License 2.0.
Metadata
Release files for spectron-openai-agents-sdk 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| spectron_openai_agents_sdk-0.1.1.tar.gz | 20.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spectron_openai_agents_sdk-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 39.2 kB
Release files / spectron_openai_agents_sdk-0.1.1.tar.gz
| Download URL | spectron_openai_agents_sdk-0.1.1.tar.gz |
|---|---|
| Size | 20.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
21acafa633b8db3ca29fbeb6eca9b07b2da53e054bd26adfc18e43c38117a5f7
|
|
BLAKE2b-256 checksum How to use checksums |
83e95f438b8873503223e6977ead509d48e3ab6b5e3f73605d03d1eee483e6e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 16, 2026.
Transparency logRelease files / spectron_openai_agents_sdk-0.1.1-py3-none-any.whl
| Download URL | spectron_openai_agents_sdk-0.1.1-py3-none-any.whl |
|---|---|
| Size | 18.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f3baa63db2d79c09a50e232a8646b640849a39a46c63a4fa04c2002ef604441c
|
|
BLAKE2b-256 checksum How to use checksums |
37547fbb11fe8c8aad622029a66217b93c207b304616610f6b4e19eec69fd952
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 16, 2026.
Transparency log