Use it well
Documentation · updated 9 November 2026
In short: localmem keeps each of your customers' memory over time and already handles history, duplicates, retries, conflicts, sources and separation between customers. Your code sends what it learns and asks what it needs. Do not read before you write to avoid duplicates, do not keep your own copy of the history, and do not ask again for an answer you already have. Read this before wiring localmem into a product; coding agents should read it before writing code.
What localmem already does: do not build it again
| localmem does this | So your code does not |
|---|---|
Duplicates and retries. facts and write take an idempotency_key: a repeat answers the first call with duplicate: true and stores nothing again. A document with the same Idempotency-Key within 24 hours is read once. | Read memory before writing to check whether something is already there. Give each write a key built from what it holds (below) and send it; a repeat costs nothing. |
One value per subject, predicate and time. A fact with the same subject, predicate and as_of as an earlier one replaces it, even after newer values. Sending a value again does not make a second copy. | Track which values you already sent, or delete before correcting. Send the corrected value with its original as_of. |
History over time. Every value keeps the period it held. recall and search with at_time answer as things stood then; without it, recall returns the whole history, replaced values marked retired_at. | Keep your own timeline or "previous value" columns for what you send us. |
Changes and conflicts. A write answers superseded (each value it replaced, was and now) and bounded (each late value that holds only until a newer one). | Compare old and new values yourself to find what changed: read it from the answer you already got. |
Sources and dates. Each fact carries the memory it came from and when it held. Your own id for a value goes in ref. | Store a mapping from your ids to ours. |
Reading documents. documents.send has a model read prose into facts, kept with the document as their source. | Run your own extraction for prose. If you already have structured values, send them as facts: no model is involved. |
| Customers kept apart. Each customer has its own memory and its own data keys; a key reaches only its project's customers, and test only test. | Filter answers by customer, or put several of your users in one customer. |
Rate limits. The SDKs wait and retry a rate_limited answer, a busy server and a timeout that cannot repeat work. | Write your own retry loop around the SDK. |
Deleting a customer. customers.delete stops access at once and removes its memory; the data contract says when no copy remains. | Delete facts one by one when a user leaves. |
What localmem does not do
- It does not compute your figures. Your product works out a value (a score, a rate, a status) and sends it; localmem remembers it over time.
- It is not your database. It answers by subject (
recall), by meaning (search) and as a summary (profile); it does not run arbitrary queries, joins or counts across customers. Keep your product's own records where they are. - It does not call you. There are no notifications when something changes; you ask when you need it, and a background document is followed with
documents.wait. - It does not send your data to a model unless you send a document.
facts,writeand every read stay on localmem. - It does not decide what one customer is. That is your product's user or company, made with your own id.
Writing efficiently
- Build the idempotency key from the value. For example
player-42:endgame_accuracy:2026-10:71, or a hash of it. The same value sent twice is stored once; a changed value has a new key and is written. No read is needed first. - Batch. One
factscall takes up to 200 facts, each with its ownas_of, so a year of monthly values is one call, in any order. - Write when something is learned, not on a timer. A value that did not change does not need sending; if you send it anyway, it costs one write and changes nothing.
- Prose to
documents.send, structured values tofacts. Documents are the costly kind (a model reads them); facts are not. - Put your id in
ref, never a name or other content in a customer'sexternal_ref.
Reading efficiently
- Read where the product needs context: when a user asks, when a page shows memory, when an agent starts a task. Not once per item processed.
- Keep an answer until you write for that customer. A customer's memory changes only when you write to it, so the answer you got stays right until your next write for them (or until a value you sent with a future
as_ofstarts). - Ask for what you need.
recallwithat_timeset to now for current values only; withreffor one value you wrote; withlimitandnextfor a long history.searchwith a smallk.profilefor a short summary to hand an agent. - Never read just to check a write landed. The write's answer says what was stored.
Limits
429 rate_limited: too many at once. The SDKs waitRetry-Afterseconds and try again; nothing for you to do. To send less, batch.429 monthly_limit: this month's documents or writes are used. Do not retry: from 0.1.3 (coming soon) the SDKs hold that kind of call back untilresets_ator until the allowance is back, without sending it, andpaused()says so. Let your product keep working without it. Searches never stop: past twice their allowance they are only slowed. For example, analysis still runs and shows; only new memories are not saved. Tell your users quietly, such as "memory paused until 1 December", never as an error. Your admins are emailed at 80% and 100%, and Team → API shows the month; going live or a larger plan raises the allowance.GET /v1/partner/usage(usage()in the SDKs) gives each day's documents, writes and reads per customer, to see what your code spends.
Before writing code: a checklist for coding agents
- Ask what one customer is in this product, what it sends (documents, chat turns, facts) and whether any of it is health data.
- Put the client in one module. Write where the product learns something, read where it needs context, handle errors once.
- Give every
factsandwritecall anidempotency_keybuilt from what it holds. Do not add a read before a write. - Do not store a copy of memory's history, a "last sent" table or a retry loop: localmem does those.
- Handle
monthly_limitby pausing that kind of call untilresets_at, with the product still working. Every answer'sx-localmem-allowance-remainingheader (allowance()in the SDKs from 0.1.3) lets you slow down before a limit. - Check a day's
usage()after the first real run: reads far above writes usually mean reads in a loop.