Cognitive Schemas
A cognitive schema is a high-level mental model that organizes many lower-level memories under one idea — and tells you when to apply it. Engrams gives your agent the same machinery: a confirmed schema pairs a plain-language claim (statement), a conditional instruction(summary: when it fires and what to do), an explicit scope(tags and paths), and the cited notes it rests on, so the agent loads the model instead of re-reading the history.
advise and prime can decidebefore any file is opened whether this situation is one the project has already reasoned about.How human schemas organize memory
Cognitive psychology describes memory as layered. At the bottom sit individual episodes and facts; at the top sit schemas — abstract frames like code review or restaurant visit that group those episodes together. A schema does two things:
- It organizes. Specific memories become instances of the schema. You do not storerestaurant visit #47 from scratch; you store what was different from the frame, and the frame supplies the rest.
- It activates conditionally. A schema carries an activation trigger — cues in the environment (a menu, a pull request diff) — plus procedural rules for what to do once it fires. Recall is top-down: the cue selects the schema, and the schema selects which lower-level memories matter.
This is why humans never search their memory linearly. The right frame arriving early is what makes behavior fast and consistent — and it is exactly what an LLM agent lacks when it greps a repository cold.
How schemas guide LLM retrieval in Engrams
An Engrams schema is a confirmed concept formed from a reviewed proposal. Each proposal cites at least three current knowledge notes (decisions, system patterns, progress entries, or custom data) spanning at least two files or two days, and defines four things:
- Claim (
statement): What the notes mean together, in plain words (checked against restating any single note). - Instruction (
summary): A conditional sentence opening with a trigger phrase:Fires when <trigger condition>: <operational rule> - Scope (
scope.paths&scope.tags): Where the schema applies — including brand-new files in those directories before any note is anchored to them. - Evidence (
members): The snapshot of cited notes (plus optional counter-evidence incontrary).
Every retrieval surface explains why a schema appeared (matched_by) and where it came from (origin):
| Surface | How the schema guides it |
|---|---|
engrams advise <paths> | Resolves active schemas whose member anchors touch the target paths (member_anchor) or whosescope.paths cover the path (scope_path, including new files not yet on disk), printing each schema's statement, summary, scope, and matched_by in aschemas block above low-level constraints (and ahead of violations if an omp pre-edit rule blocks an edit). |
engrams prime --paths --tags | Ranks schemas that match the target paths or tags above unmatched schemas (with matched_by), and surfaces up to 3 oldest undecided proposals in pending_proposals with ready-to-runconfirm_command and reject_command strings. |
engrams query <q> | Matches schemas across statement, summary, member centroids, and scopevocabulary, returning the schema tier ahead of individual notes with matched_by. |
engrams schema show <target> | Returns the schema's statement, summary, scope, origin(proposal ID, source, and proposed/confirmed timestamps), and every member enriched with type-specific details, capped at 20 members with a truncation flag for large clusters. |
engrams brief schema:<id> | One call returns the schema's claim, instruction, scope, kind, origin, and enriched details for all immediate members. |
The trigger and scope are what make this work for an LLM: matching a path prefix, tag, or short conditional sentence against the current prompt or edited paths is cheap, while the claim and directive tell the model how to act immediately — even when creating a brand-new file inside the scoped directory.
Proposing, reviewing, and refining a schema
Schemas are never auto-promoted in bulk. An agent proposes a schema over cited notes (seeded from a session-close prompt with --thread <tag> --lens <name> --members ... or a detector group via--from <sig-prefix> --lens <name>), Engrams validates the evidence and wording gates, and a person confirms or rejects the proposal:
# 1. Agent proposes a schema (from a session-close prompt, a staged detector group, or explicit --members)
engrams schema propose \
--from decision:58 --lens software \
--name error-envelope \
--statement "Public fallible functions share one error envelope so callers never handle raw panics" \
--trigger "adding or editing a fallible public function in Rust code" \
--rule "return the AppError envelope and never unwrap outside tests" \
--scope-paths src/ops --scope-tags rust,errors
# 2. Person reviews pending proposals and confirms (optionally overriding fields inline) or rejects
engrams schema proposals --status proposed
engrams schema confirm proposal:1
engrams schema reject proposal:2 --reason "One-off migration notes, not a recurring rule"
# 3. Refine an existing schema's claim, scope, or instruction at any time
engrams schema refine error-envelope \
--statement "Public fallible functions share one error envelope so callers never handle raw panics" \
--scope-paths src/ops --scope-tags rust,errors \
--trigger "editing public Rust APIs" \
--rule "return Result<T, AppError> and convert inner errors with ?"
# Accepted summary openers: "Fires when", "When", "Applies if", "Activates when"schema propose refuses proposals with fewer than 3 current knowledge notes, notes confined to a single file and single day, code files cited as notes (put files in--scope-paths), a --statement that merely repeats a single note (token overlap ≥ 0.8), an instruction without a conditional trigger prefix, or notes that repeat pending, confirmed, or recently rejected territory.Authoring principles
- Write the claim (
--statement) as the synthesized insight. Say what the notes mean together in plain words, not a copy-paste of one decision summary. - Write the trigger as observable context and the rule as an imperative. A file path, a file kind, or a task verb paired with a concrete directive lets the agent comply without opening more files.
- Set
--scope-pathsand--scope-tagswhere the concept applies. If omitted, Engrams defaults scope tags to tags carried by at least two cited notes and scope paths to the deepest shared anchor directory — lettingadvisefire on new files created in that directory. - Evidence first, proposal second, human confirmation third. Let
schema scanstage candidate clusters, propose from them withschema propose --from <sig-prefix>, and let a person runschema confirm proposal:<id>. - One schema per recurring situation. If two triggers always fire together, they are one schema; if one trigger demands two unrelated rules, it is two schemas.
Example: software architecture
A cluster of error-handling decisions, a result-envelope pattern, and the central error type become one schema that fires on any fallible-function work:
engrams schema propose \
--members system_pattern:12,decision:58,decision:61 \
--name error-envelope \
--statement "Public fallible functions share one error envelope so callers never handle raw panics" \
--trigger "adding or editing a fallible public function in Rust code" \
--rule "return the AppError envelope and never unwrap outside tests" \
--scope-paths src/ops --scope-tags rust,errors
engrams schema confirm proposal:1Running engrams schema show error-envelope returns the schema, its claim, scope, proposal origin, and enriched members:
{
"status": "success",
"schema": {
"id": 4,
"name": "error-envelope",
"statement": "Public fallible functions share one error envelope so callers never handle raw panics",
"summary": "Fires when adding or editing a fallible public function in Rust code: return the AppError envelope and never unwrap outside tests.",
"summary_source": "agent",
"scope": { "tags": ["errors", "rust"], "paths": ["src/ops"] },
"status": "active",
"kind": "schema",
"origin": {
"proposal_id": 1,
"source": { "kind": "manual", "ref": null },
"proposed_at": "2026-10-22T12:00:00Z",
"confirmed_at": "2026-10-22T12:05:00Z",
"session": "s-42"
},
"members": [
{
"kind": "system_pattern", "id": 12, "name": "result-envelope",
"description": "Public fallible functions return Result<T, AppError>.",
"severity": "error", "anchors": ["src/ops"]
},
{
"kind": "decision", "id": 58,
"summary": "Ban unwrap in library code; convert with AppError::from",
"status": "active", "anchors": ["src/ops/schemas/list.rs"]
},
{
"kind": "decision", "id": 61,
"summary": "Map rusqlite errors into AppError at the ops boundary",
"status": "active", "anchors": ["src/ops/db.rs"]
}
],
"member_count": 3,
"truncated": false
}
}From now on, engrams advise src/ops/new_handler.rs surfaces this schema above the constraint list with "matched_by": {"via": "scope_path", "value": "src/ops"} — even beforenew_handler.rs has any individual decision anchored to it.
Example: research
Research findings stored as custom data tend to go stale because nothing forces an agent to consult them. A schema turns the survey into a standing rule:
engrams schema refine survey-then-decide \
--trigger "evaluating a new dependency or settling an open design question" \
--rule "read the saved research findings first and cite the finding ID in the decision"Members: the custom-data entries holding the survey findings (each enriched with its key and full value — JSON stored as JSON), plus the decision that turned the survey into a roadmap. Now a prompt like“should we adopt bgk for clustering?” activates the schema through advise — the agent is told to ground the answer in finding IDs instead of improvising from training-data priors.
Example: planning
Planning drift happens when every session re-derives what to build next from a backlog of raw notes. The what-to-build-next schema packages the survey, the roadmap decision, and the session notes into one activation:
engrams schema refine what-to-build-next \
--trigger "planning a release or choosing what to build next" \
--rule "pick from the tiered version-by-version roadmap before inventing new scope"Running engrams prime --tags roadmap ranks this schema first with its rule inline, so planning sessions start from the committed sequence rather than the loudest recent note. Tagging the schema (or its members) with the tags your planning prompts use is what makes the match — anchors for paths, tags for topics.
The loop closes itself
You do not have to remember to look for schemas. Detection runs continuously in the background, and engrams session close [--lens <name>] (or preview-onlyengrams schema prompts [--lens <name>] [--limit <n>]) tells you two things at the exact moment a session ends:
- schema_prompts — up to three unexplained storylines drawn from recurring subject-tag threads and gate-passing detector candidates (of any label) that are not already covered by an active schema or pending proposal. Each prompt lists its
evidencein reading order (storynatural-sorts by first anchor path soch2precedesch10;timesorts chronologically), asks project-typequestionsfrom the active lens (built-ingeneral,fiction, orsoftware, or a workspace file at<root>/engrams/lenses/<name>.json), and includes a ready-to-fillpropose_command(engrams schema propose --thread <tag> --lens <name> --members ...or--from <sig-prefix> --lens <name> ...). Session close records each prompt's evidence inschema_prompt_noticesso a prompt stays quiet until a newly created note joins its storyline. - schema_value —
guided_retrievals,distinct_schemas, andschemas: [{"id", "name", "guided"}]naming each schema that guided retrieval during the session, most-used first. This is the payoff made visible: which schemas did the work, and how many times.
The same counter shows up per schema in engrams schema list andschema show as the guided field — so a schema that never fires is visible too, and worth refining with a broader --scope-paths / --scope-tags or retiring.
The six-step agent loop
- When
schema_promptsis non-empty, read each prompt's evidence and answer its questions. - Draft one claim, instruction, and scope, and run
schema propose. - Show the person the claim, the instruction, the scope, and the notes behind them in plain words, and ask whether to confirm, edit, or reject.
- Run
schema confirmorschema rejectwith the person's own words. - Raise
pending_proposalsfromprimethe same way at session start. - When a surfaced schema shapes your work, name it in your reply.
session close (or schema prompts) surfaces unexplained storylines with lens questions, schema propose writes the claim, instruction, and scope,schema confirm proposal:<id> seals it with human review, and advise /prime / query deliver the schema wherever its scope or members apply. Each session that follows the schema without re-reading the underlying memories is the compounding payoff.