Optionalconfig: MemoryWriteManagerConfigNumber of notes persisted this run (written + superseded)
Reset all per-run state. Called at run start, mirroring ArtifactToolManager.Clear().
Execute a single memory write through the guard pipeline: type guard → within-run idempotency → per-run cap → scope clamp → near-dup guard (supersede-own / exact-restatement dedupe / fail-open) → persist provisional.
ProtectedfindOne in-memory vector check against injectable notes in the same scope, returning only ACTIONABLE hits:
Near-but-textually-different matches are deliberately dropped so the write proceeds as a new provisional note. A textual difference may be a correction — live testing showed "I love pie charts" followed in a later run by "never use pie charts, bar charts only" being absorbed into the STALE note (reinforcing it) and the correction silently lost. ADD-only on mismatch preserves corrections; true paraphrase duplicates are reconciled by the Memory Manager's LLM hardening dedupe (bounded by the per-run cap and TTL). The vector query itself survives because it (a) detects own-note supersede targets and (b) shortlists exact-restatement candidates without a table scan — exact equality filters AFTER the vector shortlist.
Fail-open by design: when the vector service is unavailable or errors, we proceed with the write rather than dropping the user's stated fact — a rare duplicate is recoverable (TTL + Memory Manager hardening dedup), a silently lost memory is not.
ProtectedloadLoad an existing note entity by ID. Overridable seam for tests.
ProtectedpersistPersist a new provisional note with full provenance stamping.
ProtectedqueryRaw vector-service lookup. Overridable seam for tests.
ProtectedsupersedeSupersede-own: the request near-duplicates a note written earlier in THIS run — update that provisional note's text in place (last-write-wins within a run: "I love blue charts!" then "actually, red charts!" yields one red-charts note, no stale row). Cross-run conflicts are NOT superseded — they defer to the Memory Manager.
ProtectedtouchThe request exactly restates a pre-existing note (from a prior run or the Memory Manager). Bump its access stats instead of inserting a duplicate.
Manages in-flight durable memory writes for a single agent run.
Follows the ArtifactToolManager pattern:
Clear()ed at run startThe framework (not the agent) enforces every guard: type restriction, scope clamping, near-duplicate handling, per-run caps, and provenance stamping. Notes land with
Status='Provisional'— immediately injectable, later hardened or pruned by the MemoryManagerAgent.Writes MUST be executed sequentially (the BaseAgent caller iterates with
for...of, notPromise.all): each persisted note is embedded and synced into the in-memory vector service byMJAIAgentNoteEntityServer.Save(), so write N must be visible to write N+1's near-dup check. This is a deliberate exception to the parallelize-by-default rule.