Home › Guides › AI Agents
AI Agents · How-to

How to Give Your AI Agent Memory

Agents are stateless — they only remember what you resend. Add memory with in-context history plus a JSON file for durable facts.

You'll need: A working agent loop.

Steps

  1. Keep the full message history in-context for the current task (bounded by the context window).
  2. For durable facts, add a save_memory tool that writes to a JSON file on disk.
  3. Load relevant memories back into context at the start of each run.
  4. For large document sets, move to a vector store (RAG) instead of stuffing everything in.
  5. Log every iteration so you can see what the agent actually remembered and did.
Watch outDon't let memory grow unbounded — summarize or retrieve selectively, or you'll blow the context window on long tasks.

Go deeper: Deploy Your First AI Agent

The AI guide covers the memory ladder: in-context, external file, vector store, and KV — and when to use each.

Get the guide