0xBUFF / docs

Narrative memory

Integrate scoped facts, revision-bound proposals and host-owned deletion.

Narrative facts describe preferences, struggles and observations. They do not represent grades or official progress. Bind the optional MemoryPort to one authenticated learner and consent epoch.

Recall facts

Authorize memory.recall through grants, consent and installed capabilities. The adapter receives a bounded query and signal. Return active facts with actor, revision, fact ID, source reference and completeness. Report truncation when the limit prevents a complete response.

This synthetic example uses an already-authorized scope and demonstrates read-only recall with an offline model.

// preceptor-docs: runnable
import { POLICY_REVISION, runInstruction } from "@0xbuff/preceptor";

const host = {
  policyRevision: POLICY_REVISION,
  sessionId: "example-session",
  mode: "guided_learning",
  grants: ["memory.recall"],
  consent: ["memory.recall"],
  installed: ["memory.recall"],
};

// This synthetic read-only fixture represents an already authorized host scope.
const fact = {
  factId: "example-fact",
  kind: "preference",
  text: "Prefers small worked examples.",
  actor: "learner",
  revision: 1,
  sourceRef: "example-source",
};
const memory = {
  recall: async (query) => {
    const fits =
      query.limit > 0 &&
      new TextEncoder().encode(JSON.stringify(fact)).length <= query.maxFactBytes;
    return {
      kind: "facts",
      facts: fits ? [fact] : [],
      completeness: fits ? "complete" : "truncated",
    };
  },
};

const model = {
  provider: "example",
  model: "offline",
  generate: async (input) => {
    const attribution = { provider: "example", model: "offline" };
    if (input.context.toolResults.length === 0)
      return {
        kind: "tools",
        attribution,
        requests: [{ callId: "recall", operation: "memory.recall", arguments: { limit: 1 } }],
      };
    return { kind: "final", attribution, text: "Try a small worked example." };
  },
};

const result = await runInstruction(
  host,
  { assistance: "generate", text: "Help me practice" },
  { memory, model },
);
if (
  result.status !== "completed" ||
  result.usage.memoryItems !== 1 ||
  result.usage.toolAttempts !== 1 ||
  result.usage.modelRequests !== 2
)
  throw new Error("Expected one recalled fact and an advisory result");
console.log(result.status);

Expected output: completed. The engine performs one recall and two model invocations.

Propose changes

OperationModel arguments
memory.recallOptional topic and limit
memory.rememberKind and text; factId and expectedRevision for an update
memory.forgetfactId and expectedRevision

A remember request without a target creates a fact. Updates and forget target eligible model-owned revisions delivered during the current run. Learner-edited revisions take precedence. The model cannot assign the actor, durable operation ID, lineage or scope.

The host atomically checks scope, consent, expected revision and idempotency before admitting a proposal. Return applied with operationId, factId and revision, or declined with reason conflict, denied, revoked, suppressed or unavailable. Identical operation replay returns its prior receipt; conflicting payloads cannot reuse an identity. Invocation sessionId and attempt are run-local correlation coordinates.

The engine removes superseded facts from later model context when a newer revision or applied mutation is observed. Already charged usage is retained.

Use MemoryLifecyclePort separately for authenticated export and deletion. Do not install it in session ports. Cancel affected sessions and suppress stale callbacks and replay after deletion or consent revocation. Keep minimal opaque suppression markers without retaining deleted prose. The host controls retention, backups and physical erasure.

A successful mutation receipt can survive later generation failure. A cancelled or malformed response may leave a remote mutation ambiguous. Reconcile it using the original authorized operation identity; do not automatically replay a mutation.

See architecture and contracts.

On this page