Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions pages/ai-ecosystem.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ This section covers:
ranking and prompt assembly as one Cypher query, and [Agentic
GraphRAG](/ai-ecosystem/graph-rag/agentic-graphrag) lets an agent choose the
retrieval pipeline for each question.
- [AI memory](/ai-ecosystem/ai-memory): Store semantic, episodic and procedural
memory (what a system knows, what it did and what it knows how to do) as
one graph that any AI system can query across sessions.
- [AI memory](/ai-ecosystem/ai-memory): Give coding agents a long-term memory
with Context Graph, which records their sessions in Memgraph and serves them
back to every connected agent in later sessions.
- [Agentic AI](/ai-ecosystem/agentic-ai): Store an agent's states and actions
as a reasoning graph, so the agent plans by traversing scored paths instead
of by prompting, and every decision leaves a trace you can inspect.
Expand Down Expand Up @@ -78,9 +78,8 @@ an API key.
</Tabs>

- [AI memory](/ai-ecosystem/ai-memory): Sets up Context Graph, which records
your coding agents' sessions in Memgraph as semantic, episodic and
procedural memory. It asks before it changes anything. You need Docker. On
Windows, the command prints the setup command to run in WSL or Git Bash.
your coding agents' sessions in Memgraph and serves them back as memory. It
asks before it changes anything. You need Docker.

<Tabs items={['Linux/macOS', 'Windows']}>
<Tabs.Tab>
Expand Down
202 changes: 109 additions & 93 deletions pages/ai-ecosystem/ai-memory.mdx
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
---
title: AI memory
description: Store what an AI system knows, did and knows how to do as one graph in Memgraph, and set it up for your coding agents with one command.
description: Give coding agents and custom agents a long-term memory in Memgraph with Context Graph, which records their sessions and serves them back later.
---
Comment thread
katarinasupe marked this conversation as resolved.

import { Tabs } from 'nextra/components'

# AI memory

AI memory lets an AI system remember across sessions. In Memgraph, memory is a
graph of entities and typed relationships, so recall follows the connections
between what the system knows, what it did and what it knows how to do, not
only what sounds similar to the question.
AI memory lets an AI agent use what happened in earlier sessions: what you
decided, what it did and what it learned about your work.

## How Memgraph stores memory
Context Graph is Memgraph's AI memory. It records the sessions of your coding
agents, such as Claude Code and Codex, as a graph in Memgraph, and serves them
back to every connected agent in later sessions.

Memgraph stores three types of long-term memory in one graph:
It connects to the
[supported agents](/ai-ecosystem/ai-memory/agents) with no code to write.
[Custom agents](/ai-ecosystem/ai-memory/custom-agents), built on the Claude
Agent SDK or the OpenAI Agents SDK, can use the same memory.

| Memory type | What it holds | How it's stored |
| --- | --- | --- |
| **Semantic** | What the system knows, such as facts and preferences | `(:User)-[:HAS_MEMORY]->(:Memory)` |
| **Episodic** | What the system did, such as past interactions | `(:Session)-[:HAS_ACTION]->(:Action)`, in order by `FOLLOWED_BY` |
| **Procedural** | What the system knows how to do, such as workflows | `(:Session)-[:USED_SKILL]->(:Skill)` |
Every connected agent gets:

The `User` and `Session` nodes are shared by all three types, so one traversal
can recall facts, past actions and skills together.
- **Recording.** Hooks in the agent write each session to the graph as it
happens. You use the agent as before.
- **Recall.** A `recall` tool, served over the Model Context Protocol (MCP),
returns what your past sessions hold about a question. Each session also
starts with a short note on where you left off in the current project.
- **Memory**, if you turn it on. A `memory` tool replaces the agent's own
memory, so the notes the agent saves are stored in the graph and shared by
all your agents.

## Set up memory for your coding agents
Context Graph is open source, part of the
[Memgraph AI Toolkit](https://github.com/memgraph/ai-toolkit/tree/main/context-graph).

[Context Graph](https://github.com/memgraph/ai-toolkit/tree/main/context-graph),
part of the Memgraph AI Toolkit, records the sessions of your coding agents in
Memgraph as these three types of memory, so the agents can recall them in
later sessions. It works with Claude Code, Codex, GitHub Copilot CLI, Cursor,
OpenCode, Antigravity CLI and Grok Build.
## Get started

You need [Docker](https://docs.docker.com/get-docker/), unless you already run
Memgraph 3.6 or later, and a terminal. Start the setup:
One command installs Context Graph, finds or starts Memgraph and connects the
agents you choose. It shows its plan and changes nothing until you confirm.

<Tabs items={['Linux/macOS', 'Windows']}>
<Tabs.Tab>
Expand All @@ -43,80 +45,94 @@ curl -sSL https://install.memgraph.com/ai-memory | bash
```
</Tabs.Tab>
<Tabs.Tab>
Run the setup from WSL or Git Bash. In PowerShell, this command prints the
command to run there:

```powershell
iwr https://install.memgraph.com/ai-memory/windows -useb | iex
```
</Tabs.Tab>
</Tabs>

The setup shows its plan and changes nothing until you confirm. Then it:

1. **Finds or starts Memgraph.** It uses the Memgraph in its configuration,
then one on `localhost:7687`, and otherwise starts the
`memgraph/memgraph-mage` image in a container named
`context-graph-memgraph`, with a data volume. If port 7687 is taken, it
picks a free port.
2. **Saves its configuration:** the Memgraph URL and your user ID, which
defaults to your git `user.name`.
3. **Installs the packages:** `uv` if it's missing, the
`memgraph-context-graph` command-line tool and its connectors.
4. **Connects your agents.** Claude Code and Codex get the Context Graph
plugin for your user. The other agents get hooks in the current project
directory.
5. **Checks the setup** and prints the command to rerun for any step that
failed.

Without a terminal, for example in CI, the command only prints the setup
command to run. Set `AI_MEMORY_SKIP_SETUP=1` to get the same behavior.

After the setup, every session of a connected agent writes `Memory`, `Action`
and `Skill` nodes to the graph, and the next session reads its memory back.
To manage the setup:

- `memgraph-context-graph ui` shows what your agents record, in the terminal.
- `memgraph-context-graph setup` changes your choices and skips what's already
done.
- `memgraph-context-graph uninstall` disconnects the agents. The graph and the
configuration stay.

For the other options and how to look at the graph in Memgraph Lab, see the
[Context Graph guide](https://github.com/memgraph/ai-toolkit/blob/main/context-graph/README.md#getting-started).

## Query the memory graph

Because the three types share the `User` and `Session` nodes, one query can
answer a request such as "schedule a follow-up with the client like last
time". This query returns what the system knows about a user, their most
recent session in which a meeting was scheduled, and the skill used in it:

```cypher template
MATCH (u:User {user_id: "USER_ID"})-[:HAS_MEMORY]->(mem:Memory)
MATCH (u)-[:HAD_SESSION]->(s:Session)-[:HAS_ACTION]->(a:Action {tool_name: "schedule_meeting"})
WITH u, mem, s, a ORDER BY s.started_at DESC LIMIT 1
OPTIONAL MATCH (s)-[:USED_SKILL]->(sk:Skill)
RETURN mem.content AS client_facts, s.session_id AS last_session,
a.timestamp AS last_meeting_at, sk.name AS skill, sk.content AS how_to
```

`USER_ID` is the user ID from the setup. To see all the labels, relationship
types and properties the memory graph uses, run:

```cypher
SHOW SCHEMA INFO;
```

The Memgraph that the setup starts has schema info enabled. If you use your
own instance, start it with `--schema-info-enabled=true`.

## Use another memory framework

If you already use an agent memory framework, you can keep it and store its
memory in Memgraph:

- [Mem0](/ai-ecosystem/integrations/mem0): Use Memgraph as the backend for Mem0
graph memory, in Mem0 1.x.
- [Cognee](/ai-ecosystem/integrations/cognee): Use Memgraph as the graph
database for Cognee's knowledge graph.
See [Get started](/ai-ecosystem/ai-memory/get-started) for the prerequisites,
the choices setup offers and how to check that sessions are recorded.

## How it works

Context Graph works in three phases, shown in the diagram: during a session,
it records each event and serves recall from Memgraph; after the session,
reconciliation builds a knowledge graph from what was recorded.

<div className="light-only">

![Context Graph data flow in three phases: during a session, hooks in the agent send each event through the connectors to Memgraph, and the MCP server serves recall and memory from Memgraph back to the agent; after the session, reconciliation extracts a knowledge graph on your machine](/pages/ai-ecosystem/ai-memory/context-graph-flow.svg)

</div>
<div className="dark-only">

![Context Graph data flow in three phases: during a session, hooks in the agent send each event through the connectors to Memgraph, and the MCP server serves recall and memory from Memgraph back to the agent; after the session, reconciliation extracts a knowledge graph on your machine](/pages/ai-ecosystem/ai-memory/context-graph-flow-dark.svg)

</div>

### During a session

- **Hooks.** The `memgraph-context-graph` hooks run in the agent, whether a
coding agent or a custom agent, on each event: a prompt, a reply, a tool
call or its result. They drop text marked as private and redact secrets
before anything is stored.
- **Connectors.** The hooks pass each event to the connectors, which write it
to Memgraph. Each one records one part of a session:
- `actions-graph`: prompts, replies, tool calls and their results;
- `skills-graph`: the agent skills a session used;
- `sessions-graph`: the session, its user and project, and the memories the
agent saved;
- `resources-graph`, optional: the GitHub resources a session read.

On Memgraph Enterprise, `context-graph-spaces` adds
[shared spaces](/ai-ecosystem/ai-memory/shared-spaces) for a team.
- **Memgraph.** Users, sessions, actions, skills and memories form one graph,
and the knowledge graph links to them. See
[The graph](/ai-ecosystem/ai-memory/graph).
- **MCP server.** The MCP server reads Memgraph and serves the `recall` and
`memory` tools to the agent. See
[Recall and memory](/ai-ecosystem/ai-memory/recall-and-memory).

### After a session

When a session ends, [reconciliation](/ai-ecosystem/ai-memory/graph#add-a-knowledge-graph)
extracts the people, organizations, projects and other entities it mentions,
and the facts that connect them, into a knowledge graph. It runs on your
machine:

1. **Ontology.** The ontology is the schema of the knowledge graph: the entity
types and fact types to look for, such as a person who works for an
organization. It's a model in HyGM, the AI Toolkit's graph schema package.
Every user starts with a default ontology, and you can write your own.
2. **Extract.** GLiNER2, a local extraction model, finds the entities and
facts of those types in the session's text. It needs no LLM API key.
3. **Store.** The entities and facts are stored in Memgraph with their
embeddings, linked to the messages they came from. Recall uses them to find
facts spread over many sessions.

**Ontology learning** is optional. With an Anthropic or OpenAI API key in the
configuration, Context Graph learns new entity and fact types from your
sessions. It's the only part of Context Graph that sends session text off
your machine.

## In this section

- [Get started](/ai-ecosystem/ai-memory/get-started): Install Context Graph,
connect your agents and check that sessions are recorded.
- [Recall and memory](/ai-ecosystem/ai-memory/recall-and-memory): How agents
read their past sessions, and how to make Context Graph their memory.
- [The graph](/ai-ecosystem/ai-memory/graph): What your agents recorded, how
to browse and query it, and how to add a knowledge graph of entities and
facts.
- [Privacy](/ai-ecosystem/ai-memory/privacy): What is recorded, how to keep
text out of the graph, and how to delete sessions.
- [Supported agents](/ai-ecosystem/ai-memory/agents): The files setup changes
for each agent, and how the agents differ.
- [Custom agents](/ai-ecosystem/ai-memory/custom-agents): Use the same memory
in an app built on the Claude Agent SDK or the OpenAI Agents SDK.
- [Shared spaces](/ai-ecosystem/ai-memory/shared-spaces): Share memory between
the members of a team, on Memgraph Enterprise.
- [Configuration](/ai-ecosystem/ai-memory/configuration): The configuration
file, recall and extraction settings, your own Memgraph, updating and
uninstalling.
10 changes: 10 additions & 0 deletions pages/ai-ecosystem/ai-memory/_meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
"get-started": "Get started",
"recall-and-memory": "Recall and memory",
"graph": "The graph",
"privacy": "Privacy",
"agents": "Supported agents",
"custom-agents": "Custom agents",
"shared-spaces": "Shared spaces",
"configuration": "Configuration"
}
130 changes: 130 additions & 0 deletions pages/ai-ecosystem/ai-memory/agents.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
title: Supported agents
description: See what Context Graph setup changes for Claude Code, Codex, GitHub Copilot CLI, Cursor, OpenCode, Antigravity CLI and Grok Build.
---

import { Tabs } from 'nextra/components'

# Supported agents

Context Graph works with seven coding agents. For each one, setup installs
hooks that record sessions, registers the Model Context Protocol (MCP) server
that serves the `recall`
and `memory` tools, and can turn off the agent's own memory.

This page lists the files setup changes for each agent, and where the agents
behave differently. For an app you build on an agent SDK, see
[Custom agents](/ai-ecosystem/ai-memory/custom-agents).

| Agent | Runtime name | How it's connected | Applies to |
| --- | --- | --- | --- |
| Claude Code | `claude-code` | Context Graph plugin | Your user |
| Codex | `codex` | Context Graph plugin | Your user |
| GitHub Copilot CLI | `copilot-cli` | `.github/hooks/memgraph-context-graph.json` | One project |
| Cursor | `cursor` | `.cursor/hooks.json` | One project |
| OpenCode | `opencode` | `.opencode/plugins/memgraph-context-graph/index.js` | One project |
| Antigravity CLI | `antigravity-cli` | `.agents/hooks.json` | One project |
| Grok Build | `grok` | `.grok/hooks/memgraph-context-graph.json` | One project |

Use the runtime name to choose agents in `memgraph-context-graph setup`,
`update`, `uninstall` and `doctor`.

Claude Code and Codex sessions are recorded in any directory. For the other
agents, the hook file is in the project directory, never in your home
directory, so only sessions started in a connected project are recorded.
Connect more projects with `--project-dir`. If a hook file already exists,
setup keeps your own hooks in it.

## MCP server registration

The `recall` and `memory` tools are served by `memgraph-context-graph mcp`, an
MCP server named `context-graph`. Memory belongs to you, not to one project,
so the server is registered in each agent's user-level configuration:

| Agent | Where the server is registered | How its tools are allowed |
| --- | --- | --- |
| Claude Code | The plugin | The plugin |
| Codex | The plugin | The plugin |
| GitHub Copilot CLI | `~/.copilot/mcp-config.json` | Copilot CLI has no allow list: approve the tools once, or start it with `--allow-tool=context-graph` |
| Cursor | `~/.cursor/mcp.json` | `Mcp(context-graph:*)` in `~/.cursor/cli-config.json` |
| OpenCode | `mcp.servers` in `~/.config/opencode/opencode.json` | An allow rule in `permissions` |
| Antigravity CLI | `~/.gemini/config/mcp_config.json` | `mcp(context-graph/*)` in `~/.gemini/antigravity-cli/settings.json` |
| Grok Build | `~/.grok/config.toml` | `MCPTool(context-graph__*)` |

Setup adds the tools to the agent's allow list because an agent that runs
without a person, for example in a script, refuses a tool that needs approval.
Each file setup edits keeps the rest of its content and is backed up once, to
`FILE_NAME.context-graph.bak` next to it.

## Built-in memory

When you make Context Graph the agents' memory, setup turns off the agent's
own memory, so the agent doesn't keep two. Some agents have no memory of their
own to turn off.

| Agent | Built-in memory | What setup changes |
| --- | --- | --- |
| Claude Code | Auto memory | Sets `autoMemoryEnabled: false` in `~/.claude/settings.json` and imports the existing memory files |
| Codex | Memories | Turns off `features.memories`, `memories.use_memories` and `memories.generate_memories` in `~/.codex/config.toml` and imports the existing memory |
| GitHub Copilot CLI | Copilot Memory, stored on GitHub | Sets `"memory": false` in `~/.copilot/settings.json`; the memory stays on GitHub and isn't imported |
| Cursor | None | Nothing |
| OpenCode | None | Nothing |
| Antigravity CLI | None in the CLI | Nothing |
| Grok Build | Topic notes in `~/.grok/memory-v2/` | Sets `[memory_v2] enabled = false` and imports the notes to `/memories/grok/` |

See [Memory](/ai-ecosystem/ai-memory/recall-and-memory#memory)
for how the import works and how to switch back.

## Differences between agents

The agents' hooks don't all expose the same events, so some features work
differently:

- **Session-start note.** Every agent gets the note on where you left off at
the start of a session. Grok Build's start hooks can't add text for the
model, so it gets the note through the MCP server's instructions instead.
Codex limits hook text to about 2,500 tokens, so a long memory index is cut
from its end.
- **Note before a tool call.** Only Claude Code and Codex can show the agent a
note right before a tool runs, such as that a GitHub issue it's about to
fetch is already in the graph. The other agents' pre-tool hooks can only
allow, block or rewrite the call.
- **End of a session.** Codex, Antigravity CLI and `opencode run` don't report
when a session ends. Their sessions are processed at the end of each turn
instead, so nothing is lost.
- **Antigravity CLI** hooks don't carry the prompt or reply text. Context Graph
reads the turns from the session transcript the agent writes.
- **Cursor:** the session-start note reaches the Cursor CLI. The agent window
in the Cursor editor may not show it to the model.
- **Codex** also reloads the memory index after it compacts the context.

## Connect an agent manually

Setup connects agents for you. To install the Claude Code or Codex plugin
yourself, for example on a machine where you manage plugins by hand:

<Tabs items={['Claude Code', 'Codex']}>
<Tabs.Tab>
```bash
claude plugin marketplace add memgraph/ai-toolkit --sparse .claude-plugin
claude plugin install context-graph@context-graph-plugins -y
```
</Tabs.Tab>
<Tabs.Tab>
```bash
codex plugin marketplace add memgraph/ai-toolkit --sparse .agents/plugins
codex plugin add context-graph@context-graph-plugins
```
</Tabs.Tab>
</Tabs>

For the per-project agents, the `memgraph-context-graph hook init RUNTIME`
command writes the hook file in the current directory, where `RUNTIME` is the
agent's runtime name:

```bash
memgraph-context-graph hook init cursor
```

The `hook init` command writes only the hooks. Run `memgraph-context-graph setup` for the
MCP server registration and the memory switch.
Loading
Loading