Skip to content

samples: add AgentMemory (Neo4j-agent memory reimplemented in NET ) shopping assistant sample#7096

Merged
westey-m merged 14 commits into
microsoft:mainfrom
joslat:neo4j/shopping-assistant-sample
Jul 16, 2026
Merged

samples: add AgentMemory (Neo4j-agent memory reimplemented in NET ) shopping assistant sample#7096
westey-m merged 14 commits into
microsoft:mainfrom
joslat:neo4j/shopping-assistant-sample

Conversation

@joslat

@joslat joslat commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

AgentMemory is a native .NET reimplementation of the graph-native agent memory, inspired by Neo4j Agent Memory and verified against its compatibility kit.

It:

  • Adds a .NET shopping-assistant sample to dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step06_MemoryUsingAgentMemory, following that folder's naming/README/solution conventions (AgentWithMemory_StepNN_...).
  • Demonstrates the AgentMemory library's Microsoft Agent Framework adapter (Neo4jMemoryContextProvider, MemoryToolFactory) for durable, graph-backed memory: the agent learns a shopper's preferences and recommends products via Neo4j graph traversal, with memory persisting across brand-new sessions.
  • Ships as a standalone sample: it consumes the published AgentMemory NuGet packages (which target Microsoft.Agents.AI 1.9.0) rather than this repo's source projects, so it targets net9.0 with explicit package versions. Empty Directory.Build.props/Directory.Build.targets markers keep it isolated from the repo's net10.0 / Central-Package-Management build (verified it restores/builds cleanly in isolation).
  • Registered in the CI sample-verification list (eng/verify-samples/AgentsSamples.cs) with a SkipReason, matching the existing Mem0 sample, since it requires a live Neo4j instance.
  • Named around "AgentMemory" (the library) rather than "Neo4j" the company/product, since this is a community .NET port and not an officially recognized Neo4j integration — Neo4j is still referenced where it's a genuine technical detail (the graph backing store, env vars, Cypher).

Test plan

  • dotnet build succeeds for the new project in isolation (confirmed Directory.Build.props/targets markers correctly block inheritance of the repo's net10.0/CPM settings — TargetFrameworks, TreatWarningsAsErrors evaluate empty/false as expected).
  • Manual run against a real Neo4j instance + Azure OpenAI/Foundry deployment (requires external services not available in this environment).

joslat and others added 2 commits July 13, 2026 22:48
…ory 1.0.1)

The .NET port of the official Neo4j Agent Memory "retail assistant" example
(neo4j-labs/agent-memory examples/microsoft_agent_retail_assistant, referenced
from the Learn integration page), which is currently Python-only.

Wires Neo4jMemoryContextProvider (AIContextProvider), MemoryToolFactory
memory tools, and a ProductCatalog of retail tools over a Neo4j :Product
graph, via the published AgentMemory + AgentMemory.AgentFramework 1.0.1
NuGet packages.

Lives at the repo root rather than under dotnet/samples/: that tree is
.NET 10 + Central Package Management + Microsoft.Agents.AI ~1.13 with
source ProjectReferences, while AgentMemory currently targets net9.0 +
Microsoft.Agents.AI 1.9.0. A repo-native version needs AgentMemory bumped
to track the newer Agents.AI/Extensions.AI line first. Cross-linked from
dotnet/samples/02-agents/AgentWithMemory/README.md as a "See also" entry,
same pattern already used for the cross-folder Custom Memory Implementation
link.

Verified: dotnet build succeeds (0 warnings, 0 errors) against the published
packages, proving the AgentMemory public surface is package-consumable.
Matches sibling AgentWithMemory samples' conventions (BOM + copyright file
header on .cs files, README sections: Features Demonstrated / Prerequisites
/ Environment Variables / Run the Sample / Expected Output).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Relocates the standalone shopping-assistant sample from the repo root into
dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step06_MemoryUsingAgentMemory,
following that folder's naming/README/solution conventions. Renames its identity
from "Neo4j" to "AgentMemory" (the library it actually demonstrates) since this
is a community .NET port, not an officially recognized Neo4j integration - Neo4j
is still referenced where it's a genuine technical detail (the graph backing
store, env vars, Cypher). Adds empty Directory.Build.props/targets markers so it
stays isolated from the repo's net10.0/CPM build, and registers it (skipped, like
the Mem0 sample) in the CI sample-verification list since it needs a live Neo4j
instance.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 13, 2026 21:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@giles17 giles17 added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net labels Jul 13, 2026
@github-actions github-actions Bot changed the title samples: add AgentMemory (Neo4j-backed) shopping assistant sample .NET: samples: add AgentMemory (Neo4j-backed) shopping assistant sample Jul 13, 2026
@joslat joslat changed the title .NET: samples: add AgentMemory (Neo4j-backed) shopping assistant sample samples: add AgentMemory (Neo4j-agent memory reimplemented in NET ) shopping assistant sample Jul 13, 2026
Comment thread dotnet/samples/02-agents/AgentWithMemory/README.md Outdated
Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>
…6_MemoryUsingAgentMemory/AgentWithMemory_Step06_MemoryUsingAgentMemory.csproj

Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>
@joslat

joslat commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

@westey-m all ready!

@joslat

joslat commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@westey-m all ready!

@joslat

joslat commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

fixing something - do not merge - yet!

WithMemoryOwnerScoping(sp) (1.1.0) already removed the need to manually
wrap agent.RunAsync in ownerContext.BeginOwnerScope(userId). This picks
up 1.2.0's ExposeMemoryToolsFromContextProvider option, so
Neo4jMemoryContextProvider now appends the memory tools to AIContext.Tools
itself on every model call — no more separate MemoryToolFactory wiring,
AIContextProviders = [memoryProvider] is enough.

Addresses westey-m's PR review suggestion.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@joslat

joslat commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

And done!! all points FULLY addressed :) - some at origin

@peibekwe

Copy link
Copy Markdown
Contributor

@joslat - part of the description mentions that this "ships standalone", but there are no Directory.Build.props / .targets marker files and it seems to be a normal in-solution sample, not standalone. Is the intention for this to be standalone or should the description be updated?

@joslat

joslat commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

@peibekwe comments addressed, thanks for looking into it :)

…to net10.0

Directory.Build.props sets a repo-wide TargetFrameworks (plural) list
before this project's own properties are evaluated, and the SDK decides
multi-targeting from that plural property at Sdk.props time. The prior
singular TargetFramework=net10.0 override didn't take effect early
enough, so restore still ran against net9.0/net8.0/netstandard2.0/net472
too - frameworks the published AgentMemory 1.2.0 packages don't support
(NU1202), plus surfaced an OpenTelemetry.Api advisory as an error
(NU1902) since TreatWarningsAsErrors is on repo-wide.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
joslat added a commit to joslat/semantic-kernel-docs that referenced this pull request Jul 16, 2026
…s index

- List the Neo4j Memory Provider under the C# Memory AI Context Providers
  table in integrations/index.md (previously only linked from the Python
  pivot), per westey-m's review comment.
- Update the C# usage sample to use AddNeo4jAgentMemory's configureMemory/
  configureNeo4j overload (the prior single-arg call didn't resolve without
  an extra import), drop the now-redundant AddAgentMemoryCore/IClock/
  IIdGenerator registrations AddNeo4jAgentMemory already wires up, and pass
  configureLlm so AutoExtractOnPersist isn't a silent no-op.
- Wrap the agent in .WithMemoryOwnerScoping(services) instead of a manual
  BeginOwnerScope around RunAsync, matching the scoping fix from
  microsoft/agent-framework#7096 (BeginOwnerScope doesn't reliably cover the
  tool-calling loop).
- Fix NEO4J_USER -> NEO4J_USERNAME and overstated .NET 9.0 -> 8.0 prerequisite
  to match the sibling Neo4j GraphRAG page and the library's actual multi-targeting.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The sample opts out of central package management, so it was pulling in
OpenTelemetry.Api 1.12.0 transitively (via Microsoft.Agents.AI), which has
a known moderate-severity vulnerability (GHSA-g94r-2vxg-569j). The repo
treats NuGet audit warnings as errors, so restore failed outright and took
down every dotnet-build matrix leg plus check-format.

Pinned OpenTelemetry.Api to 1.15.3, matching Directory.Packages.props.
With restore succeeding, previously-masked analyzer/format issues surfaced
and are fixed too: RCS1118 (const local for immutable Cypher queries),
CA1859 (List<IRecord> param instead of IReadOnlyList<IRecord>), and IDE1006
naming violations (s_seed field prefix, PascalCase Cypher/Shopper consts).

Verified locally with the same mcr.microsoft.com/dotnet/sdk:10.0 image CI
uses: dotnet build --warnaserror and dotnet format --verify-no-changes both
pass clean, and a full solution build completed ~24 min with zero errors.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@joslat

joslat commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

cannot merge anymore... :'(

@westey-m
westey-m added this pull request to the merge queue Jul 16, 2026
westey-m pushed a commit to MicrosoftDocs/semantic-kernel-docs that referenced this pull request Jul 16, 2026
* docs: add C# usage for the Neo4j Memory Provider

Fills in the C# zone of the Neo4j Memory Provider page, previously just a
"not yet available" placeholder, with Prerequisites/Installation/Usage/Key
features/Resources sections mirroring the Python zone's structure. Documents
the AgentMemory / AgentMemory.AgentFramework NuGet packages (a community
.NET port of the Neo4j Labs memory provider, not an official Neo4j Labs
package) and links to its source repo and the upcoming Agent Framework
retail-assistant sample.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Address PR review: fix C# sample and link Neo4j Memory in integrations index

- List the Neo4j Memory Provider under the C# Memory AI Context Providers
  table in integrations/index.md (previously only linked from the Python
  pivot), per westey-m's review comment.
- Update the C# usage sample to use AddNeo4jAgentMemory's configureMemory/
  configureNeo4j overload (the prior single-arg call didn't resolve without
  an extra import), drop the now-redundant AddAgentMemoryCore/IClock/
  IIdGenerator registrations AddNeo4jAgentMemory already wires up, and pass
  configureLlm so AutoExtractOnPersist isn't a silent no-op.
- Wrap the agent in .WithMemoryOwnerScoping(services) instead of a manual
  BeginOwnerScope around RunAsync, matching the scoping fix from
  microsoft/agent-framework#7096 (BeginOwnerScope doesn't reliably cover the
  tool-calling loop).
- Fix NEO4J_USER -> NEO4J_USERNAME and overstated .NET 9.0 -> 8.0 prerequisite
  to match the sibling Neo4j GraphRAG page and the library's actual multi-targeting.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Merged via the queue into microsoft:main with commit f4e4995 Jul 16, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants