HazelJS LogoHazelJS
HazelJS Blog

Governed Learning Memory: Why Agents Need Preferences They Can Trust

Author
HazelJS Team
11/15/2026
General
Governed Learning Memory: Why Agents Need Preferences They Can Trust
← Back to Blog

Why continuity without governance is a liability, how learnFromTurn closes the extract → classify → accept → context loop, and why this ships in HazelJS 2.0.18.

Agents that “remember” are easy to demo and hard to ship. Paste conversation history into the prompt and the model looks personalised — until a poisoned tool output becomes policy, a secret lands in durable storage, or last week’s preference silently overwrites what the user explicitly said.

HazelJS already had the storage shape for user memory (@hazeljs/​memory) and a planner to inject it (@hazeljs/​context). What was missing was a governed learning loop: extract → classify → capture → accept only what should influence the next turn.

That loop — GovernedMemoryService.learnFromTurn, a Prisma-backed store, and a context contributor — ships in HazelJS 2.0.18, completing the governance story we started in 2.0.14.


Packages & Links


Why this was needed

1. Continuity without governance is a liability

Teams ask for the same product behaviour: “remember that I prefer email,” “keep answers short,” “I’m in the CET timezone.” The naive implementation is:

  1. Append every utterance to a buffer
  2. Or ask the model to invent “memories” and write them back unchecked
  3. Or scrape long sentences from the assistant reply and call them facts

All three fail in production:

Failure modeWhat goes wrong
Unfiltered writeTool output or jailbreak text becomes durable preference
Confidence inflationRepeating the same source raises trust without new evidence
Tenant bleedOrg A’s prefs surface in Org B’s retrieve
Explicit overwriteAn inferred “pattern” replaces what the user stated
No forgetGDPR / “stop remembering that” has nowhere to land

Session chat history is not the same as actor-scoped, reviewable, forgettable preference memory. We needed both.

2. Storage existed; learning did not

@hazeljs/​memory already offered categories (preference, behavioral, episodic, …), explicit-vs-inferred sources, and pluggable backends. @hazeljs/​context could assemble memory into the LLM prompt. Agents and RAG could share a MemoryManager.

What apps still had to invent:

  • When to extract a preference from free text
  • Whether to persist, quarantine, or discard it
  • How to accept high-trust user statements automatically without accepting procedures from tools
  • How to inject only accepted rows on the next turn

GovernedMemoryService in 2.0.14 gave capture / accept / forget — but you still had to call capture() with ready-made content. The empty extract / consolidate hook slots were the tell: the lifecycle was designed for learning; the turn loop was not wired yet.

3. Context layers are incomplete without trusted Memory

RAG vs CAG vs KAG argued for four layers. Memory is the continuity layer — but continuity that is wrong is worse than none. A refund desk that “remembers” a fake admin procedure is not personalised; it is compromised.

Governed learning closes that gap: Memory contributes to @hazeljs/​context only after classification and accept.


What we built

The full loop

User turn + optional assistant reply
        │
        ▼
  extract hooks (privacy gate)
        │
        ▼
  ObservationExtractor  (RuleBased by default; pluggable)
        │
        ▼
  consolidate hooks (dedupe /​ transform)
        │
        ▼
  classify  →  persist | review | quarantine | discard
        │
        ▼
  capture  →  auto-accept high-trust user prefs/​facts
        │
        ▼
  next turn: ContextService + createGovernedMemoryContributor
             retrieves accepted rows only

This is application-level learning — durable structured memory with governance — not foundation-model fine-tuning.

Classification policy

ActionMeaning
persistAuto-accept user preferences / facts (high trust)
reviewKeep as candidate until accept
quarantineStore but never retrieve into prompts
discardSkip persistence

Built-in rules mirror @hazeljs/​decision classifyMemoryCandidate. Inject a Decision Plane classifier when you want one policy engine across memory and other closed-set judgments.

Durable store

InMemoryGovernedMemoryStore remains the zero-infra default. createPrismaGovernedMemoryStore now ships against governed_memory_records (schema + migration already existed). MemoryService / memory_items stay untouched — the two tables never query each other.

Context injection

createGovernedMemoryContributor never substitutes tenantId for userId. Retrieve ranks by relevance; only accepted rows reach the assembler.


Benefits

For product teams

  • Preferences stick across sessions without DIY extraction scripts
  • HITL-friendly: low-trust / procedural drafts stay candidates
  • Clear UX hook: emit when memories are accepted (e.g. “remembered: prefers email”)

For security & compliance

  • Secrets and privilege-escalation language quarantine by default
  • Tool-sourced procedures cannot become executable memory without review
  • forget tombstones content; audit keeps action ids
  • Tenant and scope filters apply before ranking

For Agent OS

  • Same governance vocabulary as Decision Plane and Gatekeeper: classify → act
  • Memory becomes a first-class context substrate instead of prompt stuffing
  • Completes the 2.0.14 roadmap item that listed “Prisma governed memory store” as not shipped

For framework users

const learned = await memory.learnFromTurn({
  auth,
  tenantId: 'merchant-123',
  subjectId: 'customer-42',
  userText: 'I prefer email for refund updates.',
  assistantText: 'Got it.',
  sessionId: 'sess-1',
});

/​/​ Next turn — only accepted prefs enter the prompt
const assembled = await context.assemble({
  query: 'How should we contact you?',
  tenantId: 'merchant-123',
  userId: 'customer-42',
});

Why this ships in 2.0.18

Closing an open governance slice

In 2.0.14 we shipped Decision Plane, Governed Runtime, and the lifecycle for governed memory — with an honest roadmap line: Prisma adapter not yet available; capture was manual.

Leaving that half-finished creates the wrong incentive: teams either skip governed memory or reinvent extractors outside the package. 2.0.18 is the right place to finish the loop while APIs are still additive and opt-in.

Demand from real Agent OS apps

Meeting teammates, support desks, and ops agents all hit the same question after the first demo: “Will it remember my preferences next time — safely?” Wiring learnFromTurn into the framework means every consumer (including apps like Hazel Agent) gets one tested path instead of per-repo heuristics.

Fits the release narrative

Recent releases stacked governance primitives:

Release themePrimitive
Call contract + governance (2.0.14)Decisions, GovernedRuntime, memory lifecycle
Autonomous Runtime (2.0.15)Observe → decide → approve → execute for services
2.0.18Governed learning — extract → classify → accept → context

Learning without governance would fight that narrative. Governance without learning left Memory as storage-only. Together they match how Agent OS is supposed to feel: durable, scoped, and reviewable.

Still deliberately scoped

We are not shipping in this pass:

  • Online fine-tuning or weight updates
  • Automatic behavioural graph mining beyond preference/fact heuristics
  • Merging memory review into Gatekeeper HITL UI (candidates sit in store; accept APIs exist)

That restraint is intentional. A solid loop beats an unbounded “AI that learns everything.”


How to try it

In-process:

npm install @hazeljs/​memory @hazeljs/​context
# optional classifier:
npm install @hazeljs/​decision

Docs: Governed learning memory · Context — governed contributor

Offline lab:

# from hazeljs-meridian-ops/​
npm run example:governed-memory

Takeaway

Personalisation that cannot be quarantined, corrected, or forgotten is not a feature — it is risk with a friendly UX.

Governed learning memory gives HazelJS agents a way to earn continuity: extract from the turn, classify under policy, accept only what belongs in the next prompt, and forget on request. That is why we built it — and why it belongs in 2.0.18 as the missing piece of the Agent OS governance slice.