TypeScript SDK API Reference
The shape of `@neo4j-labs/agent-memory’s public surface, with deep links into the auto-generated TypeDoc reference for each symbol.
|
Full method-level reference lives in the TypeDoc-generated site at
The TypeDoc site is regenerated on every |
Installation
npm install @neo4j-labs/agent-memory
# pnpm add @neo4j-labs/agent-memory
# bun add @neo4j-labs/agent-memory
Requires Node.js 20+. Works in Bun, Deno, Cloudflare Workers, and Vercel Edge — the transport is fetch-only.
MemoryClient
The root class. Holds five subclients (shortTerm, longTerm, reasoning, query, auth) and the underlying Transport.
import { MemoryClient } from "@neo4j-labs/agent-memory";
// Zero-config: reads MEMORY_API_KEY from environment, targets hosted NAMS.
const memory = new MemoryClient();
// With options
const memory = new MemoryClient({
endpoint: "https://memory.neo4jlabs.com/v1",
apiKey: process.env.MEMORY_API_KEY,
timeout: 30_000,
headers: { "X-Trace-Id": traceId },
logger: (event) => console.log(event),
});
MemoryClientOptions
| Field | Type | Description | Default |
|---|---|---|---|
|
|
The NAMS REST endpoint. Auto-selects REST transport when ending in |
|
|
|
Bearer token for |
|
|
|
Dynamic token source (OAuth refresh, AWS STS, etc.). Overrides |
— |
|
|
Force the wire protocol. |
|
|
|
Per-request timeout in milliseconds. |
|
|
|
Extra request headers (User-Agent, trace headers, etc.). |
— |
|
|
Receives |
— |
TypeDoc: MemoryClient · MemoryClientOptions
client.shortTerm — short-term memory
Conversations, messages, three-tier context.
| Method | Purpose |
|---|---|
|
Append a message to a conversation. Returns the persisted |
|
Fetch a conversation by id, with its messages. |
|
Semantic + filter search across stored messages. |
|
Enumerate session ids (with message counts and timestamps). |
|
Remove a single message. |
|
Delete the whole conversation. |
|
Explicitly create a conversation with metadata (title, userId, workspace). |
|
Enumerate full conversation objects. |
|
Conversation header without the message list. |
|
Delete an entire conversation. |
|
Three-tier window: reflections, observations, recent messages — designed to be dropped into an LLM prompt. |
|
Persist many messages in one HTTP round-trip. |
|
Inline observations extracted from the conversation so far. |
|
Higher-level reflections generated when accumulated context crosses the compression threshold. |
Returned types: Message, Conversation, ConversationContext, SessionInfo, Observation, Reflection.
Hosted vs bridge: methods marked (hosted) require a NAMS REST endpoint (default). The bridge transport (for TCK conformance) raises NotSupportedError for these.
TypeDoc: ShortTermMemory
client.longTerm — long-term memory
Entities (POLE+O), preferences, facts, relationships.
| Method | Purpose |
|---|---|
|
Create an entity. Returns the persisted |
|
Record a preference (food, communication, dietary, etc.). |
|
Store a typed subject-predicate-object triple. |
|
Semantic search over entities, with optional type filter and |
|
Semantic search over preferences, with optional category filter. |
|
Look up an entity by exact name (returns |
|
Walk relationships outward from a given entity. |
|
Create a typed relationship between two entities. |
|
Merge |
|
Enumerate entities, optionally filtered by type, with pagination. |
|
Fetch an entity by id. |
|
Patch an entity’s description, type, or metadata. |
|
Remove an entity. |
|
Record positive/negative feedback that signals dedup/merge intent. |
|
Audit log of changes to an entity. |
|
Server-side merge with conflict resolution. |
|
Snapshot of the entity graph (nodes + edges) for visualization. |
Returned types: Entity, Preference, Fact, Relationship, EntityHistory, EntityGraph.
Entity types: hosted service uses lowercase strings — "person", "organization", "location", "concept", "tool", "custom". The bridge protocol uses POLE+O uppercase — "PERSON", "ORGANIZATION", "LOCATION", "EVENT", "OBJECT". The SDK normalizes both directions.
TypeDoc: LongTermMemory
client.reasoning — reasoning memory
Reasoning traces, steps, tool calls.
| Method | Purpose |
|---|---|
|
Begin a reasoning trace. Returns a |
|
Add a step (thought / action / observation) to a trace. |
|
Persist a tool call: name, arguments, result, status, duration. |
|
Mark the trace finished with an outcome and |
|
Fetch a trace including its steps and tool calls. |
|
Enumerate traces (filter by session, success, time range). |
|
Per-tool aggregate stats: success rate, average duration. |
|
"What did I do last time I tried something like this?" Semantic search over past traces. |
|
Record a "step" event for the hosted agent-trace surface. |
|
All steps recorded against a conversation. |
|
Server-generated explanation of why an agent did what it did. |
|
Pull the full reasoning trace tied to a conversation. |
|
"Which reasoning steps touched this entity?" — audit query. |
Returned types: ReasoningTrace, ReasoningStep, ToolCall, ToolStats, AgentStep, ConversationTrace, EntityProvenance.
Status values for ToolCall: "pending", "success", "failure", "error", "timeout", "cancelled".
TypeDoc: ReasoningMemory
client.query — read-only Cypher (hosted only)
| Method | Purpose |
|---|---|
|
Run a read-only Cypher query against the NAMS-managed graph. Returns |
TypeDoc: QueryConsole
client.auth — API key + OAuth (hosted only)
| Method | Purpose |
|---|---|
|
Enumerate keys in a workspace. |
|
Mint a new key. The plaintext key is only returned at creation — store it then. |
|
Permanently revoke a key. |
|
Re-reveal a stored key (one-time, if your account has the scope). |
|
Exchange a refresh token for a fresh access token pair. |
TypeDoc: AuthClient
Errors
Every error extends MemoryError and carries an optional requestId for correlation with server logs.
| Class | Raised when |
|---|---|
|
Base class. Catch this if you want everything. |
|
Network failure — DNS, refused, TLS handshake. Wraps the underlying |
|
HTTP 401 / 403. Missing, expired, or scope-restricted API key. |
|
HTTP 404. Conversation, entity, or trace id does not exist. |
|
HTTP 400. Required field missing or value out of range. |
|
HTTP 5xx after retries exhausted, OR any non-mapped status. Carries |
|
HTTP 429 after retries exhausted. Honors |
|
Method exists on the SDK but the current transport doesn’t implement it (e.g., calling hosted-only methods over a TCK bridge). |
import {
MemoryClient,
MemoryError,
AuthenticationError,
RateLimitError,
} from "@neo4j-labs/agent-memory";
try {
await memory.shortTerm.addMessage(sessionId, "user", text);
} catch (err) {
if (err instanceof AuthenticationError) {
// rotate the key
} else if (err instanceof RateLimitError) {
// back off; err.retryAfter is in seconds
} else if (err instanceof MemoryError) {
console.error("memory failure", { requestId: err.requestId, err });
}
}
TypeDoc: MemoryError and subclasses
Subpath exports
The package exposes six subpath exports beyond the root. Each is independently importable to keep tree-shaking honest on edge runtimes.
| Import | Exports | Use it for |
|---|---|---|
|
|
Standard application code. |
|
|
Wire memory into a Vercel AI SDK |
|
|
Register the 12 standard memory tools with an MCP server. See MCP tools. |
|
|
LangChain JS — duck-typed against |
|
|
Mastra agent framework. See Mastra. |
|
|
AWS Strands Agents SDK (JS). See Strands. |
|
|
TCK conformance testing against a local bridge server. Production code should not import from here. |
TypeDoc: each subpath’s exports are listed under the matching module in the TypeDoc index.
Observability
The logger constructor option receives typed `LogEvent`s for every transport call:
import { MemoryClient, type LogEvent } from "@neo4j-labs/agent-memory";
const memory = new MemoryClient({
logger: (event: LogEvent) => {
if (event.kind === "error") {
console.error("memory.error", event);
}
},
});
event.kind |
Fields |
|---|---|
|
|
|
|
|
|
See How-to: enable observability for the full pattern including OpenTelemetry forwarding.
Versioning
The TypeScript SDK follows SemVer:
-
Major — backwards-incompatible API change (rare; expect a migration guide).
-
Minor — new methods, new options. Existing code keeps working.
-
Patch — bug fixes, no API change.
Release tags are namespaced typescript-v<X.Y.Z> so they don’t collide with the Python SDK’s python-v<X.Y.Z> tags. The current published version is in
typescript/CHANGELOG.md.
See also
-
TypeScript SDK landing page — install + quickstart
-
NAMS REST API — the wire-level contract the SDK implements
-
Cross-Agent Memory Sharing — how this SDK interoperates with the Python SDK
-
TypeDoc — method-level reference
-
Source on GitHub —
typescript/src/