Skip to main content

TypeScript SDK

The TypeScript SDK (@senselab-ai/amfs) connects Node.js and TypeScript agents to your SenseLab account — briefings, reads and writes, search, outcomes and decision traces over the HttpAdapter — and ships an in-memory adapter with ReadTracker, auto-causal linking, scopes, transactions and integrity verification for tests and prototypes.

Installation

The package is ESM-only, has no runtime dependencies, and needs Node.js 18 or later for the built-in fetch. The package name still carries the project’s original name, AMFS (Agent Memory File System); npm install @senselab-ai/amfs gets you SenseLab.

Two ways to run it

The HttpAdapter is how the SDK reaches your account. Its *Async methods are what you use in an agent; the synchronous API exists for the in-memory adapter.
Over the HttpAdapter, the synchronous methods read(), write(), list() and commitOutcome() are stubs: they return null, the unsaved entry, [] and [] without calling the server, and they do not throw. Use the *Async methods on the adapter for anything that should reach SenseLab.

Quick start: connected to SenseLab

Get an API key from Settings → API Keys (see Connect to SenseLab), then:
Pass causalEntryKeys on remote commits: the SDK’s ReadTracker only sees synchronous reads, so it has nothing to credit for entries fetched with searchAsync or readAsync.
The SDK does not read AMFS_HTTP_URL or AMFS_API_KEY on its own. Those variables are honoured by the MCP server and the CLI; in TypeScript, pass the URL and key to HttpAdapter yourself, as above.

Connecting to SenseLab

Using the HttpAdapter

The HttpAdapter provides async methods for everything that reaches your account:
Requests that fail are thrown as Error("AMFS API <status>: <body>"), so a wrong key surfaces as a 401 on the first call rather than as silently missing data.

Direct REST calls

See the Connect to SenseLab guide, MCP server, and REST API reference for details.

Quick start: in memory

The sections from here through Stats describe the synchronous API, which runs on the in-memory adapter. Use it in unit tests and prototypes; in an agent, use the *Async methods above.

Constructor

Pass the HttpAdapter to reach your SenseLab account. Without adapter, the SDK uses the in-memory adapter and nothing leaves the process.

ReadTracker & Auto-Causal Linking

The TypeScript SDK includes a ReadTracker that automatically logs every read() call and external context. When you call commitOutcome() without explicit causal keys, the SDK uses the read log to build the causal chain — identical to the Python SDK behavior.

Agent-Scoped Memory

The SDK distinguishes between shared memory and agent-scoped memory. Use recall, myEntries, and readFrom for explicit agent-level operations.

Scopes

A MemoryScope provides a focused view bound to a single entity path, reducing boilerplate when working with one service or module.

Composite Scoring with RecallConfig

Pass a recallConfig to get scored results with breakdown information:

Version History


Watch

Subscribe to changes on an entity path:

Transactions

Group multiple writes into an atomic commit:

Integrity Verification

Verify content hashes and integrity chains for stored entries:

Commit Log & DAG

Inspect the commit history and navigate the commit DAG:

Stats


Rooms & Collaboration

The SDK includes room-based collaboration APIs for multi-agent knowledge sharing and negotiation. These require an HttpAdapter connection.
In the current release (0.3.2) the room and negotiation helpers below build their own request and do not attach the adapter’s API key, so against SenseLab they are rejected with 401. Until a later release fixes this, use rooms through the MCP server or the REST API.

Negotiation

Rooms support structured negotiation sessions between agents:

Full API Reference

AgentMemory

Constructor

read

write

list

search

history

stats

watch

verify

transaction

commitLog

commonAncestor

recordContext

explain

commitOutcome

recall

myEntries

readFrom

scope

listScopes

info

tree

clearReadLog


MemoryScope

A scoped view bound to a fixed entity path. When readonly is true, writes throw an error.

TransactionContext


Exports


OutcomeType Values


Troubleshooting

Nothing shows up on the dashboard. Either the memory is on the default in-memory adapter, or you called the synchronous methods over an HttpAdapter — they are stubs and never reach the server. Pass { adapter: new HttpAdapter({ url, apiKey }) } and use adapter.readAsync / writeAsync / commitOutcomeAsync. See Two ways to run it. Error: AMFS API 401. The API key is missing or wrong. Keys come from Settings → API Keys on the dashboard; the SDK does not read AMFS_API_KEY from the environment for you. commitOutcomeAsync moved no confidence. Pass causalEntryKeys — the entries the run relied on, as "entity/key" strings. The local ReadTracker cannot see reads made with the async methods. Room calls fail with 401. Known limitation of 0.3.2 — see the warning under Rooms & Collaboration above. Use the MCP server or the REST API for rooms in the meantime.

See also