Spectron agent memory for the OpenAI Agents SDK
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spectron_openai_agents_sdk-0.1.1.tar.gz.
File metadata
- Download URL: spectron_openai_agents_sdk-0.1.1.tar.gz
- Upload date:
- Size: 20.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21acafa633b8db3ca29fbeb6eca9b07b2da53e054bd26adfc18e43c38117a5f7
|
|
| MD5 |
3c9581db72ab2c6758cc3b49d0a916b5
|
|
| BLAKE2b-256 |
83e95f438b8873503223e6977ead509d48e3ab6b5e3f73605d03d1eee483e6e4
|
Provenance
The following attestation bundles were made for spectron_openai_agents_sdk-0.1.1.tar.gz:
Publisher:
release.yml on surrealdb/spectron-openai-agents-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spectron_openai_agents_sdk-0.1.1.tar.gz -
Subject digest:
21acafa633b8db3ca29fbeb6eca9b07b2da53e054bd26adfc18e43c38117a5f7 - Sigstore transparency entry: 2184937646
- Sigstore integration time:
-
Permalink:
surrealdb/spectron-openai-agents-sdk@6b79ad32efdfd7b95f737cb6968d7008def081f9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/surrealdb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6b79ad32efdfd7b95f737cb6968d7008def081f9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file spectron_openai_agents_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: spectron_openai_agents_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3baa63db2d79c09a50e232a8646b640849a39a46c63a4fa04c2002ef604441c
|
|
| MD5 |
92bbb2dccca780b54e3c527ace774487
|
|
| BLAKE2b-256 |
37547fbb11fe8c8aad622029a66217b93c207b304616610f6b4e19eec69fd952
|
Provenance
The following attestation bundles were made for spectron_openai_agents_sdk-0.1.1-py3-none-any.whl:
Publisher:
release.yml on surrealdb/spectron-openai-agents-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spectron_openai_agents_sdk-0.1.1-py3-none-any.whl -
Subject digest:
f3baa63db2d79c09a50e232a8646b640849a39a46c63a4fa04c2002ef604441c - Sigstore transparency entry: 2184937744
- Sigstore integration time:
-
Permalink:
surrealdb/spectron-openai-agents-sdk@6b79ad32efdfd7b95f737cb6968d7008def081f9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/surrealdb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6b79ad32efdfd7b95f737cb6968d7008def081f9 -
Trigger Event:
push
-
Statement type: