Concepts

Prompt Block

Make stored memory part of the system prompt so the next response can change.

Stored memory only matters when it reaches the next model call. MemexAI's prompt block is the bridge between the Postgres-backed memory record and the agent's behavior.

Use the helper

Compose your system prompt with getSystemPrompt / get_system_prompt:

const memory = memex.forUser({ userId: 'user_123', actor: 'assistant' })

const result = await generateText({
  model,
  system: await memory.getSystemPrompt(
    'You are a helpful assistant with durable user memory.',
  ),
  prompt: userMessage,
  tools: memory.createMemorySubagentToolset(),
  stopWhen: stepCountIs(5),
})

Why this matters

The most common integration mistake is wiring tools without wiring the prompt block. The agent can write memory correctly, but on the next turn it has no memory in context — so the response is still generic. system and tools are a pair: tools store and retrieve; the prompt block is what puts stored files into the model's context window.

If you forget the prompt block, memory appears to work (writes succeed, the admin UI shows files) but the agent still answers as if it knows nothing about the user.

What it contains

The prompt block tells the model:

  • that it has access to MemexAI memory
  • when to use memory_remember and memory_context
  • which virtual paths are writable or read-only
  • never to use physical database paths
  • all shared/* files visible to every user
  • all user/* files for the current user (user/index.md, when present, acts as a catalog the model uses to navigate these files)

Two-turn proof

Use this as the integration check:

Turn 1: Remember that I prefer quiet neighborhoods near parks.
Turn 2: What kind of neighborhood do I prefer?

A successful integration stores the preference on turn one, includes the MemexAI prompt block on turn two, and answers with the quiet-neighborhood preference without the user repeating it. The admin UI should then show the memory file, revision, and later access log.

On this page