withMemory

suspend fun <T> AIAgentContextBase.withMemory(action: suspend AgentMemory.() -> T): T(source)

Extension function to perform memory operations within a AIAgentStageContext.

This provides a convenient way to use memory operations within agent nodes with a more concise syntax using the withMemory block.

Example usage:

val loadUserPreferences by node {
// Use memory operations in a block
stageContext.withMemory {
loadFactsToAgent(
concept = Concept("preferred-language", "User's preferred programming language"),
subjects = listOf(MemorySubjects.User)
)
}
}

Return

The result of the action

Parameters

action

The memory operations to perform