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 helpersget_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), "query", "full".

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openai_agents_memorysync-1.0.1.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openai_agents_memorysync-1.0.1-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file openai_agents_memorysync-1.0.1.tar.gz.

File metadata

  • Download URL: openai_agents_memorysync-1.0.1.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.9

File hashes

Hashes for openai_agents_memorysync-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e9bf1c67807300404d37f299a89fdfdb840e7646301195e5517031079bd00106
MD5 7d20ef0818e245364139b70120a99586
BLAKE2b-256 65488aaeaf0547bbc49b69ba7253cc46aac8879a3e3b67c383daa1be7e3d17ad

See more details on using hashes here.

File details

Details for the file openai_agents_memorysync-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for openai_agents_memorysync-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 89f5717f9d88d9d99b38e55168e24b137a34edf04af6934c545b6f63223210d5
MD5 46c508c7bfbebff45456e547f5ecc169
BLAKE2b-256 d386415660b2ff70160ec3d92d72fd42e03ba0be2021b6080d945baffe5ca3f1

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page