FishMem

OpenAI Agents SDK

Use FishMem as session memory for the OpenAI Agents SDK — recall before each run, persist after.

The @fishmem/openai-agents adapter attaches FishMem to an Agent / Runner from the OpenAI Agents SDK. It recalls relevant facts before each run (injecting them into the agent's instructions) and persists the exchange after the run completes.

Install

npm install @openai/agents @fishmem/openai-agents

The adapter reads FISHMEM_API_KEY from the environment by default.

export FISHMEM_API_KEY="fm_..."

Attach session memory

withFishMemSession wraps an Agent and a Runner so memory is applied around every run. Scope it by user_id (who the memory belongs to) and optionally run_id (which conversation it belongs to).

agent.ts
import { Agent, Runner } from "@openai/agents";
import { withFishMemSession } from "@fishmem/openai-agents";

const agent = new Agent({
  name: "support-agent",
  instructions:
    "You are a support agent. Personalize answers using the user's remembered context.",
  model: "gpt-4o",
});

// Bind a FishMem session to this user and conversation.
const session = withFishMemSession(agent, new Runner(), {
  userId: "alex",
  runId: "conv_8821",
});

// recall → inject into instructions → run → persist, all handled by the session.
const first = await session.run("My account email is alex@example.com.");
const second = await session.run("Remind me which email is on my account.");
console.log(second.finalOutput); // recalls alex@example.com from memory

What happens on each run

Recall

Before the model runs, the session searches FishMem scoped to userId / runId and prepends the matching facts to the agent's instructions.

Run

The Runner executes the agent as usual, now grounded in the recalled context.

Persist

After the run finishes, the session adds the user message and final output back to FishMem so the next run can recall them.

Scoping

Use userId to keep each person's memory separate, and runId when you want a session-local memory that doesn't bleed into the user's other conversations. Omit runId to share memory across all of a user's sessions. See scoping for the full model.

Next steps

On this page