How to Give an AI Agent Long-Term Memory with Graphiti

October 7, 2026

Most AI agents have no memory past the current conversation. Stuff a summary into the prompt and it ages badly — the agent keeps citing a fact a user changed last week. Graphiti fixes this by storing facts in a temporal graph: each becomes invalid when it is superseded, and retrievable while it is still true.

This assumes you already have Graphiti installed and connected to a graph database. If not, start with the knowledge-graph setup guide — here we look at the agent integration.

Why is a vector store not enough for agent memory?

A vector store returns the most similar text regardless of when it was written. Ask “what plan is the customer on?” and it can return both the old plan and the new one, leaving the model to guess. Temporal graphs rank by recency and validity, so outdated facts are filtered out rather than mixed in.

How do you wire Graphiti into an agent loop?

  1. After each user turn, add the turn as an episode.
  2. Before answering, query the graph for relevant, currently-valid facts.
  3. Inject those facts into the model’s context as structured notes.
  4. Let the model answer; store the reply as the next episode.

The graph grows with the conversation and stays current without re-summarizing history.

How do you handle facts that change?

When a new episode contradicts an old edge, Graphiti invalidates the old one instead of deleting it. You can ask “what was the plan last quarter?” and still get the historical answer, while current queries see only the fresh value. This history is exactly what a summary-based memory loses.

How do you control cost and noise?

  • Don’t ingest everything — store decisions and state changes, not chit-chat.
  • Batch episodes where you can, since extraction costs tokens per episode.
  • Prune entities the agent never queries.
  • Use a smaller, cheaper model for extraction if your accuracy tolerates it.

How do you retrieve the right facts?

Use hybrid search: semantic similarity to find candidate entities, plus graph traversal to pull in their relationships, plus a time filter to keep only valid edges. Then cap the number of facts you inject — flooding the context with 50 facts hurts answer quality more than it helps.

What are the limitations?

You now run a graph database alongside your app, and extraction can misread ambiguous statements, planting wrong edges. The system is as good as the data you feed it. For a short-lived chat assistant, this is more machinery than the problem needs; for an agent that tracks a customer or project over months, it pays off.

Key Takeaways

  • Graphiti gives agents time-aware memory that filters out stale facts.
  • Add each turn as an episode; query valid facts before answering.
  • Superseded facts are invalidated, not deleted, keeping history queryable.
  • Ingest sparingly and cap injected facts to protect quality.
  • Overkill for short chats; valuable for long-lived agent state.

Last updated October 2026. More at Graphiti.