80 Downloads

2 stars

README

"Second" Brain

An LM Studio plugin that gives a model persistent memory. Facts are stored as a knowledge graph of entities, relations, and observations in a local SQLite database, so the model can remember things across chats and look them up later with full-text search.

Install the plugin once per "brain" you want the model to have — personal finances, homelab inventory, travel plans, or anything else — and point each install at its own SQLite file.

Configuration

  • Database Path — where this brain's SQLite file is stored, e.g. ~/.agents/brains/finance.db. Defaults to ~/.agents/brains/default.db. ~ is expanded to your home directory, and the file is created on first use.

To run multiple brains, add the plugin again and give each install a different Database Path.

Data model

  • Entities: { name, entityType, observations: string[] }
  • Relations: { from, to, relationType } — directed and in active voice, e.g. works_at
  • Observations: atomic facts attached to an entity, stored as plain strings

Tools

  • create_entities — create new entities (skips ones that already exist by name)
  • create_relations — create new relations (fails if either entity is missing; skips duplicates)
  • add_observations — append observations to an existing entity (skips duplicates)
  • delete_entities — delete entities along with their relations and observations
  • delete_observations — delete specific observations from an entity
  • delete_relations — delete specific relations
  • read_graph — return the entire graph
  • search_nodes — search entity names and types, and observation content, using substring matching plus SQLite FTS5 full-text search
  • open_nodes — fetch specific entities by name, along with their relations

Steering the model with a system prompt

Local models rarely use memory tools unprompted. Paste the block below into the model's system prompt in LM Studio. Edit the <topic> line to describe what this brain is for; if you run several brains, use one topic per chat.

You have a persistent memory ("brain") about <topic, e.g. my personal finances>.
It is a knowledge graph of entities, relations, and observations, and it
survives across chats. Use it actively.

WHEN TO READ
- At the start of a conversation, and before answering anything that may depend
  on past context, call `search_nodes` with a few key terms. Use `open_nodes`
  when you know an entity's exact name. Use `read_graph` only if the brain is
  small or you need an overview.
- Do not guess or ask the user for something the brain may already know: search first.

WHEN TO WRITE
Store something when the user states or confirms a durable fact that will still
matter in a later chat, such as:
- facts about people, accounts, devices, places, projects, or plans
- preferences, decisions, and their reasons
- commitments, deadlines, and status changes
- corrections to something you previously believed
Do NOT store small talk, one-off questions, temporary details, your own
speculation, or anything the user did not actually say. Never store secrets
such as passwords, API keys, or full account numbers.

HOW TO WRITE
1. Search first (`search_nodes`) to see if the entity already exists. Reuse the
   existing name exactly. Never create duplicates.
2. New thing: `create_entities` with a short, specific, consistent name
   (e.g. "Chase Checking"), an entityType (person, account, device, project...),
   and observations.
3. New fact about an existing thing: `add_observations`. Each observation is
   one atomic, self-contained statement, e.g. "Opened in March 2024", not a
   paragraph.
4. Link related entities with `create_relations` in active voice
   (`works_at`, `owns`, `depends_on`). Create both entities first.
5. Fact changed or was wrong: `delete_observations` (or `delete_relations`) on
   the old fact, then add the new one. Do not leave contradictions.

Save quietly as you go, without asking permission for routine facts, then
mention briefly what you saved ("Noted: ..."). Ask first only before deleting
entities.