An agent's memory decides which past messages enter the next context window. Three policies ship with the package; all are drop-in:
Usage
memory_buffer(keep = 40L)
memory_summary(threshold_chars = 12000L, keep_last = 10L, config = NULL)
memory_recall(embed_config, keep_recent = 6L, k = 4L)Arguments
- keep, keep_last, keep_recent, k, threshold_chars
Policy sizes; see above.
- config
Optional
LLMR::llm_config()used only for compaction summaries; NULL (default) summarizes with the agent's own model.- embed_config
An LLMR embedding config (e.g.
llm_config("gemini", "gemini-embedding-001", embedding = TRUE)).
Details
memory_buffer(keep): the lastkeepmessages, verbatim. Simple, predictable, and right for most short-lived agents.memory_summary(threshold_chars, keep_last, config): unbounded conversations. When stored text exceeds the threshold, the agent automatically condenses everything but the most recent messages into one summary note before its next request, so context stays small without forgetting decisions. By default the agent's own model writes the summary; passconfigto bill compaction to a cheaper model instead.memory_recall(embed_config, keep_recent, k): long-horizon recall. Older messages are embedded (via LLMR); at each turn thekmost similar to the current input are injected alongside the recent tail.
Examples
m <- memory_buffer(keep = 10)
m$add("user", "hello")$add("assistant", "hi")
length(m$get())
if (FALSE) { # \dontrun{
cfg <- LLMR::llm_config("groq", "openai/gpt-oss-20b")
cheap <- LLMR::llm_config("groq", "llama-3.1-8b-instant")
# an agent that summarizes its own past with the cheap model
scribe <- agent("Scribe", cfg,
memory = memory_summary(threshold_chars = 8000,
config = cheap))
# an agent that recalls relevant old exchanges by embedding similarity
emb <- LLMR::llm_config("gemini", "gemini-embedding-001", embedding = TRUE)
sage <- agent("Sage", cfg, memory = memory_recall(emb, k = 4))
} # }