Skip to content

Commit d6304f1

Browse files
replaces session manager with message history
1 parent 3466c35 commit d6304f1

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

python-recipes/RAG/01_redisvl.ipynb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,14 +1869,14 @@
18691869
"outputs": [],
18701870
"source": [
18711871
"from functools import wraps\n",
1872-
"from redisvl.extensions.session_manager import StandardSessionManager\n",
1872+
"from redisvl.extensions.message_history import MessageHistory\n",
18731873
"\n",
18741874
"\n",
18751875
"class ChatBot:\n",
18761876
" def __init__(self, index: AsyncSearchIndex, vectorizer: BaseVectorizer, user: str):\n",
18771877
" self.index = index\n",
18781878
" self.vectorizer = vectorizer\n",
1879-
" self.session_manager = StandardSessionManager(\n",
1879+
" self.history = MessageHistory(\n",
18801880
" name=f\"chat_session_{user}\",\n",
18811881
" session_tag=user,\n",
18821882
" redis_url=REDIS_URL,\n",
@@ -1915,7 +1915,7 @@
19151915
"\n",
19161916
" async def clear_history(self):\n",
19171917
" \"\"\"Clear session chat\"\"\"\n",
1918-
" self.session_manager.clear()\n",
1918+
" self.history.clear()\n",
19191919
"\n",
19201920
" async def answer_question(self, query: str):\n",
19211921
" \"\"\"Answer the user's question with historical context and caching baked-in\"\"\"\n",
@@ -1933,7 +1933,7 @@
19331933
" answer = result[0]['response']\n",
19341934
" else:\n",
19351935
" context = await self.retrieve_context(query_vector)\n",
1936-
" session = self.session_manager.messages\n",
1936+
" session = self.history.messages\n",
19371937
" messages = (\n",
19381938
" [{\"role\": \"system\", \"content\": SYSTEM_PROMPT}] +\n",
19391939
" session +\n",
@@ -1950,7 +1950,7 @@
19501950
" llmcache.store(query, answer, query_vector)\n",
19511951
"\n",
19521952
" # Add message history\n",
1953-
" self.session_manager.add_messages([\n",
1953+
" self.history.add_messages([\n",
19541954
" {\"role\": \"user\", \"content\": query},\n",
19551955
" {\"role\": \"assistant\", \"content\": answer}\n",
19561956
" ])\n",
@@ -2037,7 +2037,7 @@
20372037
],
20382038
"source": [
20392039
"# NBVAL_SKIP\n",
2040-
"chat.session_manager.messages"
2040+
"chat.history.messages"
20412041
]
20422042
},
20432043
{
@@ -2102,7 +2102,7 @@
21022102
"provenance": []
21032103
},
21042104
"kernelspec": {
2105-
"display_name": "env",
2105+
"display_name": "redis-ai-res",
21062106
"language": "python",
21072107
"name": "python3"
21082108
},
@@ -2116,7 +2116,7 @@
21162116
"name": "python",
21172117
"nbconvert_exporter": "python",
21182118
"pygments_lexer": "ipython3",
2119-
"version": "3.11.11"
2119+
"version": "3.11.9"
21202120
}
21212121
},
21222122
"nbformat": 4,

python-recipes/agents/01_crewai_langgraph_redis.ipynb

Lines changed: 3 additions & 2 deletions
Large diffs are not rendered by default.

python-recipes/agents/03_memory_agent.ipynb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,16 +1394,26 @@
13941394
"metadata": {
13951395
"id": "h6TvQaob1nfi"
13961396
},
1397-
"outputs": [],
1397+
"outputs": [
1398+
{
1399+
"data": {
1400+
"text/plain": [
1401+
"'from langgraph.graph import StateGraph, END\\n\\nworkflow = StateGraph(RuntimeState)\\n\\n# Add nodes to the graph\\nworkflow.add_node(\"agent\", respond_to_user)\\nworkflow.add_node(\"execute_tools\", execute_tools)\\nworkflow.add_node(\"summarize_conversation\", summarize_conversation)\\n'"
1402+
]
1403+
},
1404+
"execution_count": 2,
1405+
"metadata": {},
1406+
"output_type": "execute_result"
1407+
}
1408+
],
13981409
"source": [
13991410
"from langgraph.graph import StateGraph, END\n",
14001411
"\n",
14011412
"workflow = StateGraph(RuntimeState)\n",
14021413
"\n",
14031414
"# Add nodes to the graph\n",
14041415
"workflow.add_node(\"agent\", respond_to_user)\n",
1405-
"workflow.add_node(\"execute_tools\", execute_tools)\n",
1406-
"workflow.add_node(\"summarize_conversation\", summarize_conversation)"
1416+
"workflow.add_node(\"execute_tools\", execute_tools)"
14071417
]
14081418
},
14091419
{
@@ -1875,7 +1885,7 @@
18751885
"provenance": []
18761886
},
18771887
"kernelspec": {
1878-
"display_name": ".venv",
1888+
"display_name": "redis-ai-res",
18791889
"language": "python",
18801890
"name": "python3"
18811891
},
@@ -1889,7 +1899,7 @@
18891899
"name": "python",
18901900
"nbconvert_exporter": "python",
18911901
"pygments_lexer": "ipython3",
1892-
"version": "3.11.11"
1902+
"version": "3.11.9"
18931903
}
18941904
},
18951905
"nbformat": 4,

0 commit comments

Comments
 (0)