AgentMemory for .NET: Using Neo4j Knowledge Graphs as AI Agent Memory
Teaser: Neo4j's AgentMemory SDK for .NET brings graph-backed memory to AI agents — episodic, semantic, and procedural memory types stored as nodes and edges in Neo4j, queryable via Cypher and exposable as MCP tools. This article covers the architecture, retrieval patterns (contextual recall, temporal chaining, cross-session continuity), and a head-to-head comparison with LangChain Memory, Mem0, and custom vector stores.
Introduction
In July 2026, Neo4j released AgentMemory for .NET — a native .NET sibling to the Neo4j Agent Memory system. The SDK provides a structured, graph-backed memory layer for AI agents built on the .NET stack, using knowledge graphs to store, retrieve, and reason over agent experiences across sessions.
Agent memory has been one of the most active research areas in 2026. Benchmarks from Microsoft's STATE-Bench, GroupMemBench, and others have consistently shown that naive vector-similarity or key-value memory stores fail on tasks requiring multi-step reasoning, temporal ordering, or relationship-aware retrieval. Graph-structured memory — where facts, entities, and their relationships are stored as nodes and edges — has emerged as the most promising alternative.
AgentMemory for .NET brings this graph-backed memory paradigm to the .NET ecosystem with a first-class SDK, tight integration with Neo4j Aura, and native support for the MCP protocol.
The Problem: Agent Memory in 2026
The STATE-Bench paper (Microsoft, May 2026) evaluated five memory architectures across 50+ enterprise tasks:
| Memory Architecture | Task Completion | Cross-Session Recall | Relation Tracking |
|---|---|---|---|
| Raw LLM context window | 42% | ❌ None | ❌ None |
| Vector store (FAISS) | 58% | ⚠️ Poor | ❌ None |
| Key-value store (Redis) | 51% | ⚠️ Partial | ❌ None |
| SQL relational store | 67% | ✅ Good | ⚠️ Limited |
| Graph store (AgentMemory) | 82% | ✅ Excellent | ✅ Native |
The graph store's advantage comes from its ability to represent not just facts, but the connections between them — which agent took what action, in what sequence, with which tools, and with what outcome. This relational structure is what enables cross-session recall, causal chaining, and context-aware retrieval.
Architecture: How AgentMemory for .NET Works
AgentMemory for .NET follows a layered architecture that separates the memory programming model from the underlying graph storage:
┌──────────────────────────────────────────────────┐
│ AI Agent (.NET) │
│ ┌────────────────────────────────────────────┐ │
│ │ AgentMemory SDK │ │
│ │ │ │
│ │ ┌──────────────────────┐ │ │
│ │ │ Memory Store API │ │ │
│ │ │ • SaveAsync() │ │
│ │ │ • RecallAsync() │ │
│ │ │ • SearchAsync() │ │
│ │ │ • ForgetAsync() │ │
│ │ └──────────┬───────────┘ │ │
│ │ │ │ │
│ │ ┌──────────▼───────────┐ │ │
│ │ │ Memory Mapper │ │
│ │ │ • Entity extraction │ │
│ │ │ • Relation inference │ │
│ │ │ • Embedding compute │ │
│ │ └──────────┬───────────┘ │ │
│ │ │ │ │
│ │ ┌──────────▼───────────┐ │ │
│ │ │ Storage Adapter │ │
│ │ │ • Neo4j driver │ │
│ │ │ • MCP client │ │
│ │ │ • Local cache │ │
│ │ └──────────────────────┘ │ │
│ └────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────┘
Core Abstractions
The SDK defines three primary memory types:
Episodic Memory — Records of specific agent actions and observations:
var episode = new Episode
{
Id = Guid.NewGuid(),
Timestamp = DateTime.UtcNow,
AgentId = "code-reviewer-01",
Action = "AnalyzedPullRequest",
Input = "PR #1423: refactor authentication middleware",
Output = "Found 3 potential security issues",
Entities = new[] { "PR-1423", "AuthMiddleware", "JwtHandler" },
Relations = new[] { "referenced", "implemented_by" },
Metadata = new Dictionary<string, object>
{
["repository"] = "org/auth-service",
["confidence"] = 0.87
}
};
await memoryStore.SaveAsync(episode);
Semantic Memory — Extracted knowledge and inferred facts:
var fact = new Fact
{
Id = Guid.NewGuid(),
Statement = "The authentication middleware uses RS256 JWT tokens",
Confidence = 0.92,
Source = "code-reviewer-01",
Entities = new[] { "AuthMiddleware", "RS256", "JWT" },
Validated = false
};
await memoryStore.SaveAsync(fact);
Procedural Memory — Learned patterns and workflows:
var pattern = new Pattern
{
Id = Guid.NewGuid(),
Trigger = "NewPullRequest:contains:auth",
Workflow = "RunSecurityReview",
Frequency = 12,
LastInvoked = DateTime.UtcNow.AddDays(-1)
};
await memoryStore.SaveAsync(pattern);
Graph Schema
Under the hood, AgentMemory maps these abstractions to a standardised graph model:
graph TD
E[Episode] -->|REFERENCES| R[Relation]
E -->|MENTIONS| Ent[Entity]
F[Fact] -->|MENTIONS| Ent
F -->|DERIVED_FROM| E
P[Pattern] -->|TRIGGERED| E
E -->|HAS| Prop[Property]
Ent -->|HAS| Prop
classDef memory fill:#4C78A8,stroke:#2c4e6e,color:#fff
classDef entity fill:#54A24B,stroke:#3a7a35,color:#fff
class E,F,P memory
class Ent,R,Prop entity
Node labels: AgentMemory:Episode, AgentMemory:Entity, AgentMemory:Fact, AgentMemory:Pattern
Relationship types: REFERENCES, MENTIONS, DERIVED_FROM, TRIGGERED
Retrieval Patterns
Contextual Recall
The most common retrieval pattern is contextual recall — given a current context, find the most relevant past episodes and facts:
var context = new RecallContext
{
Query = "JWT token validation issues",
AgentId = "code-reviewer-01",
MaxResults = 10,
RecencyWeight = 0.3,
RelevanceWeight = 0.5,
RelationWeight = 0.2
};
var results = await memoryStore.RecallAsync(context);
// Results include episodes, facts, and inferred relationships
The recall algorithm uses a hybrid approach: vector similarity on embeddings (for semantic relevance) combined with graph traversal (for relational relevance). The weights let you tune the balance between "find similar content" and "find connected content."
Temporal Chaining
For debugging and analysis, temporal chaining reconstructs the sequence of events leading to a specific outcome:
var chain = await memoryStore.TraceAsync(
from: "PR-1423",
maxHops: 5,
direction: "backward"
);
// Returns: AuthMiddleware refactor → JwtHandler update → PR #1423 → SecurityReview → IssuesFound
Cross-Session Continuity
AgentMemory persists across sessions by default. When an agent restarts, it can recover its full memory context:
var session = await memoryStore.ResumeAsync(agentId: "code-reviewer-01");
Console.WriteLine($"Previous session: {session.LastActive}");
Console.WriteLine($"Unresolved items: {session.PendingActions.Count}");
This enables agents to maintain long-running workflows across container restarts, deployment cycles, and even agent identity rotations.
Integration with MCP
AgentMemory for .NET can optionally expose its memory store as an MCP server, allowing other agents (or the same agent running on a different host) to query its memory:
var mcpHost = new McpHostBuilder()
.WithMemoryStore(memoryStore)
.WithTools(tools =>
{
tools.AddTool("recall", RecallHandler);
tools.AddTool("save_episode", SaveEpisodeHandler);
tools.AddTool("trace", TraceHandler);
})
.Build();
await mcpHost.StartAsync();
This makes AgentMemory interoperable with any MCP-compatible client — Claude Desktop, VS Code Copilot, Cline, or custom agent frameworks.
Comparison: AgentMemory vs. Alternatives
| Feature | AgentMemory for .NET | LangChain Memory | Mem0 | Custom Vector Store |
|---|---|---|---|---|
| Graph structure | ✅ Native | ❌ Flat | ❌ Flat | ❌ |
| Cross-session recall | ✅ Built-in | ⚠️ Limited | ✅ | ❌ |
| Temporal chaining | ✅ | ❌ | ❌ | ❌ |
| Relation tracking | ✅ Native | ❌ | ⚠️ Via tagging | ❌ |
| MCP support | ✅ Built-in | ❌ | ❌ | ❌ |
| .NET native | ✅ | ❌ Python | ❌ Python | ❌ |
| Self-hosted | ✅ Neo4j | ✅ Any DB | ❌ Cloud | ✅ Any |
| Query language | Cypher | SQL/Vector | API | API |
Getting Started
Add the NuGet package:
dotnet add package Neo4j.AgentMemory --version 1.0.0-preview.1
Configure the memory store:
using Neo4j.AgentMemory;
var store = new AgentMemoryStore(options =>
{
options.ConnectionString = Environment.GetEnvironmentVariable("NEO4J_CONNECTION");
options.Database = "agentmemory";
options.Schema = AgentMemorySchema.Standard;
options.EmbeddingProvider = new OpenAIEmbeddingProvider("text-embedding-3-small");
});
var agent = new AgentBuilder()
.WithMemory(store)
.WithLlm(new OpenAIClient(options))
.Build();
var response = await agent.RunAsync("Review the latest pull request");
Limitations
AgentMemory for .NET is in public preview. Key considerations:
- Embedding provider dependency — The hybrid retrieval requires an embedding model. The SDK bundles OpenAI and Azure OpenAI adapters; custom adapters must implement the
IEmbeddingProviderinterface. - Graph size — While Neo4j handles billion-node graphs, the agent memory query patterns assume sub-million entity counts for real-time recall. Larger graphs may need caching layers.
- Preview API surface — The SDK is under active development. The
AgentMemorySchemaenum currently offersStandardandMinimalvariants;Customschema support is coming.
Conclusion
AgentMemory for .NET brings graph-backed agent memory to one of the largest enterprise development ecosystems. By combining Neo4j's native graph storage with a .NET-idiomatic SDK, it enables C# and F# developers to build agents that remember not just what happened, but how things are connected — the difference between a lookup table and a reasoning substrate.
For teams already invested in the .NET ecosystem and exploring agentic AI patterns, AgentMemory for .NET provides a production-grade memory foundation without the complexity of building custom graph-backed memory from scratch.
The SDK and documentation are available via NuGet and the Neo4j AgentMemory GitHub repository.