mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-09 19:27:54 +02:00
docs: Tutorials up to date (#1734)
* edits * add js code to web voyager
This commit is contained in:
@@ -76,6 +76,375 @@
|
||||
"</div> "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Helper Files\n",
|
||||
"\n",
|
||||
"### Math Tools\n",
|
||||
"\n",
|
||||
"Place the following code in a file called `math_tools.py` and ensure that you can import it into this notebook.\n",
|
||||
"\n",
|
||||
"<div>\n",
|
||||
" <button type=\"button\" style=\"border: 1px solid black; border-radius: 5px; padding: 5px; background-color: lightgrey;\" onclick=\"toggleVisibility('helper-functions')\">Show/Hide Math Tools</button>\n",
|
||||
" <div id=\"helper-functions\" style=\"display:none;\">\n",
|
||||
" <!-- Helper functions -->\n",
|
||||
" <pre>\n",
|
||||
"\n",
|
||||
" import math\n",
|
||||
" import re\n",
|
||||
" from typing import List, Optional\n",
|
||||
"\n",
|
||||
" import numexpr\n",
|
||||
" from langchain.chains.openai_functions import create_structured_output_runnable\n",
|
||||
" from langchain_core.messages import SystemMessage\n",
|
||||
" from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
|
||||
" from langchain_core.runnables import RunnableConfig\n",
|
||||
" from langchain_core.tools import StructuredTool\n",
|
||||
" from langchain_openai import ChatOpenAI\n",
|
||||
" from pydantic import BaseModel, Field\n",
|
||||
"\n",
|
||||
" _MATH_DESCRIPTION = (\n",
|
||||
" \"math(problem: str, context: Optional[list[str]]) -> float:\\n\"\n",
|
||||
" \" - Solves the provided math problem.\\n\"\n",
|
||||
" ' - `problem` can be either a simple math problem (e.g. \"1 + 3\") or a word problem (e.g. \"how many apples are there if there are 3 apples and 2 apples\").\\n'\n",
|
||||
" \" - You cannot calculate multiple expressions in one call. For instance, `math('1 + 3, 2 + 4')` does not work. \"\n",
|
||||
" \"If you need to calculate multiple expressions, you need to call them separately like `math('1 + 3')` and then `math('2 + 4')`\\n\"\n",
|
||||
" \" - Minimize the number of `math` actions as much as possible. For instance, instead of calling \"\n",
|
||||
" '2. math(\"what is the 10% of $1\") and then call 3. math(\"$1 + $2\"), '\n",
|
||||
" 'you MUST call 2. math(\"what is the 110% of $1\") instead, which will reduce the number of math actions.\\n'\n",
|
||||
" # Context specific rules below\n",
|
||||
" \" - You can optionally provide a list of strings as `context` to help the agent solve the problem. \"\n",
|
||||
" \"If there are multiple contexts you need to answer the question, you can provide them as a list of strings.\\n\"\n",
|
||||
" \" - `math` action will not see the output of the previous actions unless you provide it as `context`. \"\n",
|
||||
" \"You MUST provide the output of the previous actions as `context` if you need to do math on it.\\n\"\n",
|
||||
" \" - You MUST NEVER provide `search` type action's outputs as a variable in the `problem` argument. \"\n",
|
||||
" \"This is because `search` returns a text blob that contains the information about the entity, not a number or value. \"\n",
|
||||
" \"Therefore, when you need to provide an output of `search` action, you MUST provide it as a `context` argument to `math` action. \"\n",
|
||||
" 'For example, 1. search(\"Barack Obama\") and then 2. math(\"age of $1\") is NEVER allowed. '\n",
|
||||
" 'Use 2. math(\"age of Barack Obama\", context=[\"$1\"]) instead.\\n'\n",
|
||||
" \" - When you ask a question about `context`, specify the units. \"\n",
|
||||
" 'For instance, \"what is xx in height?\" or \"what is xx in millions?\" instead of \"what is xx?\"\\n'\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" _SYSTEM_PROMPT = \"\"\"Translate a math problem into a expression that can be executed using Python's numexpr library. Use the output of running this code to answer the question.\n",
|
||||
"\n",
|
||||
" Question: ${{Question with math problem.}}\n",
|
||||
" ```text\n",
|
||||
" ${{single line mathematical expression that solves the problem}}\n",
|
||||
" ```\n",
|
||||
" ...numexpr.evaluate(text)...\n",
|
||||
" ```output\n",
|
||||
" ${{Output of running the code}}\n",
|
||||
" ```\n",
|
||||
" Answer: ${{Answer}}\n",
|
||||
"\n",
|
||||
" Begin.\n",
|
||||
"\n",
|
||||
" Question: What is 37593 * 67?\n",
|
||||
" ExecuteCode({{code: \"37593 * 67\"}})\n",
|
||||
" ...numexpr.evaluate(\"37593 * 67\")...\n",
|
||||
" ```output\n",
|
||||
" 2518731\n",
|
||||
" ```\n",
|
||||
" Answer: 2518731\n",
|
||||
"\n",
|
||||
" Question: 37593^(1/5)\n",
|
||||
" ExecuteCode({{code: \"37593**(1/5)\"}})\n",
|
||||
" ...numexpr.evaluate(\"37593**(1/5)\")...\n",
|
||||
" ```output\n",
|
||||
" 8.222831614237718\n",
|
||||
" ```\n",
|
||||
" Answer: 8.222831614237718\n",
|
||||
" \"\"\"\n",
|
||||
"\n",
|
||||
" _ADDITIONAL_CONTEXT_PROMPT = \"\"\"The following additional context is provided from other functions.\\\n",
|
||||
" Use it to substitute into any ${{#}} variables or other words in the problem.\\\n",
|
||||
" \\n\\n${context}\\n\\nNote that context variables are not defined in code yet.\\\n",
|
||||
" You must extract the relevant numbers and directly put them in code.\"\"\"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" class ExecuteCode(BaseModel):\n",
|
||||
" \"\"\"The input to the numexpr.evaluate() function.\"\"\"\n",
|
||||
"\n",
|
||||
" reasoning: str = Field(\n",
|
||||
" ...,\n",
|
||||
" description=\"The reasoning behind the code expression, including how context is included, if applicable.\",\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" code: str = Field(\n",
|
||||
" ...,\n",
|
||||
" description=\"The simple code expression to execute by numexpr.evaluate().\",\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" def _evaluate_expression(expression: str) -> str:\n",
|
||||
" try:\n",
|
||||
" local_dict = {\"pi\": math.pi, \"e\": math.e}\n",
|
||||
" output = str(\n",
|
||||
" numexpr.evaluate(\n",
|
||||
" expression.strip(),\n",
|
||||
" global_dict={}, # restrict access to globals\n",
|
||||
" local_dict=local_dict, # add common mathematical functions\n",
|
||||
" )\n",
|
||||
" )\n",
|
||||
" except Exception as e:\n",
|
||||
" raise ValueError(\n",
|
||||
" f'Failed to evaluate \"{expression}\". Raised error: {repr(e)}.'\n",
|
||||
" \" Please try again with a valid numerical expression\"\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # Remove any leading and trailing brackets from the output\n",
|
||||
" return re.sub(r\"^\\[|\\]$\", \"\", output)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" def get_math_tool(llm: ChatOpenAI):\n",
|
||||
" prompt = ChatPromptTemplate.from_messages(\n",
|
||||
" [\n",
|
||||
" (\"system\", _SYSTEM_PROMPT),\n",
|
||||
" (\"user\", \"{problem}\"),\n",
|
||||
" MessagesPlaceholder(variable_name=\"context\", optional=True),\n",
|
||||
" ]\n",
|
||||
" )\n",
|
||||
" extractor = prompt | llm.with_structured_output(ExecuteCode)\n",
|
||||
"\n",
|
||||
" def calculate_expression(\n",
|
||||
" problem: str,\n",
|
||||
" context: Optional[List[str]] = None,\n",
|
||||
" config: Optional[RunnableConfig] = None,\n",
|
||||
" ):\n",
|
||||
" chain_input = {\"problem\": problem}\n",
|
||||
" if context:\n",
|
||||
" context_str = \"\\n\".join(context)\n",
|
||||
" if context_str.strip():\n",
|
||||
" context_str = _ADDITIONAL_CONTEXT_PROMPT.format(\n",
|
||||
" context=context_str.strip()\n",
|
||||
" )\n",
|
||||
" chain_input[\"context\"] = [SystemMessage(content=context_str)]\n",
|
||||
" code_model = extractor.invoke(chain_input, config)\n",
|
||||
" try:\n",
|
||||
" return _evaluate_expression(code_model.code)\n",
|
||||
" except Exception as e:\n",
|
||||
" return repr(e)\n",
|
||||
"\n",
|
||||
" return StructuredTool.from_function(\n",
|
||||
" name=\"math\",\n",
|
||||
" func=calculate_expression,\n",
|
||||
" description=_MATH_DESCRIPTION,\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
"</pre>\n",
|
||||
" </div>\n",
|
||||
"</div>\n",
|
||||
"\n",
|
||||
"<script>\n",
|
||||
" function toggleVisibility(id) {\n",
|
||||
" var element = document.getElementById(id);\n",
|
||||
" element.style.display = (element.style.display === \"none\") ? \"block\" : \"none\";\n",
|
||||
" }\n",
|
||||
"</script>\n",
|
||||
"\n",
|
||||
"### Output Parser\n",
|
||||
"\n",
|
||||
"<div>\n",
|
||||
" <button type=\"button\" style=\"border: 1px solid black; border-radius: 5px; padding: 5px; background-color: lightgrey;\" onclick=\"toggleVisibility('helper-functions-2')\">Show/Hide Output Parser</button>\n",
|
||||
" <div id=\"helper-functions-2\" style=\"display:none;\">\n",
|
||||
" <!-- Helper functions -->\n",
|
||||
" <pre>\n",
|
||||
"\n",
|
||||
" import ast\n",
|
||||
" import re\n",
|
||||
" from typing import (\n",
|
||||
" Any,\n",
|
||||
" Dict,\n",
|
||||
" Iterator,\n",
|
||||
" List,\n",
|
||||
" Optional,\n",
|
||||
" Sequence,\n",
|
||||
" Tuple,\n",
|
||||
" Union,\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" from langchain_core.exceptions import OutputParserException\n",
|
||||
" from langchain_core.messages import BaseMessage\n",
|
||||
" from langchain_core.output_parsers.transform import BaseTransformOutputParser\n",
|
||||
" from langchain_core.runnables import RunnableConfig\n",
|
||||
" from langchain_core.tools import BaseTool\n",
|
||||
" from typing_extensions import TypedDict\n",
|
||||
"\n",
|
||||
" THOUGHT_PATTERN = r\"Thought: ([^\\n]*)\"\n",
|
||||
" ACTION_PATTERN = r\"\\n*(\\d+)\\. (\\w+)\\((.*)\\)(\\s*#\\w+\\n)?\"\n",
|
||||
" # $1 or ${1} -> 1\n",
|
||||
" ID_PATTERN = r\"\\$\\{?(\\d+)\\}?\"\n",
|
||||
" END_OF_PLAN = \"<END_OF_PLAN>\"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" ### Helper functions\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" def _ast_parse(arg: str) -> Any:\n",
|
||||
" try:\n",
|
||||
" return ast.literal_eval(arg)\n",
|
||||
" except: # noqa\n",
|
||||
" return arg\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" def _parse_llm_compiler_action_args(args: str, tool: Union[str, BaseTool]) -> list[Any]:\n",
|
||||
" \"\"\"Parse arguments from a string.\"\"\"\n",
|
||||
" if args == \"\":\n",
|
||||
" return ()\n",
|
||||
" if isinstance(tool, str):\n",
|
||||
" return ()\n",
|
||||
" extracted_args = {}\n",
|
||||
" tool_key = None\n",
|
||||
" prev_idx = None\n",
|
||||
" for key in tool.args.keys():\n",
|
||||
" # Split if present\n",
|
||||
" if f\"{key}=\" in args:\n",
|
||||
" idx = args.index(f\"{key}=\")\n",
|
||||
" if prev_idx is not None:\n",
|
||||
" extracted_args[tool_key] = _ast_parse(\n",
|
||||
" args[prev_idx:idx].strip().rstrip(\",\")\n",
|
||||
" )\n",
|
||||
" args = args.split(f\"{key}=\", 1)[1]\n",
|
||||
" tool_key = key\n",
|
||||
" prev_idx = 0\n",
|
||||
" if prev_idx is not None:\n",
|
||||
" extracted_args[tool_key] = _ast_parse(\n",
|
||||
" args[prev_idx:].strip().rstrip(\",\").rstrip(\")\")\n",
|
||||
" )\n",
|
||||
" return extracted_args\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" def default_dependency_rule(idx, args: str):\n",
|
||||
" matches = re.findall(ID_PATTERN, args)\n",
|
||||
" numbers = [int(match) for match in matches]\n",
|
||||
" return idx in numbers\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" def _get_dependencies_from_graph(\n",
|
||||
" idx: int, tool_name: str, args: Dict[str, Any]\n",
|
||||
" ) -> dict[str, list[str]]:\n",
|
||||
" \"\"\"Get dependencies from a graph.\"\"\"\n",
|
||||
" if tool_name == \"join\":\n",
|
||||
" return list(range(1, idx))\n",
|
||||
" return [i for i in range(1, idx) if default_dependency_rule(i, str(args))]\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" class Task(TypedDict):\n",
|
||||
" idx: int\n",
|
||||
" tool: BaseTool\n",
|
||||
" args: list\n",
|
||||
" dependencies: Dict[str, list]\n",
|
||||
" thought: Optional[str]\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" def instantiate_task(\n",
|
||||
" tools: Sequence[BaseTool],\n",
|
||||
" idx: int,\n",
|
||||
" tool_name: str,\n",
|
||||
" args: Union[str, Any],\n",
|
||||
" thought: Optional[str] = None,\n",
|
||||
" ) -> Task:\n",
|
||||
" if tool_name == \"join\":\n",
|
||||
" tool = \"join\"\n",
|
||||
" else:\n",
|
||||
" try:\n",
|
||||
" tool = tools[[tool.name for tool in tools].index(tool_name)]\n",
|
||||
" except ValueError as e:\n",
|
||||
" raise OutputParserException(f\"Tool {tool_name} not found.\") from e\n",
|
||||
" tool_args = _parse_llm_compiler_action_args(args, tool)\n",
|
||||
" dependencies = _get_dependencies_from_graph(idx, tool_name, tool_args)\n",
|
||||
"\n",
|
||||
" return Task(\n",
|
||||
" idx=idx,\n",
|
||||
" tool=tool,\n",
|
||||
" args=tool_args,\n",
|
||||
" dependencies=dependencies,\n",
|
||||
" thought=thought,\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" class LLMCompilerPlanParser(BaseTransformOutputParser[dict], extra=\"allow\"):\n",
|
||||
" \"\"\"Planning output parser.\"\"\"\n",
|
||||
"\n",
|
||||
" tools: List[BaseTool]\n",
|
||||
"\n",
|
||||
" def _transform(self, input: Iterator[Union[str, BaseMessage]]) -> Iterator[Task]:\n",
|
||||
" texts = []\n",
|
||||
" # TODO: Cleanup tuple state tracking here.\n",
|
||||
" thought = None\n",
|
||||
" for chunk in input:\n",
|
||||
" # Assume input is str. TODO: support vision/other formats\n",
|
||||
" text = chunk if isinstance(chunk, str) else str(chunk.content)\n",
|
||||
" for task, thought in self.ingest_token(text, texts, thought):\n",
|
||||
" yield task\n",
|
||||
" # Final possible task\n",
|
||||
" if texts:\n",
|
||||
" task, _ = self._parse_task(\"\".join(texts), thought)\n",
|
||||
" if task:\n",
|
||||
" yield task\n",
|
||||
"\n",
|
||||
" def parse(self, text: str) -> List[Task]:\n",
|
||||
" return list(self._transform([text]))\n",
|
||||
"\n",
|
||||
" def stream(\n",
|
||||
" self,\n",
|
||||
" input: str | BaseMessage,\n",
|
||||
" config: RunnableConfig | None = None,\n",
|
||||
" **kwargs: Any | None,\n",
|
||||
" ) -> Iterator[Task]:\n",
|
||||
" yield from self.transform([input], config, **kwargs)\n",
|
||||
"\n",
|
||||
" def ingest_token(\n",
|
||||
" self, token: str, buffer: List[str], thought: Optional[str]\n",
|
||||
" ) -> Iterator[Tuple[Optional[Task], str]]:\n",
|
||||
" buffer.append(token)\n",
|
||||
" if \"\\n\" in token:\n",
|
||||
" buffer_ = \"\".join(buffer).split(\"\\n\")\n",
|
||||
" suffix = buffer_[-1]\n",
|
||||
" for line in buffer_[:-1]:\n",
|
||||
" task, thought = self._parse_task(line, thought)\n",
|
||||
" if task:\n",
|
||||
" yield task, thought\n",
|
||||
" buffer.clear()\n",
|
||||
" buffer.append(suffix)\n",
|
||||
"\n",
|
||||
" def _parse_task(self, line: str, thought: Optional[str] = None):\n",
|
||||
" task = None\n",
|
||||
" if match := re.match(THOUGHT_PATTERN, line):\n",
|
||||
" # Optionally, action can be preceded by a thought\n",
|
||||
" thought = match.group(1)\n",
|
||||
" elif match := re.match(ACTION_PATTERN, line):\n",
|
||||
" # if action is parsed, return the task, and clear the buffer\n",
|
||||
" idx, tool_name, args, _ = match.groups()\n",
|
||||
" idx = int(idx)\n",
|
||||
" task = instantiate_task(\n",
|
||||
" tools=self.tools,\n",
|
||||
" idx=idx,\n",
|
||||
" tool_name=tool_name,\n",
|
||||
" args=args,\n",
|
||||
" thought=thought,\n",
|
||||
" )\n",
|
||||
" thought = None\n",
|
||||
" # Else it is just dropped\n",
|
||||
" return task, thought\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"</pre>\n",
|
||||
" </div>\n",
|
||||
"</div>\n",
|
||||
"\n",
|
||||
"<script>\n",
|
||||
" function toggleVisibility(id) {\n",
|
||||
" var element = document.getElementById(id);\n",
|
||||
" element.style.display = (element.style.display === \"none\") ? \"block\" : \"none\";\n",
|
||||
" }\n",
|
||||
"</script>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a61b48ee-8c6f-4863-913a-676f659287de",
|
||||
@@ -90,15 +459,13 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 47,
|
||||
"execution_count": 6,
|
||||
"id": "e7476bb2-1a51-42f6-b7ae-82a0300bbf84",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_community.tools.tavily_search import TavilySearchResults\n",
|
||||
"from langchain_openai import ChatOpenAI\n",
|
||||
"\n",
|
||||
"# Imported from the https://github.com/langchain-ai/langgraph/tree/main/examples/plan-and-execute repo\n",
|
||||
"from math_tools import get_math_tool\n",
|
||||
"\n",
|
||||
"_get_pass(\"TAVILY_API_KEY\")\n",
|
||||
@@ -114,7 +481,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 7,
|
||||
"id": "152eecf3-6bef-4718-af71-a0b3c5a3b009",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -124,7 +491,7 @@
|
||||
"'37'"
|
||||
]
|
||||
},
|
||||
"execution_count": 4,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -164,7 +531,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 78,
|
||||
"execution_count": 10,
|
||||
"id": "15dd9639-691f-4906-9012-83fd6e9ac126",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -228,7 +595,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 79,
|
||||
"execution_count": 11,
|
||||
"id": "45689d40-d8df-4316-a121-6ea9c87d2efe",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -287,7 +654,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 80,
|
||||
"execution_count": 12,
|
||||
"id": "bbdcb57b-5362-4b9e-88db-fb3fae443fb0",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -299,7 +666,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 81,
|
||||
"execution_count": 13,
|
||||
"id": "730490c6-6e3a-4173-82a1-9eb9d5eeff20",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -307,9 +674,9 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"description='tavily_search_results_json(query=\"the search query\") - a search engine.' max_results=1 {'query': 'current temperature in San Francisco'}\n",
|
||||
"description='tavily_search_results_json(query=\"the search query\") - a search engine.' max_results=1 api_wrapper=TavilySearchAPIWrapper(tavily_api_key=SecretStr('**********')) {'query': 'current temperature in San Francisco'}\n",
|
||||
"---\n",
|
||||
"name='math' description='math(problem: str, context: Optional[list[str]]) -> float:\\n - Solves the provided math problem.\\n - `problem` can be either a simple math problem (e.g. \"1 + 3\") or a word problem (e.g. \"how many apples are there if there are 3 apples and 2 apples\").\\n - You cannot calculate multiple expressions in one call. For instance, `math(\\'1 + 3, 2 + 4\\')` does not work. If you need to calculate multiple expressions, you need to call them separately like `math(\\'1 + 3\\')` and then `math(\\'2 + 4\\')`\\n - Minimize the number of `math` actions as much as possible. For instance, instead of calling 2. math(\"what is the 10% of $1\") and then call 3. math(\"$1 + $2\"), you MUST call 2. math(\"what is the 110% of $1\") instead, which will reduce the number of math actions.\\n - You can optionally provide a list of strings as `context` to help the agent solve the problem. If there are multiple contexts you need to answer the question, you can provide them as a list of strings.\\n - `math` action will not see the output of the previous actions unless you provide it as `context`. You MUST provide the output of the previous actions as `context` if you need to do math on it.\\n - You MUST NEVER provide `search` type action\\'s outputs as a variable in the `problem` argument. This is because `search` returns a text blob that contains the information about the entity, not a number or value. Therefore, when you need to provide an output of `search` action, you MUST provide it as a `context` argument to `math` action. For example, 1. search(\"Barack Obama\") and then 2. math(\"age of $1\") is NEVER allowed. Use 2. math(\"age of Barack Obama\", context=[\"$1\"]) instead.\\n - When you ask a question about `context`, specify the units. For instance, \"what is xx in height?\" or \"what is xx in millions?\" instead of \"what is xx?\"' args_schema=<class 'pydantic.v1.main.mathSchema'> func=<function get_math_tool.<locals>.calculate_expression at 0x14e1049a0> {'problem': 'x^3', 'context': ['$1']}\n",
|
||||
"name='math' description='math(problem: str, context: Optional[list[str]]) -> float:\\n - Solves the provided math problem.\\n - `problem` can be either a simple math problem (e.g. \"1 + 3\") or a word problem (e.g. \"how many apples are there if there are 3 apples and 2 apples\").\\n - You cannot calculate multiple expressions in one call. For instance, `math(\\'1 + 3, 2 + 4\\')` does not work. If you need to calculate multiple expressions, you need to call them separately like `math(\\'1 + 3\\')` and then `math(\\'2 + 4\\')`\\n - Minimize the number of `math` actions as much as possible. For instance, instead of calling 2. math(\"what is the 10% of $1\") and then call 3. math(\"$1 + $2\"), you MUST call 2. math(\"what is the 110% of $1\") instead, which will reduce the number of math actions.\\n - You can optionally provide a list of strings as `context` to help the agent solve the problem. If there are multiple contexts you need to answer the question, you can provide them as a list of strings.\\n - `math` action will not see the output of the previous actions unless you provide it as `context`. You MUST provide the output of the previous actions as `context` if you need to do math on it.\\n - You MUST NEVER provide `search` type action\\'s outputs as a variable in the `problem` argument. This is because `search` returns a text blob that contains the information about the entity, not a number or value. Therefore, when you need to provide an output of `search` action, you MUST provide it as a `context` argument to `math` action. For example, 1. search(\"Barack Obama\") and then 2. math(\"age of $1\") is NEVER allowed. Use 2. math(\"age of Barack Obama\", context=[\"$1\"]) instead.\\n - When you ask a question about `context`, specify the units. For instance, \"what is xx in height?\" or \"what is xx in millions?\" instead of \"what is xx?\"' args_schema=<class 'langchain_core.utils.pydantic.math'> func=<function get_math_tool.<locals>.calculate_expression at 0x11bed0fe0> {'problem': 'x ** 3', 'context': ['$1']}\n",
|
||||
"---\n",
|
||||
"join ()\n",
|
||||
"---\n"
|
||||
@@ -353,7 +720,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 82,
|
||||
"execution_count": 14,
|
||||
"id": "c1fbafdd-42d4-4575-8466-e5951cee71f4",
|
||||
"metadata": {
|
||||
"jp-MarkdownHeadingCollapsed": true
|
||||
@@ -524,7 +891,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 83,
|
||||
"execution_count": 15,
|
||||
"id": "052f6b16-103a-40e9-94dd-8fcc37e77ba4",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -563,7 +930,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 84,
|
||||
"execution_count": 16,
|
||||
"id": "55142257-2674-4a47-988e-0d2810917329",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -573,19 +940,19 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 85,
|
||||
"execution_count": 17,
|
||||
"id": "a98e0525-2fcf-4fa1-baf6-79858bb8a6bd",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[FunctionMessage(content=\"[{'url': 'https://www.wunderground.com/weather/us/ca/san-francisco', 'content': 'Current Weather for Popular Cities . San Francisco, CA 82 ° F Sunny; Manhattan, NY warning 84 ° F Sunny; Schiller Park, IL (60176) warning 97 ° F Mostly Cloudy; Boston, MA warning 74 ° F ...'}]\", additional_kwargs={'idx': 1, 'args': {'query': 'current temperature in San Francisco'}}, name='tavily_search_results_json', tool_call_id=1),\n",
|
||||
" FunctionMessage(content='551368', additional_kwargs={'idx': 2, 'args': {'problem': 'x ** 3', 'context': ['$1']}}, name='math', tool_call_id=2),\n",
|
||||
" FunctionMessage(content='join', additional_kwargs={'idx': 3, 'args': ()}, name='join', tool_call_id=3)]"
|
||||
"[FunctionMessage(content=\"[{'url': 'https://www.accuweather.com/en/us/san-francisco/94103/current-weather/347629', 'content': 'Get the latest weather information for San Francisco, CA, including temperature, wind, humidity, pressure, and UV index. See hourly, daily, and monthly forecasts, as ...'}]\", additional_kwargs={'idx': 1, 'args': {'query': 'current temperature in San Francisco'}}, response_metadata={}, name='tavily_search_results_json', tool_call_id=1),\n",
|
||||
" FunctionMessage(content='ValueError(\\'Failed to evaluate \"No specific value for \\\\\\'x\\\\\\' provided.\". Raised error: SyntaxError(\\\\\\'invalid syntax\\\\\\', (\\\\\\'<expr>\\\\\\', 1, 4, \"No specific value for \\\\\\'x\\\\\\' provided.\", 1, 12)). Please try again with a valid numerical expression\\')', additional_kwargs={'idx': 2, 'args': {'problem': 'x^3', 'context': ['$1']}}, response_metadata={}, name='math', tool_call_id=2),\n",
|
||||
" FunctionMessage(content='join', additional_kwargs={'idx': 3, 'args': ()}, response_metadata={}, name='join', tool_call_id=3)]"
|
||||
]
|
||||
},
|
||||
"execution_count": 85,
|
||||
"execution_count": 17,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -611,7 +978,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 86,
|
||||
"execution_count": 18,
|
||||
"id": "942dab42-ad42-4ba2-90d5-49edbe4fae68",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -661,7 +1028,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 87,
|
||||
"execution_count": 19,
|
||||
"id": "951a33cf-2a05-4a33-899a-0ab1d97122fa",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -694,7 +1061,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 88,
|
||||
"execution_count": 20,
|
||||
"id": "1e49d4b1-8266-4520-a566-1448b1c31c8f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -704,18 +1071,18 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 89,
|
||||
"execution_count": 21,
|
||||
"id": "31854dfd-b82f-4c24-9b58-6bae66777909",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'messages': [AIMessage(content=\"Thought: We have the current temperature in San Francisco (82 °F) and have calculated the temperature raised to the 3rd power (551368). Therefore, we can provide an answer to the user's question.\"),\n",
|
||||
" AIMessage(content='The temperature in San Francisco raised to the 3rd power is 551368.')]}"
|
||||
"{'messages': [AIMessage(content='Thought: Since the temperature in San Francisco was not provided, I cannot calculate its value raised to the 3rd power. The search result did not include specific temperature information, and the subsequent action to calculate the power raised the error due to lack of numerical input.', additional_kwargs={}, response_metadata={}),\n",
|
||||
" SystemMessage(content=\"Context from last attempt: To answer the user's question, we need the current temperature in San Francisco. Please include a step to find the current temperature in San Francisco and then calculate its value raised to the 3rd power.\", additional_kwargs={}, response_metadata={})]}"
|
||||
]
|
||||
},
|
||||
"execution_count": 89,
|
||||
"execution_count": 21,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -740,7 +1107,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 90,
|
||||
"execution_count": 22,
|
||||
"id": "768b5f11-e3d2-47be-8143-a7dcd8765243",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -797,7 +1164,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 91,
|
||||
"execution_count": 23,
|
||||
"id": "5bc4584a-e31c-4065-805e-76a6db30676a",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -805,9 +1172,9 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"{'plan_and_schedule': {'messages': [FunctionMessage(content=\"[{'url': 'https://www.investopedia.com/articles/investing/011516/new-yorks-economy-6-industries-driving-gdp-growth.asp', 'content': 'The manufacturing sector is a leader in railroad rolling stock, as many of the earliest railroads were financed or founded in New York; garments, as New York City is the fashion capital of the U.S.; elevator parts; glass; and many other products.\\\\n Educational Services\\\\nThough not typically thought of as a leading industry, the educational sector in New York nonetheless has a substantial impact on the state and its residents, and in attracting new talent that eventually enters the New York business scene. New York has seen a large uptick in college attendees, both young and old, over the 21st century, and an increasing number of new employees in other New York sectors were educated in the state. New York City is the leading job hub for banking, finance, and communication in the U.S. New York is also a major manufacturing center and shipping port, and it has a thriving technological sector.\\\\n The state of New York has the third-largest economy in the United States with a gross domestic product (GDP) of $1.7 trillion, trailing only Texas and California.'}]\", additional_kwargs={'idx': 1, 'args': {'query': 'GDP of New York'}}, name='tavily_search_results_json', tool_call_id=1)]}}\n",
|
||||
"{'plan_and_schedule': {'messages': [FunctionMessage(content=\"[{'url': 'https://www.investopedia.com/articles/investing/011516/new-yorks-economy-6-industries-driving-gdp-growth.asp', 'content': 'The manufacturing sector is a leader in railroad rolling stock, as many of the earliest railroads were financed or founded in New York; garments, as New York City is the fashion capital of the U.S.; elevator parts; glass; and many other products.\\\\n Educational Services\\\\nThough not typically thought of as a leading industry, the educational sector in New York nonetheless has a substantial impact on the state and its residents, and in attracting new talent that eventually enters the New York business scene. New York has seen a large uptick in college attendees, both young and old, over the 21st century, and an increasing number of new employees in other New York sectors were educated in the state. New York City is the leading job hub for banking, finance, and communication in the U.S. New York is also a major manufacturing center and shipping port, and it has a thriving technological sector.\\\\n The state of New York has the third-largest economy in the United States with a gross domestic product (GDP) of $1.7 trillion, trailing only Texas and California.'}]\", additional_kwargs={'idx': 1, 'args': {'query': 'GDP of New York'}}, response_metadata={}, name='tavily_search_results_json', tool_call_id=1)]}}\n",
|
||||
"---\n",
|
||||
"{'join': {'messages': [AIMessage(content=\"Thought: The information required to answer the user's question has been found. The GDP of New York is mentioned as $1.7 trillion, making it the third-largest economy in the United States.\", id='d656a605-e4c4-470d-9b29-31794f298a71'), AIMessage(content='The GDP of New York is $1.7 trillion, making it the third-largest economy in the United States.', id='5135758e-d01e-4360-bb6a-31025b723d8c')]}}\n",
|
||||
"{'join': {'messages': [AIMessage(content='Thought: The search result provides the specific information requested. It states that the state of New York has the third-largest economy in the United States with a GDP of $1.7 trillion.', additional_kwargs={}, response_metadata={}, id='63af07a6-f931-43e9-8fdc-4f2b8c7b7663'), AIMessage(content='The GDP of New York is $1.7 trillion.', additional_kwargs={}, response_metadata={}, id='7cfc50e6-e041-4985-a5f4-ebf2e097826e')]}}\n",
|
||||
"---\n"
|
||||
]
|
||||
}
|
||||
@@ -822,7 +1189,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 92,
|
||||
"execution_count": 24,
|
||||
"id": "b96efd08-5314-44f0-a694-3073b638adad",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -830,7 +1197,7 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"The GDP of New York is $1.7 trillion, making it the third-largest economy in the United States.\n"
|
||||
"The GDP of New York is $1.7 trillion.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -851,7 +1218,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 93,
|
||||
"execution_count": 25,
|
||||
"id": "0b3a0916-d8ca-4092-b91c-d9e2b05259d8",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -859,9 +1226,9 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"{'plan_and_schedule': {'messages': [FunctionMessage(content='[{\\'url\\': \\'https://en.wikipedia.org/wiki/Cookie_(cockatoo)\\', \\'content\\': \\'He was one of the longest-lived birds on record[4] and was recognised by the Guinness World Records as the oldest living parrot in the world.[5]\\\\nThe next-oldest pink cockatoo to be found in a zoological setting was a 31-year-old female bird located at Paradise Wildlife Sanctuary, England.[3] Information published by the World Parrot Trust states longevity for Cookie\\\\\\'s species in captivity is on average 40–60 years.[6]\\\\nLife[edit]\\\\nCookie was Brookfield Zoo\\\\\\'s oldest resident and the last surviving member of the animal collection from the time of the zoo\\\\\\'s opening in 1934, having arrived from Taronga Zoo of Sydney, New South Wales, Australia, in the same year and judged to be one year old at the time.[7]\\\\nIn the 1950s an attempt was made to introduce Cookie to a female pink cockatoo, but Cookie rejected her as \"she was not nice to him\".[8]\\\\n In 2007, Cookie was diagnosed with, and placed on medication and nutritional supplements for, osteoarthritis and osteoporosis\\\\xa0– medical conditions which occur commonly in aging animals and humans alike,[7] although it is believed that the latter may also have been brought on as a result of being fed a seed-only diet for the first 40 years of his life, in the years before the dietary requirements of his species were fully understood.[9]\\\\nCookie was \"retired\" from exhibition at the zoo in 2009 (following a few months of weekend-only appearances) in order to preserve his health, after it was noticed by staff that his appetite, demeanor and stress levels improved markedly when not on public display. age.[11] A memorial at the zoo was unveiled in September 2017.[12]\\\\nIn 2020, Cookie became the subject of a poetry collection by Barbara Gregorich entitled Cookie the Cockatoo: Everything Changes.[13]\\\\nSee also[edit]\\\\nReferences[edit]\\\\nExternal links[edit] He was believed to be the oldest member of his species alive in captivity, at the age of 82 in June 2015,[1][2] having significantly exceeded the average lifespan for his kind.[3] He was moved to a permanent residence in the keepers\\\\\\' office of the zoo\\\\\\'s Perching Bird House, although he made occasional appearances for special events, such as his birthday celebration, which was held each June.[3]\\'}]', additional_kwargs={'idx': 1, 'args': {'query': 'oldest parrot alive'}}, name='tavily_search_results_json', tool_call_id=1), FunctionMessage(content='[{\\'url\\': \\'https://www.thesprucepets.com/how-long-do-parrots-and-other-pet-birds-live-1238433\\', \\'content\\': \"It\\'s possible that a pet bird can outlive its owners\\\\nThe Spruce / Adrienne Legault\\\\nParrots and other birds can live up to 10 to 50 years or more depending on the type and the conditions they live in. They vary in size from small birds that can fit in the palm of your hand to large birds the size of a cat and their lifespans are just as variable.\\\\n Also, for birds who live longer some owners have to make a plan of where the bird is going in the circumstance the bird outlives the owner.\\\\n In reality, there is a wide range in the age that pet birds might reach and certainly, some will live longer (or shorter amounts of time) than the ages listed.\\\\n Potential owners need to be aware of the longevity of their bird so they can be prepared to provide proper care for them for as long as they live.\\\\n\"}]', additional_kwargs={'idx': 2, 'args': {'query': 'average lifespan of a parrot'}}, name='tavily_search_results_json', tool_call_id=2), FunctionMessage(content='join', additional_kwargs={'idx': 3, 'args': ()}, name='join', tool_call_id=3)]}}\n",
|
||||
"{'plan_and_schedule': {'messages': [FunctionMessage(content='[{\\'url\\': \\'https://en.wikipedia.org/wiki/Cookie_(cockatoo)\\', \\'content\\': \\'He was one of the longest-lived birds on record[4] and was recognised by the Guinness World Records as the oldest living parrot in the world.[5]\\\\nThe next-oldest pink cockatoo to be found in a zoological setting was a 31-year-old female bird located at Paradise Wildlife Sanctuary, England.[3] Information published by the World Parrot Trust states longevity for Cookie\\\\\\'s species in captivity is on average 40–60 years.[6]\\\\nLife[edit]\\\\nCookie was Brookfield Zoo\\\\\\'s oldest resident and the last surviving member of the animal collection from the time of the zoo\\\\\\'s opening in 1934, having arrived from Taronga Zoo of Sydney, New South Wales, Australia, in the same year and judged to be one year old at the time.[7]\\\\nIn the 1950s an attempt was made to introduce Cookie to a female pink cockatoo, but Cookie rejected her as \"she was not nice to him\".[8]\\\\n In 2007, Cookie was diagnosed with, and placed on medication and nutritional supplements for, osteoarthritis and osteoporosis\\\\xa0– medical conditions which occur commonly in aging animals and humans alike,[7] although it is believed that the latter may also have been brought on as a result of being fed a seed-only diet for the first 40 years of his life, in the years before the dietary requirements of his species were fully understood.[9]\\\\nCookie was \"retired\" from exhibition at the zoo in 2009 (following a few months of weekend-only appearances) in order to preserve his health, after it was noticed by staff that his appetite, demeanor and stress levels improved markedly when not on public display. age.[11] A memorial at the zoo was unveiled in September 2017.[12]\\\\nIn 2020, Cookie became the subject of a poetry collection by Barbara Gregorich entitled Cookie the Cockatoo: Everything Changes.[13]\\\\nSee also[edit]\\\\nReferences[edit]\\\\nExternal links[edit] He was believed to be the oldest member of his species alive in captivity, at the age of 82 in June 2015,[1][2] having significantly exceeded the average lifespan for his kind.[3] He was moved to a permanent residence in the keepers\\\\\\' office of the zoo\\\\\\'s Perching Bird House, although he made occasional appearances for special events, such as his birthday celebration, which was held each June.[3]\\'}]', additional_kwargs={'idx': 1, 'args': {'query': 'oldest parrot alive'}}, response_metadata={}, name='tavily_search_results_json', tool_call_id=1), FunctionMessage(content=\"[{'url': 'https://www.birdzilla.com/learn/how-long-do-parrots-live/', 'content': 'In captivity, they can easily live to be ten or even 18 years of age. In general, most wild parrot species live only half the numbers of years they would live in captivity. For example, adopted African Gray Parrots might live to be 60, whereas wild birds have an average lifespan of 30 or 40 at the very most.'}]\", additional_kwargs={'idx': 2, 'args': {'query': 'average lifespan of a parrot'}}, response_metadata={}, name='tavily_search_results_json', tool_call_id=2), FunctionMessage(content='join', additional_kwargs={'idx': 3, 'args': ()}, response_metadata={}, name='join', tool_call_id=3)]}}\n",
|
||||
"---\n",
|
||||
"{'join': {'messages': [AIMessage(content=\"Thought: We have information on Cookie, the cockatoo, who was recognized as the oldest living parrot at 82 years old in June 2015. This significantly exceeds the average lifespan for his kind, which is stated to be 40-60 years. The second source provides a general lifespan range for parrots and other birds, which is 10-50 years. However, this range varies significantly depending on the species and conditions. Since Cookie's specific lifespan far exceeds the average for his species and falls outside the general range for parrots, we can answer the user's question.\", id='51a280ac-2327-40c5-a27a-c821697d5a4b'), AIMessage(content='The oldest parrot recorded was Cookie, a cockatoo, who lived to be 82 years old in June 2015. This is significantly longer than the average lifespan for his species, which is 40-60 years, and also exceeds the general lifespan range for parrots, which can vary from 10 to 50 years. Therefore, Cookie lived 22 to 42 years longer than the average lifespan for his species.', id='139ecedf-b090-4197-88c0-0fa39883b392')]}}\n",
|
||||
"{'join': {'messages': [AIMessage(content=\"Thought: The information from Wikipedia about Cookie, the cockatoo, indicates that he was recognized as the oldest living parrot, reaching the age of 82. This significantly exceeds the average lifespan for his species, which is noted to be 40-60 years in captivity. The information from Birdzilla provides a more general perspective on parrot lifespans, indicating that, in captivity, parrots can easily live to be ten or even 18 years of age, with some species like the African Gray Parrot potentially living up to 60 years. However, it does not provide a specific average lifespan for all parrot species, making it challenging to provide a precise comparison for Cookie's age beyond his species' average lifespan.\", additional_kwargs={}, response_metadata={}, id='f00a464e-c273-42b9-8d1b-edd27bde8687'), AIMessage(content=\"Cookie the cockatoo was recognized as the oldest living parrot, reaching the age of 82, which is significantly beyond the average lifespan for his species, noted to be between 40-60 years in captivity. While general information for parrots suggests varying lifespans with some capable of living up to 60 years in captivity, Cookie's age far exceeded these averages, highlighting his exceptional longevity.\", additional_kwargs={}, response_metadata={}, id='dc62a826-5528-446e-8797-6854abdeb94c')]}}\n",
|
||||
"---\n"
|
||||
]
|
||||
}
|
||||
@@ -885,7 +1252,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 94,
|
||||
"execution_count": 26,
|
||||
"id": "6c65c414-7668-4fdf-ba97-f42f659b1317",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -893,7 +1260,7 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"The oldest parrot recorded was Cookie, a cockatoo, who lived to be 82 years old in June 2015. This is significantly longer than the average lifespan for his species, which is 40-60 years, and also exceeds the general lifespan range for parrots, which can vary from 10 to 50 years. Therefore, Cookie lived 22 to 42 years longer than the average lifespan for his species.\n"
|
||||
"Cookie the cockatoo was recognized as the oldest living parrot, reaching the age of 82, which is significantly beyond the average lifespan for his species, noted to be between 40-60 years in captivity. While general information for parrots suggests varying lifespans with some capable of living up to 60 years in captivity, Cookie's age far exceeded these averages, highlighting his exceptional longevity.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -912,7 +1279,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 96,
|
||||
"execution_count": 27,
|
||||
"id": "38d3ea91-59ba-4267-8060-ed75bbc840c6",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -920,8 +1287,8 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"{'plan_and_schedule': {'messages': [FunctionMessage(content='3307.0', additional_kwargs={'idx': 1, 'args': {'problem': '((3*(4+5)/0.5)+3245) + 8'}}, name='math', tool_call_id=1), FunctionMessage(content='7.565011820330969', additional_kwargs={'idx': 2, 'args': {'problem': '32/4.23'}}, name='math', tool_call_id=2), FunctionMessage(content='join', additional_kwargs={'idx': 3, 'args': ()}, name='join', tool_call_id=3)]}}\n",
|
||||
"{'join': {'messages': [AIMessage(content=\"Thought: The calculations for both individual questions have been provided: 3307.0 for the first equation and 7.565011820330969 for the second. To answer the user's final question, we need to sum these two values.\", id='96eb85f5-831f-434e-83d8-59deeebce05d'), AIMessage(content='The result of the first calculation is 3307.0, and the result of the second calculation is approximately 7.57. The sum of those two values is approximately 3314.57.', id='671a1a08-4725-4f98-997a-848815d61aa5')]}}\n"
|
||||
"{'plan_and_schedule': {'messages': [FunctionMessage(content='3307.0', additional_kwargs={'idx': 1, 'args': {'problem': '((3*(4+5)/0.5)+3245) + 8'}}, response_metadata={}, name='math', tool_call_id=1), FunctionMessage(content='7.565011820330969', additional_kwargs={'idx': 2, 'args': {'problem': '32/4.23'}}, response_metadata={}, name='math', tool_call_id=2), FunctionMessage(content='join', additional_kwargs={'idx': 3, 'args': ()}, response_metadata={}, name='join', tool_call_id=3)]}}\n",
|
||||
"{'join': {'messages': [AIMessage(content=\"Thought: The calculations for both the expressions provided by the user have been successfully completed, with the results being 3307.0 for the first expression and 7.565011820330969 for the second. Therefore, we have all the necessary information to answer the user's question.\", additional_kwargs={}, response_metadata={}, id='2dd394b3-468a-4abc-b7d2-02f7b803a8b6'), AIMessage(content='The result of the first calculation ((3*(4+5)/0.5)+3245) + 8 is 3307.0, and the result of the second calculation (32/4.23) is approximately 7.57. The sum of those two values is 3307.0 + 7.57 = approximately 3314.57.', additional_kwargs={}, response_metadata={}, id='83eb8e01-7a0a-4f79-8475-fad5bc83e645')]}}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -938,7 +1305,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 97,
|
||||
"execution_count": 28,
|
||||
"id": "a6cf5fe0-f178-4197-950f-257711bff8d2",
|
||||
"metadata": {
|
||||
"scrolled": true
|
||||
@@ -948,7 +1315,7 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"The result of the first calculation is 3307.0, and the result of the second calculation is approximately 7.57. The sum of those two values is approximately 3314.57.\n"
|
||||
"The result of the first calculation ((3*(4+5)/0.5)+3245) + 8 is 3307.0, and the result of the second calculation (32/4.23) is approximately 7.57. The sum of those two values is 3307.0 + 7.57 = approximately 3314.57.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -969,7 +1336,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 29,
|
||||
"id": "391d6931",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -977,12 +1344,8 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"{'plan_and_schedule': {'messages': [FunctionMessage(content=\"[{'url': 'https://www.timeanddate.com/weather/japan/tokyo', 'content': '88 / 84 °F. 13. 87 / 82 °F. 14. 84 / 80 °F. Detailed forecast for 14 days. Need some help? Current weather in Tokyo and forecast for today, tomorrow, and next 14 days.'}]\", additional_kwargs={'idx': 1, 'args': {'query': 'current temperature in Tokyo'}}, name='tavily_search_results_json', tool_call_id=1), FunctionMessage(content='join', additional_kwargs={'idx': 2, 'args': ()}, name='join', tool_call_id=2)]}}\n",
|
||||
"{'join': {'messages': [AIMessage(content=\"Thought: The search result provides the current temperature in Tokyo but does not explicitly state which temperature (88 / 84 °F) corresponds to the current condition. It seems to be a range, possibly the day's high and low. Without a clear indication of the exact current temperature, it's challenging to provide a precise flashcard summary.\", id='8ef2a131-69db-4180-a76e-fd9d6f4037c1'), SystemMessage(content='Context from last attempt: The information provided does not explicitly state the current temperature in Tokyo; it provides a temperature range without specifying which is the current temperature. Need to find a source that gives the exact current temperature in Tokyo for a precise flashcard summary.', id='f5bd752c-b068-459a-8d9e-bd1f1b5fa4fe')]}}\n",
|
||||
"{'plan_and_schedule': {'messages': [FunctionMessage(content='join', additional_kwargs={'idx': 3, 'args': ()}, name='join', tool_call_id=3)]}}\n",
|
||||
"{'join': {'messages': [AIMessage(content=\"Thought: The search result provides a temperature range for Tokyo but does not specify the current temperature. This makes it challenging to create a precise flashcard without an exact current temperature. The user's request cannot be fully satisfied without this detail.\", id='3cc41891-4f47-4453-8edf-b989926ab25e'), SystemMessage(content='Context from last attempt: The search did not provide an exact current temperature for Tokyo, making it impossible to create a precise flashcard. A source that explicitly states the current temperature is needed for an accurate response.', id='96290b41-a4c4-4ab5-829a-89cc31dfe6c8')]}}\n",
|
||||
"{'plan_and_schedule': {'messages': [FunctionMessage(content='join', additional_kwargs={'idx': 4, 'args': ()}, name='join', tool_call_id=4)]}}\n",
|
||||
"{'join': {'messages': [AIMessage(content=\"Thought: The search result provides a temperature range for Tokyo but does not specify the current temperature. This makes it challenging to create a precise flashcard without an exact current temperature. The user's request cannot be fully satisfied without this detail.\", id='4724b242-ddb8-47e6-b235-de25de54fe45'), AIMessage(content='I was unable to find the exact current temperature in Tokyo. However, the temperature range for today in Tokyo is between 88°F and 84°F. For the most accurate and up-to-date temperature, I recommend checking a reliable weather forecasting website or app.', id='40e29a47-a001-4f65-a18f-65c2931d1ae5')]}}\n"
|
||||
"{'plan_and_schedule': {'messages': [FunctionMessage(content=\"[{'url': 'https://www.timeanddate.com/weather/japan/tokyo/ext', 'content': 'Tokyo 14 Day Extended Forecast. Weather Today Weather Hourly 14 Day Forecast Yesterday/Past Weather Climate (Averages) Currently: 84 °F. Partly sunny. (Weather station: Tokyo, Japan). See more current weather.'}]\", additional_kwargs={'idx': 1, 'args': {'query': 'current temperature in Tokyo'}}, response_metadata={}, name='tavily_search_results_json', tool_call_id=1), FunctionMessage(content='join', additional_kwargs={'idx': 2, 'args': ()}, response_metadata={}, name='join', tool_call_id=2)]}}\n",
|
||||
"{'join': {'messages': [AIMessage(content='Thought: The extracted information provides the current temperature in Tokyo, which is 84 °F and describes the weather as partly sunny. This information is sufficient to create a flashcard summary for the user.', additional_kwargs={}, response_metadata={}, id='e9a1af40-ca06-4eb8-b4bb-24429cf8c689'), AIMessage(content='**Flashcard: Current Temperature in Tokyo**\\n\\n- **Temperature:** 84 °F\\n- **Weather Conditions:** Partly sunny\\n\\n*Note: This information is based on the latest available data and may change.*', additional_kwargs={}, response_metadata={}, id='92bb42bc-e9b9-4b98-8936-8f74ff111504')]}}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user