Session-scoped agent memory with three storage levels: session (shared conversation history), user (per-user persistent data), and KB (shared domain knowledge).
Functions
candidate-edge
fn (from: Str, relation: Str, to: Str, provenance: Vec<MemoryProvenance>, opts: Map?): MemoryEdge
Build a graph edge candidate with provenance and confidence.
Example
prov [::ai::memory/MemoryProvenance({source: "slack", message-id: "m1"})]
edge ::ai::memory/candidate-edge("person:ada", "reported", "topic:refunds", prov, {weight: 2.0})
edge.id // "person:ada:reported:topic:refunds"
edge.weight // 2.0
candidate-node
fn (kind: Str, label: Str, provenance: Vec<MemoryProvenance>, opts: Map?): MemoryNode
Build a graph node candidate with provenance and confidence.
Example
prov [::ai::memory/MemoryProvenance({source: "slack", message-id: "m1"})]
node ::ai::memory/candidate-node("topic", "Late Refunds", prov, null)
node.id // "topic:late-refunds"
node.confidence // 0.7
capsule-from-window
fn (id: Str, summary: Str, entries: Vec, opts: Map?): MemoryCapsule
Build a MemoryCapsule from a summary and source store entries.
Example
entry {key: "1767225600:m1", score: 0.92, value: {
content: "Order 42 never arrived.",
sender-id: "u1",
source: "slack",
timestamp: 1767225600,
metadata: {message_id: "m1"}
}}
capsule ::ai::memory/capsule-from-window("c1", "Ada reported a missing order.", [entry], null)
capsule.source-ids // ["m1"]
capsule.start-ts // 1767225600
capsule-key
fn (id: Str): Str
Return the KB key used for a memory capsule.
Example
::ai::memory/capsule-key("2026-11-09") // "capsule:2026-11-09"
citation-from-result
fn (result: Map): Citation
Build a normalized Citation from a search/list result.
Example
citation ::ai::memory/citation-from-result({
key: "graph:node:topic:refunds",
score: 0.9,
value: {id: "topic:refunds", label: "Refunds", content: "How refunds work."}
})
citation.label // "Refunds"
citation.excerpt // "How refunds work."
create-memory
fn (agent-name: Str, session: ::ai::session/Session, identity: ::ai::session/Identity): AgentMemory
Build an AgentMemory with all three scoped stores.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
mem.agent-name
create-memory-with-options
fn (agent-name: Str, session: ::ai::session/Session, identity: ::ai::session/Identity, opts: MemoryOptions?): AgentMemory
Build an AgentMemory, optionally overriding session/KB embedding configuration.
Example
::mem ::ai::memory
opts ::mem/MemoryOptions({embedding: ::hot::store/EmbeddingOptions.Off})
mem ::mem/create-memory-with-options(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"}),
opts
)
mem.session-store
delete-entries
fn (store: ::hot::store/Map, entries: Vec): Int
Delete store entries and return the count deleted.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
stale ::hot::store/filter(mem.session-store, (k, v) { eq(v.source, "slack") })
::mem/delete-entries(mem.session-store, stale)
entry-record
fn (entry: Map, kind: Str): MemoryRecord
Convert a store entry to a stable MemoryRecord export shape.
Example
entry {key: "1767225600:m1", score: 0.92, value: {
content: "Order 42 never arrived.",
sender-id: "u1",
source: "slack",
timestamp: 1767225600,
metadata: {message_id: "m1"}
}}
record ::ai::memory/entry-record(entry, "session")
record.id // "1767225600:m1"
record.content // "Order 42 never arrived."
export-memory
fn (mem: AgentMemory): MemoryExport
fn (mem: AgentMemory, t: Thread?): MemoryExport
Export session, user, and KB records for this memory scope.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
bundle ::mem/export-memory(mem)
length(bundle.session)
bundle.metadata.exported-at
extract-graph-candidates
fn (structured: Map, provenance: Vec<MemoryProvenance>): Map
Convert structured extraction output into graph node/edge candidates.
Expected shape: {nodes: [{kind,label,...}], edges: [{from,relation,to,...}]}.
Example
prov [::ai::memory/MemoryProvenance({source: "slack", message-id: "m1"})]
found ::ai::memory/extract-graph-candidates({
nodes: [{kind: "person", label: "Ada"}],
edges: [{from: "person:ada", relation: "reported", to: "topic:refunds"}]
}, prov)
map(found.nodes, %.id) // ["person:ada"]
map(found.edges, %.relation) // ["reported"]
forget-by-source-id
fn (mem: AgentMemory, source-id: Str): Int
Delete session memory entries with matching key, metadata.source_id,
or metadata.message_id.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
::mem/forget-by-source-id(mem, "m1")
forget-kb-key
fn (mem: AgentMemory, key: Str): Bool
Delete one key from the shared KB.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
::mem/forget-kb-key(mem, "refund-policy")
forget-session
fn (mem: AgentMemory): Bool
Clear all entries in session memory.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
::mem/forget-session(mem)
forget-session-range
fn (mem: AgentMemory, start-ts: Int, end-ts: Int): Int
Delete session memory entries whose timestamp is within the inclusive
range.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
::mem/forget-session-range(mem, 1767225600, 1767312000)
forget-session-where
fn (mem: AgentMemory, predicate: Fn): Int
Delete session memory entries matching a predicate (key, value) -> Bool.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
::mem/forget-session-where(mem, (k, v) { eq(v.sender-id, "u1") })
forget-user-key
fn (mem: AgentMemory, key: Str): Bool
Delete one key from user memory.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
::mem/forget-user-key(mem, "timezone")
get-capsule
fn (mem: AgentMemory, id: Str): Any
Load a stored MemoryCapsule by id.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
::mem/get-capsule(mem, "c1").summary
get-user-data
fn (mem: AgentMemory, key: Str): Any
Read a value from the user's persistent store.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
::mem/get-user-data(mem, "timezone")
graph-edge-key
fn (id: Str): Str
Return the KB key used for a graph edge.
Example
::ai::memory/graph-edge-key("e1") // "graph:edge:e1"
graph-expand
fn (mem: AgentMemory, seed-node-ids: Vec): Map
Expand seed node ids into neighboring graph edges and citations.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
graph ::mem/graph-expand(mem, ["topic:refunds"])
map(graph.citations, %.excerpt)
graph-node-key
fn (id: Str): Str
Return the KB key used for a graph node.
Example
::ai::memory/graph-node-key("topic:refunds") // "graph:node:topic:refunds"
hybrid-recall
fn (mem: AgentMemory, query: Str, opts: Map?): Map
Hybrid retrieval: vector recall over raw/capsule/graph text plus graph expansion from explicit seed node ids.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
result ::mem/hybrid-recall(mem, "refund delays", {limit: 5, seed-node-ids: ["topic:refunds"]})
length(result.vector)
map(result.citations, %.label)
learn
fn (mem: AgentMemory, key: Str, content: Map): Any
Add an entry to the shared knowledge base. Auto-embedded for search.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
::mem/learn(mem, "refund-policy", {content: "Refunds take 5 business days."})
list-capsules
fn (mem: AgentMemory): Vec
List all memory capsule KB entries.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
map(::mem/list-capsules(mem), %.value.summary)
list-edges
fn (mem: AgentMemory): Vec
List all graph-RAG edges in this memory scope.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
map(::mem/list-edges(mem), %.value.relation)
list-kb-records
fn (mem: AgentMemory): Vec<MemoryRecord>
Export KB entries as MemoryRecord values.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
map(::mem/list-kb-records(mem), %.content)
list-nodes
fn (mem: AgentMemory): Vec
List all graph-RAG nodes in this memory scope.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
map(::mem/list-nodes(mem), %.value.label)
list-session-records
fn (mem: AgentMemory): Vec<MemoryRecord>
Export session memory entries as MemoryRecord values.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
map(::mem/list-session-records(mem), %.content)
list-user-records
fn (mem: AgentMemory): Vec<MemoryRecord>
Export user-profile entries as MemoryRecord values.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
map(::mem/list-user-records(mem), %.id)
memory-provenance
fn (entry: Map, kind: Str): MemoryProvenance
Build provenance for a store entry returned by ::hot::store/list,
filter, or search.
Example
entry {key: "1767225600:m1", score: 0.92, value: {
content: "Order 42 never arrived.",
sender-id: "u1",
source: "slack",
timestamp: 1767225600,
metadata: {message_id: "m1"}
}}
prov ::ai::memory/memory-provenance(entry, "session")
prov.message-id // "m1"
prov.source // "slack"
prov.score // 0.92
neighbor-edges
fn (mem: AgentMemory, node-id: Str): Vec
Find graph edges touching a node id.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
map(::mem/neighbor-edges(mem, "topic:refunds"), %.value.content)
recall
fn (mem: AgentMemory, query: Str, opts: Map?): Vec
Semantic search over session memory. Options: limit (default 10), min-score (default 0.5).
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
hits ::mem/recall(mem, "missing order", {limit: 5, min-score: 0.7})
map(hits, %.value.content)
recall-with-capsules
fn (mem: AgentMemory, query: Str, opts: Map?): Map
Retrieve raw session memory plus compacted capsules for a query.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
result ::mem/recall-with-capsules(mem, "missing order", {limit: 5})
length(result.raw)
map(result.capsules, %.value.summary)
recent
fn (mem: AgentMemory, opts: Map?): Vec
Retrieve recent messages from session memory. Options: hours (default 24), limit (default 100).
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
entries ::mem/recent(mem, {hours: 6, limit: 20})
map(entries, %.value.content)
remember
fn (mem: AgentMemory, message: ::ai::message/Message): Any
Store a Message in session memory. Auto-generates a time-based key.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
::mem/remember(mem, ::ai::message/Message({
id: "m1",
content: "Order 42 never arrived.",
sender: ::ai::session/Identity({id: "u1", name: "Ada"}),
session: ::ai::session/Session({id: "slack:C123"}),
timestamp: 1767225600,
source: "slack"
}))
search-kb
fn (mem: AgentMemory, query: Str, opts: Map?): Vec
Semantic search over the shared knowledge base. Options: limit (default 5).
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
hits ::mem/search-kb(mem, "refunds", {limit: 3})
map(hits, %.value.content)
set-user-data
fn (mem: AgentMemory, key: Str, value: Any): Any
Write a value to the user's persistent store.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
::mem/set-user-data(mem, "timezone", "Europe/Paris")
store-capsule
fn (mem: AgentMemory, capsule: MemoryCapsule): Any
Persist a MemoryCapsule in the KB store with provenance and embedding-friendly content.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
::mem/store-capsule(mem, ::mem/MemoryCapsule({
id: "c1",
summary: "Ada reported a missing order.",
source-ids: ["m1"]
}))
store-edge
fn (mem: AgentMemory, edge: MemoryEdge): Any
Persist a graph-RAG edge in the KB store.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
::mem/store-edge(mem, ::mem/candidate-edge("person:ada", "reported", "topic:refunds", [], null))
store-graph-candidates
fn (mem: AgentMemory, candidates: Map): Map
Persist graph node and edge candidates into memory stores.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
::mem/store-graph-candidates(mem, ::mem/extract-graph-candidates({
nodes: [{kind: "person", label: "Ada"}],
edges: []
}, []))
store-node
fn (mem: AgentMemory, node: MemoryNode): Any
Persist a graph-RAG node in the KB store.
Example
::mem ::ai::memory
mem ::mem/create-memory(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"})
)
::mem/store-node(mem, ::mem/candidate-node("topic", "Refunds", [], null))
thread
fn (agent-name: Str, session: ::ai::session/Session, identity: ::ai::session/Identity, opts: Map?): Thread
Create or get a per-(session, user) thread store for multi-turn
interactions. Options: max-turns (default 20).
The thread is scoped to (session, identity) so the same user in a
different session has an independent thread. Pass the same
session you used to build AgentMemory so memory and thread
stay aligned.
Example
::mem ::ai::memory
t ::mem/thread(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"}),
{max-turns: 10}
)
t.turn-limit
thread-add
fn (t: Thread, role: ::ai::message/Role, content: Str): Any
Append a message to a conversation thread.
Example
::mem ::ai::memory
t ::mem/thread(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"}),
{max-turns: 10}
)
::mem/thread-add(t, ::ai::message/Role.User, "Where is order 42?")
::mem/thread-add(t, ::ai::message/Role.Assistant, "It shipped on Monday.")
thread-clear
fn (t: Thread): Bool
Reset a conversation thread.
Example
::mem ::ai::memory
t ::mem/thread(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"}),
{max-turns: 10}
)
::mem/thread-clear(t)
thread-history
fn (t: Thread, opts: Map?): Vec
Get the recent thread history as ChatMessages. Options: limit (default all).
Example
::mem ::ai::memory
t ::mem/thread(
"support-bot",
::ai::session/Session({id: "slack:C123"}),
::ai::session/Identity({id: "u1", name: "Ada"}),
{max-turns: 10}
)
// The last four messages, oldest first
history ::mem/thread-history(t, {limit: 4})
::ai::message/format-chat-messages(history)
Types
AgentMemory
AgentMemory type {
agent-name: Str,
session-store: ::hot::store/Map,
user-store: ::hot::store/Map,
kb-store: ::hot::store/Map
}
Bundles three scoped stores for an agent + session + identity combination.
Citation
Citation type {
id: Str,
label: Str?,
excerpt: Str?,
score: Dec?,
provenance: MemoryProvenance?
}
Normalized citation returned by retrieval and graph expansion.
MemoryCapsule
MemoryCapsule type {
id: Str,
summary: Str,
start-ts: Int?,
end-ts: Int?,
source-ids: Vec<Str>,
facts: Vec<MemoryFact>?,
decisions: Vec<MemoryDecision>?,
tasks: Vec<MemoryTask>?,
open-questions: Vec<Str>?,
provenance: Vec<MemoryProvenance>?,
metadata: Map?
}
Durable compacted summary of a source memory window.
MemoryDecision
MemoryDecision type {
id: Str,
decision: Str,
owner: Str?,
rationale: Str?,
decided-at: Int?,
confidence: Dec?,
provenance: Vec<MemoryProvenance>?,
metadata: Map?
}
Structured decision extracted from team or personal memory.
MemoryEdge
MemoryEdge type {
id: Str,
from: Str,
to: Str,
relation: Str,
weight: Dec?,
confidence: Dec?,
provenance: Vec<MemoryProvenance>?,
metadata: Map?
}
Graph-RAG edge persisted in a memory graph.
MemoryExport
MemoryExport type {
agent-name: Str,
session: Vec<MemoryRecord>,
user: Vec<MemoryRecord>,
kb: Vec<MemoryRecord>,
thread: Vec?,
metadata: Map?
}
Portable export bundle for an AgentMemory scope.
MemoryFact
MemoryFact type {
id: Str,
subject: Str,
predicate: Str,
object: Str,
confidence: Dec?,
provenance: Vec<MemoryProvenance>?,
metadata: Map?
}
Structured long-term fact extracted from raw memory or a capsule.
MemoryNode
MemoryNode type {
id: Str,
kind: Str,
label: Str,
summary: Str?,
confidence: Dec?,
provenance: Vec<MemoryProvenance>?,
metadata: Map?
}
Graph-RAG node persisted in a memory graph.
MemoryOptions
MemoryOptions type {
embedding: ::hot::store/::hot::store/EmbeddingOptions?,
session-embedding: ::hot::store/::hot::store/EmbeddingOptions?,
kb-embedding: ::hot::store/::hot::store/EmbeddingOptions?
}
Optional store configuration for create-memory-with-options.
embedding is the default for session and KB memory stores.
session-embedding and kb-embedding override that default for
their specific stores. Pass ::hot::store/EmbeddingOptions.Default for
system defaults, ::hot::store/EmbeddingOptions.Off to disable, or
::hot::store/Embedding({...}) for Hot-level providers.
MemoryProvenance
MemoryProvenance type {
source: Str?,
source-id: Str?,
session-id: Str?,
user-id: Str?,
message-id: Str?,
key: Str?,
timestamp: Int?,
score: Dec?,
metadata: Map?
}
Evidence pointer for remembered, compacted, or graph-extracted memory.
MemoryRecord
MemoryRecord type {
id: Str,
kind: Str,
content: Str?,
timestamp: Int?,
metadata: Map?,
provenance: MemoryProvenance?
}
Stable export shape for one memory store entry.
MemoryTask
MemoryTask type {
id: Str,
title: Str,
owner: Str?,
due-at: Int?,
status: Str?,
confidence: Dec?,
provenance: Vec<MemoryProvenance>?,
metadata: Map?
}
Structured task or commitment extracted from memory.
Thread
Thread type {
store: ::hot::store/Map,
turn-limit: Int
}
A per-user conversation thread for multi-turn interactions.