Skip to content

Graphorin API reference v0.1.0


Graphorin API reference / @graphorin/memory / / WorkingMemory

Class: WorkingMemory

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

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).

Stable

Constructors

Constructor

ts
new WorkingMemory(args): WorkingMemory;

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

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:159

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:214

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:257

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:114

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:125

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:120

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:231

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:197

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:130

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

Parameters

ParameterType
scopeSessionScope

Returns

Promise&lt;readonly Block[]&gt;


read()

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

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

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:171

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:188

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:154

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

Parameters

ParameterType
scopeSessionScope
labelstring
valuestring

Returns

Promise&lt;Block&gt;