← Catalog

pi-cortex

Cortex memory for pi: saves and recalls what the agent learns, consolidates it when pi compacts, and dreams nightly. Built for long-lived sessions such as pi-durable.

Extension

Install

Install with PiG

pig install npm:pi-cortex

Install with Pi

pi install npm:pi-cortex
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 0.1.0 (README.md). PiG does not review it.

pi-cortex

Cortex memory for pi. The agent saves what it learns, finds it again later, and Cortex consolidates it in the background, so a long-lived session (pi-durable, Tavern's host) keeps what compaction summaries drop.

What it does

  • Tools: cortex_save (one fact, decision, preference, fix or pattern) and cortex_recall (search this agent's memory and the global ~/.cortex store).
  • Every prompt gets a <memory> block in the system prompt: how to use memory, the consolidated context (entities, learned patterns, global knowledge) and the memories that match the message.
  • Session start: creates .cortex/ in the session's folder if needed, then cortex wake catches up anything an earlier run saved but never consolidated.
  • Compaction: cortex sleep. What the summary leaves out is still in Cortex.
  • Turn end: cortex sleep once 15 new memories have piled up.
  • Nightly: cortex dream once a day after 3:00 local time.
  • Shutdown: cortex sleep --micro (no LLM).

Writes to the store run one at a time, so a save never races a consolidation.

Model access comes from pi

Cortex's sleep and dream call a model. pi-cortex hands Cortex the agent's own pi login on each run: it picks a Haiku on the session model's provider (else the session model, else any Haiku pi can reach; CORTEX_PI_MODEL=provider/id to choose), resolves its key, base URL and headers through pi (so a gateway's workspace header comes along), and passes them as ANTHROPIC_API_KEY, ANTHROPIC_BASE_URL, CORTEX_HEADERS and CORTEX_MODEL. Nothing to configure in Cortex.

Only Anthropic Messages models qualify. Subscription (OAuth) logins aren't passed on; without another key Cortex falls back to LLM-free micro sleeps, and saving and recall still work.

Install

pi-cortex runs the cortex binary: ../target/release/cortex when it sits in a cortex checkout, else cortex on PATH (brew install thrashr888/tap/cortex), or CORTEX_BIN.

pi install /path/to/cortex/pi-cortex      # from a checkout

Settings

VariableDefault(blank)
CORTEX_BINsee abovecortex binary
CORTEX_PI_DIRsession cwdfolder holding the agent's .cortex/
CORTEX_PI_MODELHaiku on the session's providerprovider/id of the pi model Cortex uses
CORTEX_PI_INHERIT10: don't pass pi's model access; Cortex uses its own env
CORTEX_PI_SLEEP_AFTER15new memories that trigger a sleep at turn end (0 never)
CORTEX_PI_DREAM_HOUR3local hour after which the nightly dream runs (-1 never)
CORTEX_MODELoverrides the model pi-cortex picks
CORTEX_EXTRACT_ON_SAVE0 here1 extracts entities on every save instead of in sleep

Tests

cargo build && cd pi-cortex && npm test     # Node 22.18+; uses ../target/debug/cortex