OpenAI Agents SDK
@neurophic/openai-agents wraps the JavaScript SDK for the OpenAI Agents SDK. It needs Node 22 or later, the runtime the Agents SDK needs.
Install
npm install neurophic @neurophic/openai-agents @openai/agents zod
pnpm add neurophic @neurophic/openai-agents @openai/agents zod
yarn add neurophic @neurophic/openai-agents @openai/agents zod
createTools
import { Agent, run } from '@openai/agents';
import { createTools } from '@neurophic/openai-agents';
import { Neurophic } from 'neurophic';
const client = new Neurophic({ apiKey: process.env.NEUROPHIC_API_KEY });
const { remember, recall } = createTools({
client,
identifier: 'user-123',
name: 'Ada',
search: { roles: ['user', 'assistant'], sources: true, rerank: 'fast' },
});
const agent = new Agent({
name: 'Travel assistant',
instructions: 'Use recall before answering and remember what the user shares.',
tools: [remember, recall],
});
const result = await run(agent, 'Remember that I prefer window seats on long flights.');
createTools returns two tools for an Agent:
remember. Takescontent; see API reference > Ingest.recall. Takesqueryandgoal,since,untilandlimit, each nullable; see API reference > Retrieve. It returns the memories as Markdown.
search is applied to every recall call and is set by you, never by the model: roles for whose words to return, sources to also return the original turns, and rerank for a second ranking stage before the cut.
The Agents SDK uses strict tool schemas, where every field must be present, so the optional recall parameters are nullable rather than optional. The model sends null for the ones it does not use.
createContextFilter
createContextFilter puts the memories relevant to the latest user message in front of the model on every turn, with no tool call. It returns a callModelInputFilter, which the Agents SDK runs before each model call; pass it to run() or to a Runner.
import { Agent, run } from '@openai/agents';
import { createContextFilter } from '@neurophic/openai-agents';
import { Neurophic } from 'neurophic';
const client = new Neurophic({ apiKey: process.env.NEUROPHIC_API_KEY });
const agent = new Agent({
name: 'Travel assistant',
instructions: 'You are a travel assistant.',
});
const result = await run(agent, 'Can you find me a flight to Lisbon next month?', {
callModelInputFilter: createContextFilter(client, { identifier: 'user-123' }),
});
It takes:
identifier. Whose memory to read.roles,sources,rerank. Optional; the same search options ascreateTools, see API reference > Context.template. Optional(context, instructions) => string; the default appends a## Context from memoryheading and the context lines to the agent's instructions.
withContext
withContext calls client.context and returns an instructions string with the context appended, for when you build the instructions yourself.
import { withContext } from '@neurophic/openai-agents';
const userMessage = 'Can you find me a flight to Lisbon next month?';
const instructions = await withContext(client, {
identifier: 'user-123',
query: userMessage,
instructions: 'You are a travel assistant.',
});
With the default template, the returned string is:
You are a travel assistant.
## Context from memory
- Prefers window seats on long flights. (memory)
It takes query, an optional instructions and template, and the same roles, sources and rerank. Like the filter, it returns the instructions unchanged when nothing is relevant or the request fails.
Learn more under API reference > Context.