Class: CognitiveWorkingMemory
Defined in: packages/agentos/src/memory/core/working/CognitiveWorkingMemory.ts:74
Cognitive working memory with Baddeley-inspired slot management.
Also implements IWorkingMemory for backward compatibility —
get/set/delete/clear/has/size/getAll delegate to the backing store,
while slot management is layered on top.
Implements
IWorkingMemory
Constructors
Constructor
new CognitiveWorkingMemory(
backing,config?):CognitiveWorkingMemory
Defined in: packages/agentos/src/memory/core/working/CognitiveWorkingMemory.ts:83
Parameters
backing
IWorkingMemory
config?
Partial<CognitiveWorkingMemoryConfig>
Returns
CognitiveWorkingMemory
Properties
id
readonlyid:string
Defined in: packages/agentos/src/memory/core/working/CognitiveWorkingMemory.ts:75
A unique identifier for this specific working memory instance. This ID may be correlated with a GMI instance or a user session.
Implementation of
IWorkingMemory.id
Methods
clear()
clear():
Promise<void>
Defined in: packages/agentos/src/memory/core/working/CognitiveWorkingMemory.ts:114
Async
Clears all data from the working memory, effectively resetting it to an empty state. This is often used when a session ends or a persona is switched, and session-specific adaptations should not persist.
Returns
Promise<void>
A promise that resolves when the memory has been cleared.
Throws
If clearing fails (e.g., storage errors).
Example
await workingMemory.clear(); // Session ended, wipe working memory.
Implementation of
IWorkingMemory.clear
close()
close():
Promise<void>
Defined in: packages/agentos/src/memory/core/working/CognitiveWorkingMemory.ts:127
Async
Closes any open resources associated with this working memory instance, such as database connections or file handles. This should be called when the GMI instance is being shut down to ensure graceful resource release.
Returns
Promise<void>
A promise that resolves when resources are released.
Throws
If closing fails.
Implementation of
IWorkingMemory.close
decayActivations()
decayActivations():
Promise<string[]>
Defined in: packages/agentos/src/memory/core/working/CognitiveWorkingMemory.ts:206
Apply per-turn activation decay to all slots. Slots that drop below minActivation become eviction candidates.
Returns
Promise<string[]>
delete()
delete(
key):Promise<void>
Defined in: packages/agentos/src/memory/core/working/CognitiveWorkingMemory.ts:106
Async
Removes a key-value pair from the working memory. If the key does not exist, the operation should complete without error.
Parameters
key
string
The key of the value to delete.
Returns
Promise<void>
A promise that resolves when the value has been deleted or if the key was not found.
Throws
If deletion fails for other reasons (e.g., storage errors).
Example
await workingMemory.delete('temporary_calculation_result');
Implementation of
IWorkingMemory.delete
focus()
focus(
traceId,initialActivation?):Promise<string>
Defined in: packages/agentos/src/memory/core/working/CognitiveWorkingMemory.ts:161
Focus attention on a trace, adding it to working memory. If at capacity, the lowest-activation slot is evicted first.
Parameters
traceId
string
initialActivation?
number = 0.8
Returns
Promise<string>
The slot ID assigned to this trace.
formatForPrompt()
formatForPrompt():
string
Defined in: packages/agentos/src/memory/core/working/CognitiveWorkingMemory.ts:235
Serialise current slots as a formatted string for prompt injection.
Returns
string
get()
get<
T>(key):Promise<T|undefined>
Defined in: packages/agentos/src/memory/core/working/CognitiveWorkingMemory.ts:102
Async
Retrieves a value from the working memory based on its key.
Type Parameters
T
T = any
The expected type of the retrieved value.
Parameters
key
string
The key of the value to retrieve.
Returns
Promise<T | undefined>
A promise that resolves with the retrieved value,
or undefined if the key is not found in the memory.
Throws
If retrieval fails for reasons other than the key not being found (e.g., deserialization issues).
Example
const currentMood = await workingMemory.get<string>('current_mood');
if (currentMood) {
console.log(`Current mood is: ${currentMood}`);
}
Implementation of
IWorkingMemory.get