Skip to content

Commit 3d753f4

Browse files
committed
cleanup
1 parent 365f0d7 commit 3d753f4

File tree

4 files changed

+15
-246
lines changed

4 files changed

+15
-246
lines changed

Lab_7_Agent_Memory/01_memory_context_provider.ipynb

Lines changed: 7 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,7 @@
44
"cell_type": "markdown",
55
"id": "0",
66
"metadata": {},
7-
"source": [
8-
"# Memory Context Provider\n",
9-
"\n",
10-
"This notebook uses the [`neo4j-agent-memory`](https://github.com/neo4j-labs/agent-memory) package — a graph-native memory system for AI agents, and the second Neo4j context provider package covered in this workshop. Unlike the `agent-framework-neo4j` provider in Lab 6 that retrieves from a static knowledge base, agent memory is dynamic: it grows with every conversation.\n",
11-
"\n",
12-
"Here you'll use its `Neo4jContextProvider` (distinct from the one in Lab 6) as a MAF context provider for automatic memory injection. The provider supports three memory types:\n",
13-
"- **Short-term**: Recent conversation history with semantic search\n",
14-
"- **Long-term**: Entities, preferences, and facts extracted from conversations\n",
15-
"- **Reasoning**: Similar past task traces for learning from experience\n",
16-
"\n",
17-
"***"
18-
]
7+
"source": "# Memory Context Provider\n\nThis notebook uses the [`neo4j-agent-memory`](https://github.com/neo4j-labs/agent-memory) package — a graph-native memory system for AI agents, and the second Neo4j context provider package covered in this workshop. Unlike the `agent-framework-neo4j` provider in Lab 6 that retrieves from a static knowledge base, agent memory is dynamic: it grows with every conversation.\n\nHere you'll use its `Neo4jContextProvider` (distinct from the one in Lab 6) as a MAF context provider for automatic memory injection. The provider supports three memory types:\n- **Short-term**: Recent conversation history with semantic search\n- **Long-term**: Entities, preferences, and facts extracted from conversations\n- **Reasoning**: Similar past task traces for learning from experience\n\n***"
198
},
209
{
2110
"cell_type": "markdown",
@@ -31,26 +20,7 @@
3120
"id": "2",
3221
"metadata": {},
3322
"outputs": [],
34-
"source": [
35-
"import sys\n",
36-
"sys.path.insert(0, '../shared')\n",
37-
"\n",
38-
"import asyncio\n",
39-
"\n",
40-
"from pydantic import SecretStr\n",
41-
"\n",
42-
"from agent_framework.azure import AzureAIClient\n",
43-
"from azure.identity.aio import AzureCliCredential\n",
44-
"\n",
45-
"from neo4j_agent_memory import MemoryClient, MemorySettings\n",
46-
"from neo4j_agent_memory.integrations.microsoft_agent import (\n",
47-
" Neo4jContextProvider,\n",
48-
" Neo4jMicrosoftMemory,\n",
49-
")\n",
50-
"\n",
51-
"from azure_embedder import get_memory_embedder\n",
52-
"from config import get_agent_config, Neo4jConfig"
53-
]
23+
"source": "import sys\nsys.path.insert(0, '../shared')\n\nimport asyncio\n\nfrom pydantic import SecretStr\n\nfrom agent_framework.azure import AzureAIClient\nfrom azure.identity.aio import AzureCliCredential\n\nfrom neo4j_agent_memory import MemoryClient, MemorySettings\nfrom neo4j_agent_memory.integrations.microsoft_agent import (\n Neo4jContextProvider,\n Neo4jMicrosoftMemory,\n)\n\nfrom azure_embedder import get_memory_embedder\nfrom config import get_agent_config, Neo4jConfig"
5424
},
5525
{
5626
"cell_type": "markdown",
@@ -68,23 +38,7 @@
6838
"id": "4",
6939
"metadata": {},
7040
"outputs": [],
71-
"source": [
72-
"# Get workshop configuration\n",
73-
"config = get_agent_config()\n",
74-
"neo4j_config = Neo4jConfig()\n",
75-
"\n",
76-
"# Configure memory settings\n",
77-
"settings = MemorySettings(\n",
78-
" neo4j={\n",
79-
" \"uri\": neo4j_config.uri,\n",
80-
" \"username\": neo4j_config.username,\n",
81-
" \"password\": SecretStr(neo4j_config.password),\n",
82-
" },\n",
83-
")\n",
84-
"\n",
85-
"print(f\"Neo4j URI: {neo4j_config.uri}\")\n",
86-
"print(f\"Memory settings configured\")"
87-
]
41+
"source": "# Get workshop configuration\nconfig = get_agent_config()\nneo4j_config = Neo4jConfig()\n\n# Configure memory settings\nsettings = MemorySettings(\n neo4j={\n \"uri\": neo4j_config.uri,\n \"username\": neo4j_config.username,\n \"password\": SecretStr(neo4j_config.password),\n },\n extraction={\"extractor_type\": \"spacy\"},\n)\n\nprint(f\"Neo4j URI: {neo4j_config.uri}\")\nprint(f\"Memory settings configured\")"
8842
},
8943
{
9044
"cell_type": "markdown",
@@ -105,26 +59,7 @@
10559
"id": "6",
10660
"metadata": {},
10761
"outputs": [],
108-
"source": [
109-
"# Create memory client\n",
110-
"memory_client = MemoryClient(settings, embedder=get_memory_embedder())\n",
111-
"await memory_client.__aenter__()\n",
112-
"\n",
113-
"# Create unified memory interface\n",
114-
"session_id = \"workshop-demo\"\n",
115-
"\n",
116-
"memory = Neo4jMicrosoftMemory.from_memory_client(\n",
117-
" memory_client=memory_client,\n",
118-
" session_id=session_id,\n",
119-
" include_short_term=True,\n",
120-
" include_long_term=True,\n",
121-
" include_reasoning=True,\n",
122-
" extract_entities=True,\n",
123-
")\n",
124-
"\n",
125-
"print(f\"Session: {session_id}\")\n",
126-
"print(f\"Memory created with context provider and chat store\")"
127-
]
62+
"source": "# Create memory client\nmemory_client = MemoryClient(settings, embedder=get_memory_embedder())\nawait memory_client.__aenter__()\n\n# Create unified memory interface\nsession_id = \"workshop-demo\"\n\nmemory = Neo4jMicrosoftMemory.from_memory_client(\n memory_client=memory_client,\n session_id=session_id,\n include_short_term=True,\n include_long_term=True,\n include_reasoning=True,\n extract_entities=True,\n)\n\nprint(f\"Session: {session_id}\")\nprint(f\"Memory created with context provider and chat store\")"
12863
},
12964
{
13065
"cell_type": "markdown",
@@ -154,44 +89,7 @@
15489
"id": "9",
15590
"metadata": {},
15691
"outputs": [],
157-
"source": [
158-
"async def run_conversation():\n",
159-
" async with AzureCliCredential() as credential:\n",
160-
" async with AzureAIClient(\n",
161-
" project_endpoint=config.project_endpoint,\n",
162-
" model_deployment_name=config.model_name,\n",
163-
" credential=credential,\n",
164-
" ) as client:\n",
165-
" agent = client.as_agent(\n",
166-
" name=\"workshop-memory-agent\",\n",
167-
" instructions=(\n",
168-
" \"You are a helpful assistant with persistent memory. \"\n",
169-
" \"You can remember previous conversations and user preferences. \"\n",
170-
" \"When you notice the user expressing a preference, acknowledge it.\"\n",
171-
" ),\n",
172-
" context_providers=[memory.context_provider],\n",
173-
" )\n",
174-
" session = agent.create_session()\n",
175-
"\n",
176-
" # First interaction\n",
177-
" queries = [\n",
178-
" \"Hi! I'm interested in learning about Apple's products.\",\n",
179-
" \"What about their risk factors? I'm particularly concerned about supply chain issues.\",\n",
180-
" \"Can you remind me what we discussed about Apple?\",\n",
181-
" ]\n",
182-
"\n",
183-
" for query in queries:\n",
184-
" print(f\"User: {query}\\n\")\n",
185-
" print(\"Assistant: \", end=\"\", flush=True)\n",
186-
"\n",
187-
" response = await agent.run(query, session=session)\n",
188-
" print(response.text)\n",
189-
" print(\"\\n\" + \"-\" * 50 + \"\\n\")\n",
190-
"\n",
191-
" await asyncio.sleep(0.1)\n",
192-
"\n",
193-
"await run_conversation()"
194-
]
92+
"source": "async def run_conversation():\n async with AzureCliCredential() as credential:\n async with AzureAIClient(\n project_endpoint=config.project_endpoint,\n model_deployment_name=config.model_name,\n credential=credential,\n ) as client:\n agent = client.as_agent(\n name=\"workshop-memory-agent\",\n instructions=(\n \"You are a helpful assistant with persistent memory. \"\n \"You can remember previous conversations and user preferences. \"\n \"When you notice the user expressing a preference, acknowledge it.\"\n ),\n context_providers=[memory.context_provider],\n )\n session = agent.create_session()\n\n # First interaction\n queries = [\n \"Hi! I'm interested in learning about Apple's products.\",\n \"What about their risk factors? I'm particularly concerned about supply chain issues.\",\n \"Can you remind me what we discussed about Apple?\",\n ]\n\n for query in queries:\n print(f\"User: {query}\\n\")\n print(\"Assistant: \", end=\"\", flush=True)\n\n response = await agent.run(query, session=session)\n print(response.text)\n print(\"\\n\" + \"-\" * 50 + \"\\n\")\n\n await asyncio.sleep(0.1)\n\nawait run_conversation()"
19593
},
19694
{
19795
"cell_type": "markdown",
@@ -253,13 +151,7 @@
253151
"cell_type": "markdown",
254152
"id": "13",
255153
"metadata": {},
256-
"source": [
257-
"***\n",
258-
"\n",
259-
"[View the complete code](../financial_data_load/solution_srcs/07_01_memory_context_provider.py)\n",
260-
"\n",
261-
"[Move on to the Memory Tools Agent Notebook](02_memory_tools_agent.ipynb)"
262-
]
154+
"source": "***\n\n[View the complete code](../financial_data_load/solution_srcs/07_01_memory_context_provider.py)\n\n[Move on to the Memory Tools Agent Notebook](02_memory_tools_agent.ipynb)"
263155
},
264156
{
265157
"cell_type": "code",
@@ -294,4 +186,4 @@
294186
},
295187
"nbformat": 4,
296188
"nbformat_minor": 5
297-
}
189+
}

0 commit comments

Comments
 (0)