openai-agents-memorysync
Long-term memory for the OpenAI Agents SDK, backed by MemorySync — including the first drop-in implementation of the SDK's Session protocol from any memory vendor.
MemorySyncSession— durable server-side conversation history forRunner.run(..., session=...): survives restarts and deploys, follows multi-agent handoffs, and sends user messages to fact extraction so durable facts become long-term memories.memory_instructions— dynamic instructions that inject recalled memory context per run.- Five agent tools — add, search, list, update, delete; they never raise.
- Async helpers —
get_memory_context,search_memories,save_turn.
pip install openai-agents-memorysync openai-agents
Set MEMORYSYNC_API_KEY in the environment (create a key at app.memorysync.io), or pass api_key explicitly. Python 3.10+. The package never imports the Agents SDK at runtime — the Session contract is a structural protocol — so it never constrains which SDK version you run.
The drop-in session
from agents import Agent, Runner
from openai_agents_memorysync import MemorySyncSession
agent = Agent(name="Assistant", instructions="You are a helpful assistant.")
session = MemorySyncSession(
"thread-42", # the conversation
user_id="customer-7", # the end user it belongs to — required
)
# First conversation
await Runner.run(agent, "I'm vegetarian and I fly aisle.", session=session)
# Any later run — same session id, any process, any deploy
result = await Runner.run(agent, "Book my trip.", session=session)
# The model saw the full prior history — no manual .to_input_list() plumbing.
Session items live in MemorySync conversation history, one turn per item, and get_items() returns them exactly as the SDK wrote them — assistant messages, function calls, tool outputs, reasoning items — verified in the test suite against OpenAI's own SQLiteSession, item for item. Conversation history is not memory: it never shows up in memory search, recall or the memory list. Each session is stored under its own server-side owner: clear_session() can only ever reach that one conversation, and function-call JSON never reaches the user's long-term memories.
Long-term memory: with long_term=True (the default), the text of each user message is also sent to fact extraction, so durable facts ("I'm vegetarian") become memories for user_id that every MemorySync surface can recall. Assistant replies are not stored as memories. Pass long_term=False to keep a session out of long-term memory.
Multi-agent handoffs: the SDK shares one session across every agent in a run, so with a correct Session implementation, cross-handoff memory needs no extra code.
Failure discipline: the transcript IS the conversation state, so session-plane errors raise (a silently empty history would corrupt every following turn); the auxiliary long-term plane degrades through on_error. pop_item/clear_session refuse loudly when the key cannot delete. Transcript writes converge under retries — total and partial batch failures alike — via position + content-hash idempotency keys.
Long-term memory in instructions
from openai_agents_memorysync import memory_instructions
agent = Agent(
name="Assistant",
instructions=memory_instructions(
"You are a helpful assistant.",
user_id="customer-7", # or a per-run resolver:
# user_id=lambda ctx: ctx.context.user_id,
),
)
Every run starts with what MemorySync knows about the user. Recall failure degrades to the base instructions — reported through on_error, never thrown. Modes: "profile" (default — an overview of the user: the newest facts, listed, no query needed), "query" (semantic recall for the text your prompt resolver returns), "full" (both). 1.0.3 note: profile mode is a listing; 1.0.1 searched with a generic overview prompt, which production answered with nothing for ordinary users, so the default injected no memory.
Agent tools
from openai_agents_memorysync import create_memory_tools
agent = Agent(
name="Assistant",
instructions="Use the memory tools to remember durable facts.",
tools=create_memory_tools(user_id="customer-7"),
)
# Untrusted agents: search + list only.
create_memory_tools(user_id="customer-7", read_only=True)
add_memory, search_memory, list_memories, update_memory, delete_memory — the same five operations, same response strings as the MemorySync LangChain, AI SDK, CrewAI and Mastra tool sets. All async; failures return short readable strings, never exceptions.
Helpers
from openai_agents_memorysync import get_memory_context, save_turn, search_memories
context = await get_memory_context("what should I cook?", user_id="customer-7")
hits = await search_memories("dietary preferences", user_id="customer-7")
await save_turn(user_id="customer-7", user="I'm vegetarian", assistant="Noted!")
save_turn sends the user message to fact extraction, so the durable facts in it become memories; assistant is accepted but not stored as a memory. All surfaces share the same turn seeds, so the same user message sent for the same session through both MemorySyncSession and save_turn is extracted once. save_turn raises on failure — an explicit persist call is owed the truth.
Version support
| Package | Requires | Runtime |
|---|---|---|
openai-agents-memorysync 1.1.0 |
openai-agents installed alongside (any current 0.x) |
Python 3.10+ |
CI drives a real Runner — SQLite parity oracle, handoffs, retry convergence — against the latest openai-agents release on every push.
Documentation
Metadata
Release files for openai-agents-memorysync 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| openai_agents_memorysync-1.1.0.tar.gz | 19.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| openai_agents_memorysync-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 43.9 kB
Release files / openai_agents_memorysync-1.1.0.tar.gz
| Download URL | openai_agents_memorysync-1.1.0.tar.gz |
|---|---|
| Size | 19.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3a8b817e4e6e0344cf0d0c9b5b7ea64a223038d0a5faf06a78d0e3db43f961f6
|
|
BLAKE2b-256 checksum How to use checksums |
379c480a0b0be995db9ff9431ea7d7bfb67c39a5a446a55188c047fa673caab1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.5
|
Release files / openai_agents_memorysync-1.1.0-py3-none-any.whl
| Download URL | openai_agents_memorysync-1.1.0-py3-none-any.whl |
|---|---|
| Size | 24.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
78e0c7efef915939ef5cd08350288f0323b8be318e4129f9c185603aabd3108f
|
|
BLAKE2b-256 checksum How to use checksums |
aad87eb1fd3a507c810f91e9a313f51d342a8c7d4dac05c8cd4168393cb9647f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.5
|
Security for openai-agents-memorysync 1.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.