|
41 | 41 | "## Short-term Memory\n", |
42 | 42 | "The agent tracks chat history using Redis through LangGraph's [checkpointer](https://github.com/redis-developer/langgraph-redis). Each node in the graph (Retrieve Memories, Respond, Summarize) saves its state to Redis, including conversation history and thread metadata.\n", |
43 | 43 | "\n", |
44 | | - "<img src=\"resources/short-term-memory.png\" style=\"width: 100%; max-width: 400px;\">\n", |
| 44 | + "<img src=\"https://github.com/redis-developer/redis-ai-resources/blob/feat/update-memory-agent-recipe/python-recipes/agents/resources/short-term-memory.png?raw=true\" style=\"width: 100%; max-width: 400px;\">\n", |
45 | 45 | "\n", |
46 | 46 | "To prevent context window pollution, the agent summarizes conversations when they exceed a configurable length.\n", |
47 | 47 | "\n", |
|
51 | 51 | "- **Episodic**: User preferences and experiences\n", |
52 | 52 | "- **Semantic**: General travel knowledge\n", |
53 | 53 | "\n", |
54 | | - "<img src=\"resources/long-term-memory.png\" style=\"width: 100%; max-width: 600px;\">\n", |
| 54 | + "<img src=\"https://github.com/redis-developer/redis-ai-resources/blob/feat/update-memory-agent-recipe/python-recipes/agents/resources/long-term-memory.png?raw=true\" style=\"width: 100%; max-width: 600px;\">\n", |
55 | 55 | "\n", |
56 | 56 | ">**NOTE**: These memory types align with the [CoALA](https://arxiv.org/abs/2309.02427) paper's concepts. Our agent's procedural memory is encoded in its Python workflow." |
57 | 57 | ] |
58 | 58 | }, |
| 59 | + { |
| 60 | + "cell_type": "markdown", |
| 61 | + "metadata": {}, |
| 62 | + "source": [ |
| 63 | + "## Let's Begin\n", |
| 64 | + "<a href=\"https://colab.research.google.com/github/redis-developer/redis-ai-resources/blob/main/python-recipes/agents/03_memory_agent.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" |
| 65 | + ] |
| 66 | + }, |
59 | 67 | { |
60 | 68 | "cell_type": "markdown", |
61 | 69 | "metadata": { |
|
79 | 87 | }, |
80 | 88 | "outputs": [], |
81 | 89 | "source": [ |
82 | | - "%pip install langchain-openai langgraph-checkpoint langgraph langgraph-checkpoint-redis langchain-redis" |
| 90 | + "%pip install langchain-openai langgraph-checkpoint langgraph langgraph-checkpoint-redis pydantic" |
83 | 91 | ] |
84 | 92 | }, |
85 | 93 | { |
|
143 | 151 | }, |
144 | 152 | "outputs": [], |
145 | 153 | "source": [ |
| 154 | + "# NBVAL_SKIP\n", |
| 155 | + "\n", |
146 | 156 | "%%sh\n", |
147 | 157 | "curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg\n", |
148 | 158 | "echo \"deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main\" | sudo tee /etc/apt/sources.list.d/redis.list\n", |
|
581 | 591 | }, |
582 | 592 | "outputs": [], |
583 | 593 | "source": [ |
584 | | - "\n", |
585 | | - "\n", |
586 | 594 | "from datetime import datetime\n", |
587 | 595 | "from typing import List, Optional, Union\n", |
588 | 596 | "\n", |
|
751 | 759 | "\n", |
752 | 760 | "> NOTE: **This tutorial uses tool-based memory** for optimal balance of control and efficiency.\n", |
753 | 761 | "\n", |
754 | | - "<img src=\"resources/memory-agents.png\" alt=\"Memory Agents Diagram\" width=\"250\">" |
| 762 | + "<img src=\"https://github.com/redis-developer/redis-ai-resources/blob/feat/update-memory-agent-recipe/python-recipes/agents/resources/memory-agents.png?raw=true\" alt=\"Memory Agents Diagram\" width=\"250\">" |
755 | 763 | ] |
756 | 764 | }, |
757 | 765 | { |
|
1145 | 1153 | }, |
1146 | 1154 | "outputs": [], |
1147 | 1155 | "source": [ |
1148 | | - "\n", |
1149 | 1156 | "from langchain_core.messages import HumanMessage\n", |
1150 | 1157 | "from langgraph.graph.message import MessagesState\n", |
1151 | 1158 | "\n", |
|
1727 | 1734 | } |
1728 | 1735 | ], |
1729 | 1736 | "source": [ |
| 1737 | + "# NBVAL_SKIP\n", |
| 1738 | + "\n", |
1730 | 1739 | "try:\n", |
1731 | 1740 | " user_id = input(\"Enter a user ID: \") or \"demo_user\"\n", |
1732 | 1741 | " thread_id = input(\"Enter a thread ID: \") or \"demo_thread\"\n", |
|
1780 | 1789 | } |
1781 | 1790 | ], |
1782 | 1791 | "source": [ |
| 1792 | + "# NBVAL_SKIP\n", |
1783 | 1793 | "res = retrieve_memories_tool.invoke({\"query\": \"Travel, activity, and dietary preferences\", \"memory_type\": [\"episodic\", \"semantic\"]})\n", |
1784 | 1794 | "res.split(\"\\n\")" |
1785 | 1795 | ] |
|
0 commit comments