Skip to content

Graphorin API reference v0.15.1


Graphorin API reference / @graphorin/memory / / WorkingMemory

Class: WorkingMemory ​

Defined in: packages/memory/src/tiers/working-memory.ts:105

Stable

WorkingMemory - labeled, character-bounded blocks rendered into every system prompt. Operations:

  • define(spec): idempotently registers a block definition; the block's row is created in storage on the next write call so operators can change description between runs without triggering a write.
  • read(scope, label) / list(scope): surface the current block contents.
  • write(scope, label, value): full replace.
  • append(scope, label, content): append-with-newline.
  • replace(scope, label, oldUnique, newText): targeted replace with a uniqueness check.
  • compile(scope): render the active blocks for the context engine (used by Phase 10d).

Constructors ​

Constructor ​

ts
new WorkingMemory(args): WorkingMemory;

Defined in: packages/memory/src/tiers/working-memory.ts:110

Parameters ​

ParameterType
args{ store: MemoryStoreAdapter; tracer: Tracer; }
args.storeMemoryStoreAdapter
args.tracerTracer

Returns ​

WorkingMemory

Methods ​

append() ​

ts
append(
   scope, 
   label, 
content): Promise<Block>;

Defined in: packages/memory/src/tiers/working-memory.ts:167

Append content to a block (with a newline separator).

Parameters ​

ParameterType
scopeSessionScope
labelstring
contentstring

Returns ​

Promise&lt;Block&gt;


attach() ​

ts
attach(
   scope, 
   blockId, 
agentId): Promise<void>;

Defined in: packages/memory/src/tiers/working-memory.ts:251

Attach a working block to an additional agent. Backed by the adapter's shared.attach(...) join table so multi-agent crews can share the same block without duplicating storage.

Parameters ​

ParameterType
scopeSessionScope
blockIdstring
agentIdstring

Returns ​

Promise&lt;void&gt;


compile() ​

ts
compile(scope, agentId?): Promise<string>;

Defined in: packages/memory/src/tiers/working-memory.ts:294

Render a deterministic <memory_blocks> XML fragment for the supplied scope. The full layered system prompt (six layers) is produced by Phase 10d's ContextEngine; this method ships the minimum-viable rendering used by the smoke acceptance criteria.

The optional agentId argument is reserved for the per-agent filtering Phase 10d wires through. In Phase 10a the argument is accepted but ignored - the rendering is scope-wide.

Parameters ​

ParameterType
scopeSessionScope
agentId?string

Returns ​

Promise&lt;string&gt;


define() ​

ts
define(definition): BlockDefinition;

Defined in: packages/memory/src/tiers/working-memory.ts:117

Register a block definition. Returns the same definition object.

Parameters ​

ParameterType
definitionBlockDefinition

Returns ​

BlockDefinition


definitionFor() ​

ts
definitionFor(label): 
  | BlockDefinition
  | undefined;

Defined in: packages/memory/src/tiers/working-memory.ts:128

Lookup a definition by label.

Parameters ​

ParameterType
labelstring

Returns ​

| BlockDefinition | undefined


definitions() ​

ts
definitions(): readonly BlockDefinition[];

Defined in: packages/memory/src/tiers/working-memory.ts:123

Snapshot of every registered definition.

Returns ​

readonly BlockDefinition[]


detach() ​

ts
detach(
   scope, 
   blockId, 
agentId): Promise<void>;

Defined in: packages/memory/src/tiers/working-memory.ts:268

Detach a working block from an agent.

Parameters ​

ParameterType
scopeSessionScope
blockIdstring
agentIdstring

Returns ​

Promise&lt;void&gt;


forget() ​

ts
forget(
   scope, 
   label, 
reason?): Promise<void>;

Defined in: packages/memory/src/tiers/working-memory.ts:205

Soft-delete a block.

Parameters ​

ParameterType
scopeSessionScope
labelstring
reason?string

Returns ​

Promise&lt;void&gt;


list() ​

ts
list(scope): Promise<readonly Block[]>;

Defined in: packages/memory/src/tiers/working-memory.ts:133

List active (non-deleted) blocks for the supplied scope.

Parameters ​

ParameterType
scopeSessionScope

Returns ​

Promise&lt;readonly Block[]&gt;


purge() ​

ts
purge(scope, label): Promise<void>;

Defined in: packages/memory/src/tiers/working-memory.ts:227

Hard-delete a block (GDPR path). Unlike forget (soft tombstone), the stored value is gone. This is the erasure surface for USER-scoped blocks (e.g. the profile projection): the session-delete cascade never reaches rows without a session id, so user-level erasure must call this explicitly. Throws when the storage adapter does not implement the optional WorkingMemoryStoreExt.purge - a silent soft-delete fallback would misreport erasure.

Parameters ​

ParameterType
scopeSessionScope
labelstring

Returns ​

Promise&lt;void&gt;


read() ​

ts
read(scope, label): Promise<string | null>;

Defined in: packages/memory/src/tiers/working-memory.ts:142

Read a single block's value (or null when absent).

Parameters ​

ParameterType
scopeSessionScope
labelstring

Returns ​

Promise&lt;string | null&gt;


replace() ​

ts
replace(
   scope, 
   label, 
   oldUnique, 
newText): Promise<Block>;

Defined in: packages/memory/src/tiers/working-memory.ts:179

Replace the unique substring oldUnique inside the block's value with newText. Throws WorkingBlockReplaceMismatchError when the substring is missing or appears more than once.

Parameters ​

ParameterType
scopeSessionScope
labelstring
oldUniquestring
newTextstring

Returns ​

Promise&lt;Block&gt;


rethink() ​

ts
rethink(
   scope, 
   label, 
mutator): Promise<Block>;

Defined in: packages/memory/src/tiers/working-memory.ts:196

Run mutator(current) => next and persist the result.

Parameters ​

ParameterType
scopeSessionScope
labelstring
mutator(current) => string | Promise&lt;string&gt;

Returns ​

Promise&lt;Block&gt;


write() ​

ts
write(
   scope, 
   label, 
value): Promise<Block>;

Defined in: packages/memory/src/tiers/working-memory.ts:162

Replace a block's value entirely. Honours overflow policy.

Parameters ​

ParameterType
scopeSessionScope
labelstring
valuestring

Returns ​

Promise&lt;Block&gt;