Interface: IWorkingMemory
Defined in: internal/working-memory/types.ts:24
The thread memory of the gateway, raw: what the model gets from the thread's history, and what it learns from an answer.
Implemented by WorkingMemory (two built-in strategies, EWorkingMemoryStrategy) and by a host class passed as
overrides.workingMemory to the AIGateway constructor. The gateway holds no history logic of its own: the
ContextAssembler calls load for every request, the background memory update calls saveContext after every
answer, the facade calls getState and reset for the UI.
Methods
getState()
getState(
args):Promise<IWorkingMemoryState>
Defined in: internal/working-memory/types.ts:115
getState -- what the memory has stored about one thread
About
The memory, as the user may see it.
Returns the stored summary, facts and the turn count they were written at; the empty state for a thread the memory never
wrote. Under SLIDING_WINDOW the state is whatever an earlier SUMMARY_BUFFER period left: the window ignores it, it is
not wiped.
- Never calls a model.
- Never writes.
Who needs it
AIGateway.getThreadMemory, for a "what do you remember" UI.
Pitfalls
An unknown thread, or one of another tenant, is a 404.
Parameters
args
tenantId
string
threadId
string
Returns
Promise<IWorkingMemoryState>
load()
load(
args):Promise<IWorkingMemoryLoad>
Defined in: internal/working-memory/types.ts:48
load -- the history part of one model request
About
Everything the model should know from this thread, sized for this call.
Returns the message window (the turns the model reads verbatim, the current user turn last) and the notes (the text
of the "About this conversation" part of the {memory} slot; empty when there is nothing). Which turns, how many
and whether there are notes is the implementation's business: the strategy, the profile's override, the budget.
- Never calls a model.
- Never writes.
Who needs it
ContextAssembler.build, once per request, after it rendered the system prompt, so budgetTokens is known.
Pitfalls
budgetTokens is what is left of the window after the system prompt and the output reserve; an implementation
that returns more is trimmed by the assembler, oldest message first, with a turns_trimmed warning.
Parameters
args
budgetTokens
number
Tokens left for the history after the system prompt and the output reserve.
model
profile
The call's profile; profile.workingMemory may override the gateway's strategy.
tenantId
string
threadId
string
Returns
Promise<IWorkingMemoryLoad>
reset()
reset(
args):Promise<void>
Defined in: internal/working-memory/types.ts:138
reset -- forgets what the memory stored about one thread
About
"Forget this conversation": the notes go, the turns stay.
Clears the stored summary and facts and marks the turns so far as seen, so the next saveContext does not bring them
back. The thread and its turns are untouched; the model still reads the window.
Who needs it
AIGateway.resetThreadMemory, for a "forget" action of the UI.
Pitfalls
An unknown thread, or one of another tenant, is a 404.
Parameters
args
tenantId
string
threadId
string
Returns
Promise<void>
saveContext()
saveContext(
args):Promise<void>
Defined in: internal/working-memory/types.ts:78
saveContext -- learns from one answered call
About
The answer is in; remember what must be remembered.
Called in the background after every answer. The new turns are already stored on the thread (ThreadStore); an
implementation reads them from there, or from request and result when the gateway has them (an answer a human
edited in a review has no model result). The built-in SUMMARY_BUFFER updates the summary + facts when
updateEveryTurns turns are due; SLIDING_WINDOW does nothing.
Who needs it
The gateway's background memory update, after ask and after every closed run.
Pitfalls
Runs on the gateway's background queue (whenIdle): it must not throw; it reports and returns.
Parameters
args
cheapModelId
string
Cheap model for helper calls, resolved by the gateway (the profile's or the platform default).
meta
For the usage guard and the trace; kind = MEMORY_WORKING.
profile
request?
The request the answer was produced for; absent when the gateway has none at hand.
result?
The model's answer; absent when a human wrote or edited it (a reviewed run).
tenantId
string
threadId
string
userId
string
Returns
Promise<void>