diff --git a/notebooks/08-llamaindex-react-agent.ipynb b/notebooks/08-llamaindex-react-agent.ipynb index 1e15597..c046537 100644 --- a/notebooks/08-llamaindex-react-agent.ipynb +++ b/notebooks/08-llamaindex-react-agent.ipynb @@ -123,7 +123,7 @@ "from llama_index.core.agent import ReActAgent\n", "\n", "\n", - "def create_memory_agent(user_id: str) -> ReActAgent:\n", + "def create_memory_agent(user_id: str) -> tuple[ReActAgent, HindsightMemory]:\n", " \"\"\"Create a ReAct agent with automatic per-user memory.\"\"\"\n", " memory = HindsightMemory.from_client(\n", " client=client,\n", @@ -133,13 +133,14 @@ " context=\"llamaindex-cookbook\",\n", " )\n", "\n", - " return ReActAgent(\n", + " agent = ReActAgent(\n", " tools=[], # No memory tools needed — memory is automatic\n", " llm=OpenAI(model=\"gpt-4o-mini\"),\n", - " memory=memory,\n", " system_prompt=\"You are a helpful assistant. Answer questions using your memory of past conversations.\",\n", " verbose=True,\n", - " )" + " )\n", + "\n", + " return agent, memory" ] }, { @@ -172,10 +173,11 @@ "metadata": {}, "outputs": [], "source": [ - "agent = create_memory_agent(\"alice\")\n", + "agent, memory = create_memory_agent(\"alice\")\n", "response = await agent.run(\n", " \"Hi! I'm Alice. I'm a data scientist who works with Python and SQL. \"\n", " \"I prefer dark mode and use VS Code.\",\n", + " memory=memory,\n", " max_iterations=10,\n", ")\n", "print(f\"\\nAgent: {response}\")" @@ -210,8 +212,8 @@ "metadata": {}, "outputs": [], "source": [ - "agent = create_memory_agent(\"alice\")\n", - "response = await agent.run(\"What IDE do I use? And what's my job?\", max_iterations=10)\n", + "agent, memory = create_memory_agent(\"alice\")\n", + "response = await agent.run(\"What IDE do I use? And what's my job?\", memory=memory, max_iterations=10)\n", "print(f\"\\nAgent: {response}\")" ] },