From 190b42850f227fa347da65dc3573622675b1f2bd Mon Sep 17 00:00:00 2001 From: ArrayPD Date: Thu, 13 Mar 2025 14:28:20 -0400 Subject: [PATCH] docs: Enhance get_weather() in create-react-agent-memory.ipynb (#3825) Since we are demonstrating thread-level memory not human-in-the-loop, a string is more straightforward and reliable than AssertionError(), when dealing with 'Unknown Location'. --- docs/docs/how-tos/create-react-agent-memory.ipynb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/docs/how-tos/create-react-agent-memory.ipynb b/docs/docs/how-tos/create-react-agent-memory.ipynb index b109db3a0..2c19130a9 100644 --- a/docs/docs/how-tos/create-react-agent-memory.ipynb +++ b/docs/docs/how-tos/create-react-agent-memory.ipynb @@ -122,20 +122,18 @@ "\n", "# For this tutorial we will use custom tool that returns pre-defined values for weather in two cities (NYC & SF)\n", "\n", - "from typing import Literal\n", - "\n", "from langchain_core.tools import tool\n", "\n", "\n", "@tool\n", - "def get_weather(city: Literal[\"nyc\", \"sf\"]):\n", + "def get_weather(location: str) -> str:\n", " \"\"\"Use this to get weather information.\"\"\"\n", - " if city == \"nyc\":\n", + " if any([city in location.lower() for city in [\"nyc\", \"new york city\"]]):\n", " return \"It might be cloudy in nyc\"\n", - " elif city == \"sf\":\n", + " elif any([city in location.lower() for city in [\"sf\", \"san francisco\"]]):\n", " return \"It's always sunny in sf\"\n", " else:\n", - " raise AssertionError(\"Unknown city\")\n", + " return f\"I am not sure what the weather is in {location}\"\n", "\n", "\n", "tools = [get_weather]\n",