Skip to main content
Swarms agents can persist their interaction history to disk through a per-agent MEMORY.md file. The flag is False by default: set persistent_memory=True 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 (PDFs, databases, doc stores), give the agent a retrieval tool instead — MEMORY.md is for the agent’s own history, not a document index. See External knowledge.

How it works

Memory is keyed by agent_name and lives under the workspace directory. When WORKSPACE_DIR is not set, it falls back to ./agent_workspace:
On construction, Swarms reads MEMORY.md and adds it to agent.short_memory as a single System message. Every conversation.add(...) then writes through to disk so nothing is lost on exit.

Basic example

Set agent_name and persistent_memory=True. The first construction creates MEMORY.md, and every turn after that is appended to it:

Resume across restarts

Re-instantiate an agent with the same agent_name and persistent_memory=True. The prior log is loaded into agent.short_memory as one System message, and new turns keep appending to the same file. Changing the name starts a fresh memory folder; id changes between runs and is not used as the key.
agent.run() does not currently send that System message to the model, so a resumed agent does not see its earlier sessions on its own. Until it does, put the log into system_prompt yourself. The system prompt is never written to MEMORY.md, so this does not make the log grow.

Inspect memory in code

The Conversation object is exposed as agent.short_memory:

Export and reload

Snapshot the conversation to JSON and reload it later:
Snapshots go to ./conversations/ under the current working directory, not to the workspace. The folder is created only when you save.

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