Skip to content

Memory Types

shared.memory_types

Typed memory — 14 categories with per-type retention/decay/boost policy.

14 types: instruction, fact, decision, goal, preference, commitment, relationship, observation, rule, todo, question, hypothesis, context, procedural (S17, ENGRAM: "how to do X" — the data foundation for Stage 2 behavior annotations).

Each type has its own: - default_importance (auto-fill on save) - decay_rate (0 = never decays) - never_archive flag - requires_expires_at flag - boost_on_keywords for retrieval

MemoryKind

Bases: str, Enum

Source code in shared/memory_types.py
class MemoryKind(str, enum.Enum):
    INSTRUCTION = "instruction"
    FACT = "fact"
    DECISION = "decision"
    GOAL = "goal"
    PREFERENCE = "preference"
    COMMITMENT = "commitment"
    RELATIONSHIP = "relationship"
    OBSERVATION = "observation"
    RULE = "rule"
    TODO = "todo"
    QUESTION = "question"
    HYPOTHESIS = "hypothesis"
    CONTEXT = "context"
    PROCEDURAL = "procedural"

get_policy

get_policy(kind)

Get policy for a kind. Unknown kinds fall back to FACT.

Source code in shared/memory_types.py
def get_policy(kind: MemoryKind | str) -> TypePolicy:
    """Get policy for a kind. Unknown kinds fall back to FACT."""
    try:
        k = MemoryKind(kind) if isinstance(kind, str) else kind
    except ValueError:
        k = MemoryKind.FACT
    return _REGISTRY[k]

kind_for_text

kind_for_text(text)

Best-effort heuristic for auto-classification. Returns FACT if nothing matches.

Four gates apply. QUESTION is decided by _is_question, TODO by _is_task_request, RULE by _is_prohibition — by the SHAPE of the text, not by one word appearing in it — and harness framing is stripped before any of them runs, because the framing carries a RULE keyword of its own.

ONE MATCHER PER LANGUAGE. Russian keywords match by substring, deliberately: a boundary costs the Russian stems tens of live matches each, because the house writes feminine and prefixed forms the key does not spell. English keywords match at a word start with a hyphen treated as part of the word, deliberately: there the plain substring only ever hit compounds, while a strict boundary would also kill the inflections the suite requires. See _keyword_hits for the measurement.

Returning FACT is not a failure: it is the honest answer for text that matched no pattern, and it costs a coarser retrieval hint. Over-tagging is what this replaces.

Source code in shared/memory_types.py
def kind_for_text(text: str) -> MemoryKind:
    """Best-effort heuristic for auto-classification. Returns FACT if nothing matches.

    Four gates apply. QUESTION is decided by `_is_question`, TODO by `_is_task_request`,
    RULE by `_is_prohibition` — by the SHAPE of the text, not by one word appearing in
    it — and harness framing is stripped before any of them runs, because the framing
    carries a RULE keyword of its own.

    ONE MATCHER PER LANGUAGE. Russian keywords match by substring, deliberately: a
    boundary costs the Russian stems tens of live matches each, because the house writes
    feminine and prefixed forms the key does not spell. English keywords match at a word
    start with a hyphen treated as part of the word, deliberately: there the plain
    substring only ever hit compounds, while a strict boundary would also kill the
    inflections the suite requires. See `_keyword_hits` for the measurement.

    Returning FACT is not a failure: it is the honest answer for text that matched no
    pattern, and it costs a coarser retrieval hint. Over-tagging is what this replaces.
    """
    text = _strip_harness(text)
    tl = text.lower()
    for kind, kws in _KEYWORD_MAP:
        if kind is MemoryKind.QUESTION:
            if _is_question(text):
                return kind
            continue
        if kind is MemoryKind.TODO and _is_task_request(text):
            return kind
        if kind is MemoryKind.RULE:
            if _is_prohibition(text, kws):
                return kind
            continue
        if any(_keyword_hits(kw, tl, text) for kw in kws):
            return kind
    return MemoryKind.FACT