Skip to main content

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 for Runner.run(..., session=...): survives restarts and deploys, follows multi-agent handoffs, extracts long-term memory automatically.
  • 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.

Items are stored and returned byte-for-byte — assistant messages, function calls, tool outputs, reasoning items — verified in the test suite against OpenAI's own SQLiteSession, item for item. Each session lives in its own server-side namespace: clear_session() can only ever reach that one conversation, and function-call JSON never pollutes the user's long-term memories.

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 seeds.

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.2 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!")

All surfaces share the same idempotency seeds, so mixing styles cannot double-store a turn. save_turn raises on failure — an explicit persist call is owed the truth.

Version support

Package Requires Runtime
openai-agents-memorysync 1.0.1 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.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openai-agents-memorysync 1.0.2
File Size Uploaded Provenance
openai_agents_memorysync-1.0.2.tar.gz 18.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for openai-agents-memorysync 1.0.2
File Interpreter ABI Platform
openai_agents_memorysync-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 41.6 kB

Release files / openai_agents_memorysync-1.0.2.tar.gz

Download URL openai_agents_memorysync-1.0.2.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9eaf9804ccf6520b157e26132cd1a345367fc77de17c53cfa70721ce948bec8c
BLAKE2b-256 checksum
How to use checksums
7cd362f8734ebff60545cb7f0dee4040279bed9676b5cb63392e3e4e32811fb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / openai_agents_memorysync-1.0.2-py3-none-any.whl

Download URL openai_agents_memorysync-1.0.2-py3-none-any.whl
Size 23.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c865ae52de78d55eab65a99ca252f8702f7fa8e59f12aae7bb0ad11aea73710
BLAKE2b-256 checksum
How to use checksums
5bc2d824913902011b7ba7b51b9127dd0ae963990642f6ba69c3816a0d5b5f5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Security for openai-agents-memorysync 1.0.2

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page