Skip to content
Draft
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
53 changes: 53 additions & 0 deletions agent-framework/user-guide/agents/agent-memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,59 @@ agent = ChatAgent(
)
```

#### Neo4j Memory Provider

Neo4j offers two separate integrations for Agent Framework, each serving a different purpose. This provider (`neo4j-agent-memory`) is for **persistent memory** — storing and recalling agent interactions, extracting entities, and building a knowledge graph over time. For **GraphRAG** from an existing knowledge graph using vector, fulltext, or hybrid search, see the [Neo4j Context Provider for GraphRAG](./agent-rag.md#using-neo4j-for-graphrag).

The Neo4j Memory Provider gives agents persistent memory backed by a knowledge graph. Unlike GraphRAG providers that retrieve from static knowledge bases, the memory provider stores and recalls agent interactions, automatically extracting entities and building a knowledge graph over time.

The provider manages three types of memory:
- **Short-term memory**: Conversation history and recent context
- **Long-term memory**: Entities, preferences, and facts extracted from interactions
- **Reasoning memory**: Past reasoning traces and tool usage patterns

```python
from agent_framework import Agent
from agent_framework.azure import AzureAIClient
from azure.identity.aio import AzureCliCredential
from neo4j_agent_memory import MemoryClient, MemorySettings
from neo4j_agent_memory.integrations.microsoft_agent import (
Neo4jMicrosoftMemory,
create_memory_tools,
)

settings = MemorySettings()
memory_client = MemoryClient(settings)

async with memory_client:
memory = Neo4jMicrosoftMemory.from_memory_client(
memory_client=memory_client,
session_id="user-123",
)
tools = create_memory_tools(memory)

async with (
AzureAIClient(credential=AzureCliCredential(), project_endpoint=project_endpoint) as client,
Agent(
client=client,
instructions="You are a helpful assistant with persistent memory.",
tools=tools,
context_providers=[memory.context_provider],
) as agent,
):
session = agent.create_session()
response = await agent.run("Remember that I prefer window seats on flights.", session=session)
```

Key features:
- **Bidirectional**: Automatically retrieves relevant context before invocation and saves new memories after responses
- **Entity extraction**: Builds a knowledge graph from conversations using a multi-stage extraction pipeline
- **Preference learning**: Infers and stores user preferences across sessions
- **Memory tools**: Agents can explicitly search memory, remember preferences, and find entity connections

> [!TIP]
> Install with `pip install neo4j-agent-memory[microsoft-agent]`. See the [Neo4j Agent Memory repository](https://github.com/neo4j-labs/agent-memory) for complete documentation.

### Thread Serialization and Persistence
The framework supports serializing entire thread states for persistence across application restarts:

Expand Down
51 changes: 51 additions & 0 deletions agent-framework/user-guide/agents/agent-rag.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,57 @@ This pattern works with any Semantic Kernel VectorStore connector, including:

Each connector provides the same `create_search_function` method that can be bridged to Agent Framework tools, allowing you to choose the vector database that best fits your needs. See [the full list here](/semantic-kernel/concepts/vector-store-connectors/out-of-the-box-connectors).

### Using Neo4j for GraphRAG

Neo4j offers two separate integrations for Agent Framework, each serving a different purpose. This provider (`agent-framework-neo4j`) is for **GraphRAG** — searching an existing knowledge graph to ground agent responses. For **persistent memory** that learns from conversations and builds a knowledge graph over time, see the [Neo4j Memory Provider](./agent-memory.md#neo4j-memory-provider).

For knowledge graph scenarios where relationships between entities matter, the Neo4j Context Provider offers GraphRAG. It supports vector, fulltext, and hybrid search modes, with optional graph traversal to enrich results with related entities via custom Cypher queries.

```python
from agent_framework import Agent
from agent_framework.azure import AzureAIClient
from agent_framework_neo4j import Neo4jContextProvider, Neo4jSettings, AzureAIEmbedder
from azure.identity.aio import AzureCliCredential

settings = Neo4jSettings()

neo4j_provider = Neo4jContextProvider(
uri=settings.uri,
username=settings.username,
password=settings.get_password(),
index_name="documentChunks",
index_type="vector",
embedder=AzureAIEmbedder(...),
top_k=5,
retrieval_query="""
MATCH (node)-[:FROM_DOCUMENT]->(doc:Document)
OPTIONAL MATCH (doc)<-[:FILED]-(company:Company)
RETURN node.text AS text, score, doc.title AS title, company.name AS company
ORDER BY score DESC
""",
)

async with (
neo4j_provider,
AzureAIClient(credential=AzureCliCredential(), project_endpoint=project_endpoint) as client,
Agent(
client=client,
instructions="You are a financial analyst assistant.",
context_providers=[neo4j_provider],
) as agent,
):
session = agent.create_session()
response = await agent.run("What risks does Acme Corp face?", session=session)
```

Key features:
- **Index-driven**: Works with any Neo4j vector or fulltext index
- **Graph traversal**: Custom Cypher queries enrich search results with related entities
- **Search modes**: Vector (semantic similarity), fulltext (keyword/BM25), or hybrid (both combined)

> [!TIP]
> Install with `pip install agent-framework-neo4j`. See the [Neo4j Context Provider repository](https://github.com/neo4j-labs/neo4j-maf-provider) for complete documentation.

::: zone-end

## Next steps
Expand Down