Trust & safety

Memory

Long-term memory lets agents recall relevant facts from past runs and store new outcomes. It's retrieval-backed and pluggable — from a dependency-free keyword store to any vector database.

SemanticMemory

memory.py
from antraft import Antraft, SemanticMemory
 
mem = SemanticMemory(path="mem.jsonl") # persists across runs (optional)
 
runtime = Antraft.agent(model, tools, task="...", memory=mem).build()
await runtime.run()
Note
At the start of a run, relevant memories are recalled into the agent's context. On finish, the task and answer are stored back — so the next run benefits automatically.

Manual use

memory.py
mem.add("The deploy key lives in vault path secret/deploy.")
mem.recall("where is the deploy key") # -> formatted relevant entries
mem.search("deploy key", k=4) # -> raw docs with scores

Bring your own store

The default InMemoryRetriever uses TF-IDF-style keyword scoring. Swap in any object with add() and search() — e.g. a vector DB — without changing agent code.

memory.py
mem = SemanticMemory(retriever=MyVectorStore())

Memory vs checkpoints

Memory persists knowledge between runs. Checkpoints persist a single run's state for crash recovery — see Reliability.