Class CognitiveMemoryManager

Implements

Constructors

Methods

  • This manager as one session sees it: the same store, graph and mechanisms, with a working memory of its own. encode, retrieve and assembleForPrompt on the view focus traces in that working memory, and the view's active context lists only the traces the session encoded or recalled. Sessions that call the manager directly share its one working memory, whose slot list (trace ids and activations) is part of every assembled context.

    shutdown() on the view does nothing: whoever owns the manager shuts it down.

    Returns ICognitiveMemoryManager

    A view to hand to one session (one GMI).

  • Encode a new input into a memory trace. Called after each user message.

    Parameters

    • input: string
    • mood: PADState
    • gmiMood: string
    • options: {
          type?: MemoryType;
          scope?: MemoryScope;
          scopeId?: string;
          sourceType?: MemorySourceType;
          contentSentiment?: number;
          tags?: string[];
          entities?: string[];
          turnUserId?: string;
          perspectiveSource?: {
              eventId: string;
              eventHash: string;
          };
      } = {}
      • Optional type?: MemoryType
      • Optional scope?: MemoryScope
      • Optional scopeId?: string
      • Optional sourceType?: MemorySourceType
      • Optional contentSentiment?: number
      • Optional tags?: string[]
      • Optional entities?: string[]
      • Optional turnUserId?: string

        MemoryTrace.turnUserId: set on a trace a turn with no learner files for a second user.

      • Optional perspectiveSource?: {
            eventId: string;
            eventHash: string;
        }

        When encoding a subjective trace from PerspectiveObserver (@framers/agentos/memory/pipeline/observation/PerspectiveObserver), thread the source-event identifiers through so the resulting MemoryTrace carries the MechanismMetadata fields that applyReconsolidation reads at retrieval time.

        • eventId: string
        • eventHash: string

    Returns Promise<MemoryTrace>

  • Feed a conversation message to the observation pipeline.

    Pipeline flow:

    1. Observer extracts typed observation notes from buffered messages
    2. Notes are fed to the Reflector for consolidation into long-term traces
    3. Reflected traces are encoded via encode() (typed as semantic/episodic/etc.)
    4. Superseded traces are soft-deleted
    5. Commitment and intention notes are auto-registered with ProspectiveMemoryManager

    Parameters

    • role: "user" | "assistant" | "system" | "tool"

      Message role (user, assistant, system, tool)

    • content: string

      Message text content

    • Optional mood: PADState

      Optional PAD emotional state at observation time

    • Optional options: {
          contentSentiment?: number;
      }
      • Optional contentSentiment?: number

    Returns Promise<null | ObservationNote[]>

    Observation notes if threshold was reached, null otherwise

  • Check prospective memory triggers (Batch 2).

    Parameters

    • context: {
          now?: number;
          events?: string[];
          queryText?: string;
          queryEmbedding?: number[];
          maxTierRank?: number;
      }
      • Optional now?: number
      • Optional events?: string[]
      • Optional queryText?: string
      • Optional queryEmbedding?: number[]
      • Optional maxTierRank?: number

        Policy-tier ceiling forwarded to prospective.check, so the direct prospective-check path gates by session tier exactly like the assembly path (assembleForPrompt) already does.

    Returns Promise<ProspectiveMemoryItem[]>

  • Rehydrate a gisted/archived trace to its original verbatim content.

    Delegates to the configured IMemoryArchive. Returns null when no archive is configured or when the trace is not found/integrity fails.

    Parameters

    • traceId: string

      The trace id to rehydrate.

    • Optional requestContext: string

      Optional caller hint for audit.

    Returns Promise<null | string>

    The original verbatim content, or null.

  • Track a conversation message for context window management. Call for every user/assistant/system/tool message in the conversation.

    Parameters

    • role: "user" | "assistant" | "system" | "tool"
    • content: string

    Returns void

  • Run context window compaction if needed. Call BEFORE assembling the LLM prompt. Returns the (potentially compacted) message list for the conversation. If infinite context is disabled, returns null (caller should use original messages).

    Parameters

    • systemPromptTokens: number
    • memoryBudgetTokens: number

    Returns Promise<null | ContextMessage[]>

  • Delete every trace of one scope for good (MemoryStore.deleteScope), a batch at a time. What this manager keeps of each trace in a batch goes before the batch's traces (forgetTraces), so a call that fails part way can be made again and finds the same traces. With turnUserId, only the scope's traces that user filed as a second user on the session.

    Parameters

    • scope: MemoryScope
    • scopeId: string
    • options: {
          turnUserId?: string;
      } = {}
      • Optional turnUserId?: string

    Returns Promise<MemoryDeletion>

    Throws

    TypeError when scopeId is empty, or when turnUserId is given and is not a non-empty string.

  • Re-files the Brain's plain user and persona scope ids that hold a /, a % or a : in the encoded form a learning layer reads, once per Brain, and moves what the manager's store holds of the traces it moved; on a Brain another handle or process re-filed, the store follows the Brain's rows (MemoryStore.ensureEncodedScopeIds). The layer calls it when it first opens the manager. Optional, so a host's own implementation keeps compiling.

    Returns Promise<number>

    How many traces its re-file moved: none when the Brain held the record already.

  • Step-8: Force the reflector to run over pending notes regardless of threshold. Encodes reflection traces, soft-deletes superseded IDs. Safe to call when no reflector or no pending notes exist (returns an empty result). Errors do not propagate — reflection is non-critical.

    scopeOverride forces every encoded reflection trace to use the caller-supplied scope + scopeId, overriding whatever the reflector LLM invented. Callers that want all reflection traces to land in a single canonical scope (e.g. bench adapters that retrieve under user/bench) should pass this override.

    Parameters

    Returns Promise<FlushReflectionResult>

  • Attach a HyDE retriever to enable hypothesis-driven memory recall.

    When set, the retrieve() and assembleForPrompt() methods can accept options.hyde = true to generate a hypothetical memory trace before searching. This improves recall for vague or abstract queries by producing embeddings that are semantically closer to stored traces.

    Parameters

    • retriever: null | HydeRetriever

      A pre-configured HydeRetriever instance, or null to disable HyDE.

    Returns void

    Example

    memoryManager.setHydeRetriever(new HydeRetriever({
    llmCaller: myLlmCaller,
    embeddingManager: myEmbeddingManager,
    config: { enabled: true },
    }));