Writes the agent's name, persona, config, memory contents, budget,
guardrails, trace, and accounting to an RDS file. Tools are functions and
are not serialized; re-attach them at load time via
load_agent(tools = ...). Guardrails are serialized (their check functions
travel through RDS) and restored automatically. The accounting includes the
count of calls whose usage was not reported (n_unknown_usage), so a
reloaded agent's budget() warnings stay accurate.
Arguments
- x
An Agent.
- path
File path (
.rds).
Details
A config carrying a literal API key (one passed as a string rather than the usual environment-variable reference) is refused: saving it would write the key to disk. Rebuild the config from an environment variable.
Examples
cfg <- LLMR::llm_config("groq", "openai/gpt-oss-20b")
a <- agent("Ada", cfg, persona = "Terse.", quiet = TRUE)
a$memory$add("user", "Remember this: the project deadline is March 3.")
path <- tempfile(fileext = ".rds")
save_agent(a, path)
ada <- load_agent(path)
ada$transcript() # the memory came along
unlink(path)
if (FALSE) { # \dontrun{
# a later session, any machine with GROQ_API_KEY set:
ada$chat("When is the deadline?")
} # }