Skip to content
Open
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
16 changes: 9 additions & 7 deletions notebooks/08-llamaindex-react-agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
]
},
{
Expand Down Expand Up @@ -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}\")"
Expand Down Expand Up @@ -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}\")"
]
},
Expand Down
Loading