Skip to main content
Swarms agents persist their interaction history to disk through a per-agent MEMORY.md file. Set persistent_memory=True (the default) and reuse the same agent_name across process starts to resume the same memory.

When to use it

  • The agent runs in separate processes (CLI, cron, restarts) and needs to resume prior context.
  • You want a human-readable transcript of what the agent has seen and produced.
  • You need to inspect, search, or export the agent’s interaction log.
For external knowledge retrieval (PDFs, databases, doc stores), use long_term_memory (RAG) instead — MEMORY.md is for the agent’s own history, not a document index.

How it works

Memory is keyed by agent_name and lives under the workspace directory:
On construction, Swarms reads MEMORY.md and injects it into conversation_history as a single System message. Every conversation.add(...) then write-throughs to disk so nothing is lost on exit.

Basic example

Set agent_name and persistent_memory=True (the default). On the first run Swarms creates MEMORY.md. On subsequent runs the prior conversation is preloaded as a system preamble and the agent picks up where it left off:

Resume across restarts

Re-instantiate an agent with the same agent_name and persistent_memory=True. The prior transcript is preloaded as a system message before the new task runs:
Changing the name starts a fresh memory folder; id changes between runs and is not used as the key.

Inspect memory in code

The Conversation object is exposed as agent.short_memory:

Export and reload

Snapshot memory to JSON or YAML and reload it later:

Disable disk-backed memory

For privacy-sensitive or one-off agents, set persistent_memory=False. In-process conversation_history still works for the duration of the run, but nothing is written to disk and nothing is preloaded next time:

Tips

  • Use stable, descriptive agent_name values for any agent that should remember prior work.
  • Don’t reuse the same agent_name across unrelated tasks — memory will leak between runs.
  • For long-running agents, also enable context compression so memory stays within the model’s context window.

See also