LLMSlim + Mastra
Long-term memory for Mastra agents as tools and an output processor, with no LLM writing your memory and nothing injected into the prompt.
The llmslim npm package is a client for an llmslim serve server. Its llmslim/mastra entry gives a Mastra agent recall_memory and remember tools, and an output processor that saves each user message and reply. Messages are stored word for word and selected at read time within a token budget, so nothing is summarized or extracted into a wrong fact. Recalled memory reaches the model as a tool result, which stays in the agent's history like any other message.
1. Installation and setup
The client talks to an llmslim serve server (Python, one process, one SQLite file or Postgres). Call it from your backend: an API key gives access to every user's memory.
npm install llmslim @mastra/core # @mastra/core 1.29.1 or newerStart the memory server:
pip install "llmslim[server]"
llmslim serve # http://127.0.0.1:8080; set LLMSLIM_API_KEYS to serve beyond localhost2. Architecture & execution flow
3. Production code pattern
import { Agent } from "@mastra/core/agent";
import { MASTRA_RESOURCE_ID_KEY } from "@mastra/core/request-context";
import { LLMSlim } from "llmslim";
import { memoryProcessor, memoryTools, type MemoryOptions } from "llmslim/mastra";
const memory: MemoryOptions = {
client: new LLMSlim(), // LLMSLIM_BASE_URL and LLMSLIM_API_KEY, or pass baseUrl and apiKey
// Whose memory: the signed-in user, from your server, for each request.
scope: (requestContext) => ({ userId: requestContext.get(MASTRA_RESOURCE_ID_KEY) }),
};
export const assistant = new Agent({
id: "assistant",
name: "Assistant",
instructions: "You are a helpful assistant.",
model: "anthropic/claude-haiku-5-5",
tools: { ...memoryTools(memory) }, // recall_memory and remember
outputProcessors: [memoryProcessor(memory)], // after any guardrails
});4. Options
Keyword arguments, shown as name = default.