withLongTermMemory

suspend fun <T> AIAgentContext.withLongTermMemory(action: suspend LongTermMemory.() -> T): T(source)

Executes the given action in the context of the LongTermMemory feature installed on this agent.

This is the primary way to access long-term memory storages from within strategy nodes. Inside the action block, you can use LongTermMemory.retrievalStorage and LongTermMemory.ingestionStorage to search and add memory records.

Example usage:

val myNode by node<String, Unit> {
withLongTermMemory {
ingestionStorage?.add(records, namespace = "my-namespace")
val results = retrievalStorage?.search(request, namespace = "my-namespace")
}
}

Return

the result of the action block.

Parameters

action

the block to execute with LongTermMemory as the receiver.

See also

Throws

if the LongTermMemory feature is not installed.