From 791452583d2d41b9d064385baae678877539ec26 Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:35:48 +0000 Subject: [PATCH 01/27] implement multihop agent --- .../cohere/docs/cohere_multihop_agent.ipynb | 229 ++++++++++ .../cohere/docs/multi_hop_agent.ipynb | 408 ++++++++++++++++++ .../cohere/langchain_cohere/__init__.py | 2 + .../langchain_cohere/multi_hop/__init__.py | 0 .../langchain_cohere/multi_hop/agent.py | 223 ++++++++++ .../langchain_cohere/multi_hop/prompt.py | 83 ++++ 6 files changed, 945 insertions(+) create mode 100644 libs/partners/cohere/docs/cohere_multihop_agent.ipynb create mode 100644 libs/partners/cohere/docs/multi_hop_agent.ipynb create mode 100644 libs/partners/cohere/langchain_cohere/multi_hop/__init__.py create mode 100644 libs/partners/cohere/langchain_cohere/multi_hop/agent.py create mode 100644 libs/partners/cohere/langchain_cohere/multi_hop/prompt.py diff --git a/libs/partners/cohere/docs/cohere_multihop_agent.ipynb b/libs/partners/cohere/docs/cohere_multihop_agent.ipynb new file mode 100644 index 0000000000000..e50ce4d1f0610 --- /dev/null +++ b/libs/partners/cohere/docs/cohere_multihop_agent.ipynb @@ -0,0 +1,229 @@ +{ + "cells": [ + { + "cell_type": "raw", + "metadata": {}, + "source": [ + "---\n", + "sidebar_position: 0\n", + "---" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Cohere Tools\n", + "\n", + "The following notebook goes over how to use the Cohere tools agent:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Prerequisites for this notebook:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: langchain-cohere in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (0.1.0rc0)\n", + "Requirement already satisfied: cohere<6.0.0,>=5.1.1 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-cohere) (5.1.2)\n", + "Requirement already satisfied: langchain-core<0.2.0,>=0.1.32 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-cohere) (0.1.33)\n", + "Requirement already satisfied: httpx>=0.21.2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from cohere<6.0.0,>=5.1.1->langchain-cohere) (0.27.0)\n", + "Requirement already satisfied: pydantic>=1.9.2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from cohere<6.0.0,>=5.1.1->langchain-cohere) (2.6.4)\n", + "Requirement already satisfied: typing_extensions>=4.0.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from cohere<6.0.0,>=5.1.1->langchain-cohere) (4.10.0)\n", + "Requirement already satisfied: PyYAML>=5.3 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (6.0.1)\n", + "Requirement already satisfied: anyio<5,>=3 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (4.3.0)\n", + "Requirement already satisfied: jsonpatch<2.0,>=1.33 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (1.33)\n", + "Requirement already satisfied: langsmith<0.2.0,>=0.1.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (0.1.31)\n", + "Requirement already satisfied: packaging<24.0,>=23.2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (23.2)\n", + "Requirement already satisfied: requests<3,>=2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (2.31.0)\n", + "Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (8.2.3)\n", + "Requirement already satisfied: idna>=2.8 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from anyio<5,>=3->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (3.6)\n", + "Requirement already satisfied: sniffio>=1.1 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from anyio<5,>=3->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (1.3.1)\n", + "Requirement already satisfied: certifi in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from httpx>=0.21.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (2024.2.2)\n", + "Requirement already satisfied: httpcore==1.* in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from httpx>=0.21.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (1.0.4)\n", + "Requirement already satisfied: h11<0.15,>=0.13 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from httpcore==1.*->httpx>=0.21.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (0.14.0)\n", + "Requirement already satisfied: jsonpointer>=1.9 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from jsonpatch<2.0,>=1.33->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (2.4)\n", + "Requirement already satisfied: orjson<4.0.0,>=3.9.14 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langsmith<0.2.0,>=0.1.0->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (3.9.15)\n", + "Requirement already satisfied: annotated-types>=0.4.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from pydantic>=1.9.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (0.6.0)\n", + "Requirement already satisfied: pydantic-core==2.16.3 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from pydantic>=1.9.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (2.16.3)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3,>=2->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (3.3.2)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3,>=2->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (2.2.1)\n", + "Requirement already satisfied: wikipedia in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (1.4.0)\n", + "Requirement already satisfied: beautifulsoup4 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from wikipedia) (4.12.3)\n", + "Requirement already satisfied: requests<3.0.0,>=2.0.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from wikipedia) (2.31.0)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (3.3.2)\n", + "Requirement already satisfied: idna<4,>=2.5 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (3.6)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (2.2.1)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (2024.2.2)\n", + "Requirement already satisfied: soupsieve>1.2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from beautifulsoup4->wikipedia) (2.5)\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "# install package\n", + "!pip install -U langchain-cohere\n", + "%pip install wikipedia" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from langchain.agents import AgentExecutor\n", + "from langchain_cohere.chat_models import ChatCohere\n", + "from langchain_cohere.multi_hop_agent import create_cohere_multi_hop_agent\n", + "from langchain.retrievers import WikipediaRetriever\n", + "from langchain.tools.retriever import create_retriever_tool\n", + "from langchain_core.prompts import ChatPromptTemplate" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Next we create the prompt template and cohere model" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "# Create the prompt\n", + "prompt = ChatPromptTemplate.from_template(\n", + " \"Write all output in capital letters. {input}\"\n", + ")\n", + "\n", + "# Create the Cohere chat model\n", + "chat = ChatCohere(cohere_api_key=\"csNOPHXFK0QW4gVMwbgcaZcAEnuI490n4o1eujtg\", model=\"command-r\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In this example we use a Wikipedia retrieval tool " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "retriever = WikipediaRetriever()\n", + "retriever_tool = create_retriever_tool(\n", + " retriever,\n", + " \"wikipedia\",\n", + " \"Search for information on Wikipedia\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Next, create the cohere tool agent and call with the input" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", + "messages=[HumanMessage(content='Write all output in capital letters. What was the hometown of the moter of the second person to walk on the moon?')]\n" + ] + }, + { + "ename": "KeyError", + "evalue": "\"Input to PromptTemplate is missing variables {'agent_scratchpad'}. Expected: ['agent_scratchpad', 'input'] Received: ['input']\"", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[5], line 7\u001b[0m\n\u001b[1;32m 1\u001b[0m agent \u001b[38;5;241m=\u001b[39m create_cohere_multi_hop_agent(\n\u001b[1;32m 2\u001b[0m llm\u001b[38;5;241m=\u001b[39mchat,\n\u001b[1;32m 3\u001b[0m tools\u001b[38;5;241m=\u001b[39m[retriever_tool],\n\u001b[1;32m 4\u001b[0m prompt\u001b[38;5;241m=\u001b[39mprompt,\n\u001b[1;32m 5\u001b[0m )\n\u001b[1;32m 6\u001b[0m agent_executor \u001b[38;5;241m=\u001b[39m AgentExecutor(agent\u001b[38;5;241m=\u001b[39magent, tools\u001b[38;5;241m=\u001b[39m[retriever_tool], verbose\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[0;32m----> 7\u001b[0m \u001b[43magent_executor\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minvoke\u001b[49m\u001b[43m(\u001b[49m\u001b[43m{\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43minput\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mWhat was the hometown of the moter of the second person to walk on the moon?\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/langchain/langchain/chains/base.py:163\u001b[0m, in \u001b[0;36mChain.invoke\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 161\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 162\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n\u001b[0;32m--> 163\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m 164\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_end(outputs)\n\u001b[1;32m 166\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m include_run_info:\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/langchain/langchain/chains/base.py:153\u001b[0m, in \u001b[0;36mChain.invoke\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 150\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 151\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_validate_inputs(inputs)\n\u001b[1;32m 152\u001b[0m outputs \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 153\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 154\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m 155\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(inputs)\n\u001b[1;32m 156\u001b[0m )\n\u001b[1;32m 158\u001b[0m final_outputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_outputs(\n\u001b[1;32m 159\u001b[0m inputs, outputs, return_only_outputs\n\u001b[1;32m 160\u001b[0m )\n\u001b[1;32m 161\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/langchain/langchain/agents/agent.py:1432\u001b[0m, in \u001b[0;36mAgentExecutor._call\u001b[0;34m(self, inputs, run_manager)\u001b[0m\n\u001b[1;32m 1430\u001b[0m \u001b[38;5;66;03m# We now enter the agent loop (until it returns something).\u001b[39;00m\n\u001b[1;32m 1431\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_should_continue(iterations, time_elapsed):\n\u001b[0;32m-> 1432\u001b[0m next_step_output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_take_next_step\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1433\u001b[0m \u001b[43m \u001b[49m\u001b[43mname_to_tool_map\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1434\u001b[0m \u001b[43m \u001b[49m\u001b[43mcolor_mapping\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1435\u001b[0m \u001b[43m \u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1436\u001b[0m \u001b[43m \u001b[49m\u001b[43mintermediate_steps\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1437\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1438\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1439\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(next_step_output, AgentFinish):\n\u001b[1;32m 1440\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_return(\n\u001b[1;32m 1441\u001b[0m next_step_output, intermediate_steps, run_manager\u001b[38;5;241m=\u001b[39mrun_manager\n\u001b[1;32m 1442\u001b[0m )\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/langchain/langchain/agents/agent.py:1138\u001b[0m, in \u001b[0;36mAgentExecutor._take_next_step\u001b[0;34m(self, name_to_tool_map, color_mapping, inputs, intermediate_steps, run_manager)\u001b[0m\n\u001b[1;32m 1129\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_take_next_step\u001b[39m(\n\u001b[1;32m 1130\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 1131\u001b[0m name_to_tool_map: Dict[\u001b[38;5;28mstr\u001b[39m, BaseTool],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 1135\u001b[0m run_manager: Optional[CallbackManagerForChainRun] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 1136\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Union[AgentFinish, List[Tuple[AgentAction, \u001b[38;5;28mstr\u001b[39m]]]:\n\u001b[1;32m 1137\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_consume_next_step(\n\u001b[0;32m-> 1138\u001b[0m \u001b[43m[\u001b[49m\n\u001b[1;32m 1139\u001b[0m \u001b[43m \u001b[49m\u001b[43ma\u001b[49m\n\u001b[1;32m 1140\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43ma\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_iter_next_step\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1141\u001b[0m \u001b[43m \u001b[49m\u001b[43mname_to_tool_map\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1142\u001b[0m \u001b[43m \u001b[49m\u001b[43mcolor_mapping\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1143\u001b[0m \u001b[43m \u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1144\u001b[0m \u001b[43m \u001b[49m\u001b[43mintermediate_steps\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1145\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1146\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1147\u001b[0m \u001b[43m \u001b[49m\u001b[43m]\u001b[49m\n\u001b[1;32m 1148\u001b[0m )\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/langchain/langchain/agents/agent.py:1138\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 1129\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_take_next_step\u001b[39m(\n\u001b[1;32m 1130\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 1131\u001b[0m name_to_tool_map: Dict[\u001b[38;5;28mstr\u001b[39m, BaseTool],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 1135\u001b[0m run_manager: Optional[CallbackManagerForChainRun] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 1136\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Union[AgentFinish, List[Tuple[AgentAction, \u001b[38;5;28mstr\u001b[39m]]]:\n\u001b[1;32m 1137\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_consume_next_step(\n\u001b[0;32m-> 1138\u001b[0m \u001b[43m[\u001b[49m\n\u001b[1;32m 1139\u001b[0m \u001b[43m \u001b[49m\u001b[43ma\u001b[49m\n\u001b[1;32m 1140\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43ma\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_iter_next_step\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1141\u001b[0m \u001b[43m \u001b[49m\u001b[43mname_to_tool_map\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1142\u001b[0m \u001b[43m \u001b[49m\u001b[43mcolor_mapping\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1143\u001b[0m \u001b[43m \u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1144\u001b[0m \u001b[43m \u001b[49m\u001b[43mintermediate_steps\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1145\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1146\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1147\u001b[0m \u001b[43m \u001b[49m\u001b[43m]\u001b[49m\n\u001b[1;32m 1148\u001b[0m )\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/langchain/langchain/agents/agent.py:1166\u001b[0m, in \u001b[0;36mAgentExecutor._iter_next_step\u001b[0;34m(self, name_to_tool_map, color_mapping, inputs, intermediate_steps, run_manager)\u001b[0m\n\u001b[1;32m 1163\u001b[0m intermediate_steps \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_prepare_intermediate_steps(intermediate_steps)\n\u001b[1;32m 1165\u001b[0m \u001b[38;5;66;03m# Call the LLM to see what to do.\u001b[39;00m\n\u001b[0;32m-> 1166\u001b[0m output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43magent\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mplan\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1167\u001b[0m \u001b[43m \u001b[49m\u001b[43mintermediate_steps\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1168\u001b[0m \u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_child\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 1169\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1170\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1171\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m OutputParserException \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 1172\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandle_parsing_errors, \u001b[38;5;28mbool\u001b[39m):\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/langchain/langchain/agents/agent.py:514\u001b[0m, in \u001b[0;36mRunnableMultiActionAgent.plan\u001b[0;34m(self, intermediate_steps, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m 506\u001b[0m final_output: Any \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 507\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mstream_runnable:\n\u001b[1;32m 508\u001b[0m \u001b[38;5;66;03m# Use streaming to make sure that the underlying LLM is invoked in a\u001b[39;00m\n\u001b[1;32m 509\u001b[0m \u001b[38;5;66;03m# streaming\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 512\u001b[0m \u001b[38;5;66;03m# Because the response from the plan is not a generator, we need to\u001b[39;00m\n\u001b[1;32m 513\u001b[0m \u001b[38;5;66;03m# accumulate the output into final output and return that.\u001b[39;00m\n\u001b[0;32m--> 514\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mchunk\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrunnable\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstream\u001b[49m\u001b[43m(\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m{\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcallbacks\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\u001b[43m:\u001b[49m\n\u001b[1;32m 515\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mfinal_output\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mis\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m:\u001b[49m\n\u001b[1;32m 516\u001b[0m \u001b[43m \u001b[49m\u001b[43mfinal_output\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mchunk\u001b[49m\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:2791\u001b[0m, in \u001b[0;36mRunnableSequence.stream\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 2785\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mstream\u001b[39m(\n\u001b[1;32m 2786\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 2787\u001b[0m \u001b[38;5;28minput\u001b[39m: Input,\n\u001b[1;32m 2788\u001b[0m config: Optional[RunnableConfig] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 2789\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Optional[Any],\n\u001b[1;32m 2790\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Iterator[Output]:\n\u001b[0;32m-> 2791\u001b[0m \u001b[38;5;28;01myield from\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtransform(\u001b[38;5;28miter\u001b[39m([\u001b[38;5;28minput\u001b[39m]), config, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:2778\u001b[0m, in \u001b[0;36mRunnableSequence.transform\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 2772\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mtransform\u001b[39m(\n\u001b[1;32m 2773\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 2774\u001b[0m \u001b[38;5;28minput\u001b[39m: Iterator[Input],\n\u001b[1;32m 2775\u001b[0m config: Optional[RunnableConfig] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 2776\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Optional[Any],\n\u001b[1;32m 2777\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Iterator[Output]:\n\u001b[0;32m-> 2778\u001b[0m \u001b[38;5;28;01myield from\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_transform_stream_with_config(\n\u001b[1;32m 2779\u001b[0m \u001b[38;5;28minput\u001b[39m,\n\u001b[1;32m 2780\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_transform,\n\u001b[1;32m 2781\u001b[0m patch_config(config, run_name\u001b[38;5;241m=\u001b[39m(config \u001b[38;5;129;01mor\u001b[39;00m {})\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_name\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mname),\n\u001b[1;32m 2782\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs,\n\u001b[1;32m 2783\u001b[0m )\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:1849\u001b[0m, in \u001b[0;36mRunnable._transform_stream_with_config\u001b[0;34m(self, input, transformer, config, run_type, **kwargs)\u001b[0m\n\u001b[1;32m 1847\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 1848\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[0;32m-> 1849\u001b[0m chunk: Output \u001b[38;5;241m=\u001b[39m \u001b[43mcontext\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mnext\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43miterator\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[1;32m 1850\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m chunk\n\u001b[1;32m 1851\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m final_output_supported:\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:2742\u001b[0m, in \u001b[0;36mRunnableSequence._transform\u001b[0;34m(self, input, run_manager, config)\u001b[0m\n\u001b[1;32m 2733\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m step \u001b[38;5;129;01min\u001b[39;00m steps:\n\u001b[1;32m 2734\u001b[0m final_pipeline \u001b[38;5;241m=\u001b[39m step\u001b[38;5;241m.\u001b[39mtransform(\n\u001b[1;32m 2735\u001b[0m final_pipeline,\n\u001b[1;32m 2736\u001b[0m patch_config(\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 2739\u001b[0m ),\n\u001b[1;32m 2740\u001b[0m )\n\u001b[0;32m-> 2742\u001b[0m \u001b[43m\u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43moutput\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mfinal_pipeline\u001b[49m\u001b[43m:\u001b[49m\n\u001b[1;32m 2743\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01myield\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43moutput\u001b[49m\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:1283\u001b[0m, in \u001b[0;36mRunnable.transform\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 1280\u001b[0m final: Input\n\u001b[1;32m 1281\u001b[0m got_first_val \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[0;32m-> 1283\u001b[0m \u001b[43m\u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mchunk\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m:\u001b[49m\n\u001b[1;32m 1284\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mnot\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mgot_first_val\u001b[49m\u001b[43m:\u001b[49m\n\u001b[1;32m 1285\u001b[0m \u001b[43m \u001b[49m\u001b[43mfinal\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43madapt_first_streaming_chunk\u001b[49m\u001b[43m(\u001b[49m\u001b[43mchunk\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore\u001b[39;49;00m\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:4638\u001b[0m, in \u001b[0;36mRunnableBindingBase.transform\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 4632\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mtransform\u001b[39m(\n\u001b[1;32m 4633\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 4634\u001b[0m \u001b[38;5;28minput\u001b[39m: Iterator[Input],\n\u001b[1;32m 4635\u001b[0m config: Optional[RunnableConfig] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 4636\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m 4637\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Iterator[Output]:\n\u001b[0;32m-> 4638\u001b[0m \u001b[38;5;28;01myield from\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbound\u001b[38;5;241m.\u001b[39mtransform(\n\u001b[1;32m 4639\u001b[0m \u001b[38;5;28minput\u001b[39m,\n\u001b[1;32m 4640\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_merge_configs(config),\n\u001b[1;32m 4641\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m{\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mkwargs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs},\n\u001b[1;32m 4642\u001b[0m )\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:1283\u001b[0m, in \u001b[0;36mRunnable.transform\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 1280\u001b[0m final: Input\n\u001b[1;32m 1281\u001b[0m got_first_val \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[0;32m-> 1283\u001b[0m \u001b[43m\u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mchunk\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m:\u001b[49m\n\u001b[1;32m 1284\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mnot\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mgot_first_val\u001b[49m\u001b[43m:\u001b[49m\n\u001b[1;32m 1285\u001b[0m \u001b[43m \u001b[49m\u001b[43mfinal\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43madapt_first_streaming_chunk\u001b[49m\u001b[43m(\u001b[49m\u001b[43mchunk\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore\u001b[39;49;00m\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:1300\u001b[0m, in \u001b[0;36mRunnable.transform\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 1293\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\n\u001b[1;32m 1294\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFailed while trying to add together \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 1295\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtype \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mtype\u001b[39m(final)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m and \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mtype\u001b[39m(chunk)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 1296\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mThese types should be addable for transform to work.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 1297\u001b[0m )\n\u001b[1;32m 1299\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m got_first_val:\n\u001b[0;32m-> 1300\u001b[0m \u001b[38;5;28;01myield from\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mstream(final, config, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:808\u001b[0m, in \u001b[0;36mRunnable.stream\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 798\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mstream\u001b[39m(\n\u001b[1;32m 799\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 800\u001b[0m \u001b[38;5;28minput\u001b[39m: Input,\n\u001b[1;32m 801\u001b[0m config: Optional[RunnableConfig] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 802\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Optional[Any],\n\u001b[1;32m 803\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Iterator[Output]:\n\u001b[1;32m 804\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 805\u001b[0m \u001b[38;5;124;03m Default implementation of stream, which calls invoke.\u001b[39;00m\n\u001b[1;32m 806\u001b[0m \u001b[38;5;124;03m Subclasses should override this method if they support streaming output.\u001b[39;00m\n\u001b[1;32m 807\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 808\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minvoke\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/prompts/base.py:118\u001b[0m, in \u001b[0;36mBasePromptTemplate.invoke\u001b[0;34m(self, input, config)\u001b[0m\n\u001b[1;32m 116\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtags:\n\u001b[1;32m 117\u001b[0m config[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtags\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m.\u001b[39mextend(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtags)\n\u001b[0;32m--> 118\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call_with_config\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 119\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_format_prompt_with_error_handling\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 120\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 121\u001b[0m \u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 122\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_type\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mprompt\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 123\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:1594\u001b[0m, in \u001b[0;36mRunnable._call_with_config\u001b[0;34m(self, func, input, config, run_type, **kwargs)\u001b[0m\n\u001b[1;32m 1590\u001b[0m context \u001b[38;5;241m=\u001b[39m copy_context()\n\u001b[1;32m 1591\u001b[0m context\u001b[38;5;241m.\u001b[39mrun(var_child_runnable_config\u001b[38;5;241m.\u001b[39mset, child_config)\n\u001b[1;32m 1592\u001b[0m output \u001b[38;5;241m=\u001b[39m cast(\n\u001b[1;32m 1593\u001b[0m Output,\n\u001b[0;32m-> 1594\u001b[0m \u001b[43mcontext\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1595\u001b[0m \u001b[43m \u001b[49m\u001b[43mcall_func_with_variable_args\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore[arg-type]\u001b[39;49;00m\n\u001b[1;32m 1596\u001b[0m \u001b[43m \u001b[49m\u001b[43mfunc\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore[arg-type]\u001b[39;49;00m\n\u001b[1;32m 1597\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore[arg-type]\u001b[39;49;00m\n\u001b[1;32m 1598\u001b[0m \u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1599\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1600\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1601\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m,\n\u001b[1;32m 1602\u001b[0m )\n\u001b[1;32m 1603\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 1604\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/config.py:347\u001b[0m, in \u001b[0;36mcall_func_with_variable_args\u001b[0;34m(func, input, config, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m 345\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m run_manager \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m accepts_run_manager(func):\n\u001b[1;32m 346\u001b[0m kwargs[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_manager\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m run_manager\n\u001b[0;32m--> 347\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/prompts/base.py:103\u001b[0m, in \u001b[0;36mBasePromptTemplate._format_prompt_with_error_handling\u001b[0;34m(self, inner_input)\u001b[0m\n\u001b[1;32m 101\u001b[0m missing \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mset\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minput_variables)\u001b[38;5;241m.\u001b[39mdifference(inner_input)\n\u001b[1;32m 102\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m missing:\n\u001b[0;32m--> 103\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(\n\u001b[1;32m 104\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInput to \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m is missing variables \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mmissing\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 105\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m Expected: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minput_variables\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 106\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m Received: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mlist\u001b[39m(inner_input\u001b[38;5;241m.\u001b[39mkeys())\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 107\u001b[0m )\n\u001b[1;32m 108\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mformat_prompt(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39minner_input)\n", + "\u001b[0;31mKeyError\u001b[0m: \"Input to PromptTemplate is missing variables {'agent_scratchpad'}. Expected: ['agent_scratchpad', 'input'] Received: ['input']\"" + ] + } + ], + "source": [ + "agent = create_cohere_multi_hop_agent(\n", + " llm=chat,\n", + " tools=[retriever_tool],\n", + " prompt=prompt,\n", + ")\n", + "agent_executor = AgentExecutor(agent=agent, tools=[retriever_tool], verbose=True)\n", + "agent_executor.invoke({\"input\": \"What was the hometown of the moter of the second person to walk on the moon?\"})" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.7" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/libs/partners/cohere/docs/multi_hop_agent.ipynb b/libs/partners/cohere/docs/multi_hop_agent.ipynb new file mode 100644 index 0000000000000..a31e9d030f1c0 --- /dev/null +++ b/libs/partners/cohere/docs/multi_hop_agent.ipynb @@ -0,0 +1,408 @@ +{ + "cells": [ + { + "cell_type": "raw", + "metadata": {}, + "source": [ + "---\n", + "sidebar_position: 0\n", + "---" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Cohere Tools\n", + "\n", + "The following notebook goes over how to use the Cohere tools agent:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Prerequisites for this notebook:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: langchain-cohere in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (0.1.0rc0)\n", + "Requirement already satisfied: cohere<6.0.0,>=5.1.1 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-cohere) (5.1.2)\n", + "Requirement already satisfied: langchain-core<0.2.0,>=0.1.32 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-cohere) (0.1.33)\n", + "Requirement already satisfied: httpx>=0.21.2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from cohere<6.0.0,>=5.1.1->langchain-cohere) (0.27.0)\n", + "Requirement already satisfied: pydantic>=1.9.2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from cohere<6.0.0,>=5.1.1->langchain-cohere) (2.6.4)\n", + "Requirement already satisfied: typing_extensions>=4.0.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from cohere<6.0.0,>=5.1.1->langchain-cohere) (4.10.0)\n", + "Requirement already satisfied: PyYAML>=5.3 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (6.0.1)\n", + "Requirement already satisfied: anyio<5,>=3 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (4.3.0)\n", + "Requirement already satisfied: jsonpatch<2.0,>=1.33 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (1.33)\n", + "Requirement already satisfied: langsmith<0.2.0,>=0.1.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (0.1.31)\n", + "Requirement already satisfied: packaging<24.0,>=23.2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (23.2)\n", + "Requirement already satisfied: requests<3,>=2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (2.31.0)\n", + "Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (8.2.3)\n", + "Requirement already satisfied: idna>=2.8 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from anyio<5,>=3->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (3.6)\n", + "Requirement already satisfied: sniffio>=1.1 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from anyio<5,>=3->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (1.3.1)\n", + "Requirement already satisfied: certifi in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from httpx>=0.21.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (2024.2.2)\n", + "Requirement already satisfied: httpcore==1.* in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from httpx>=0.21.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (1.0.4)\n", + "Requirement already satisfied: h11<0.15,>=0.13 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from httpcore==1.*->httpx>=0.21.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (0.14.0)\n", + "Requirement already satisfied: jsonpointer>=1.9 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from jsonpatch<2.0,>=1.33->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (2.4)\n", + "Requirement already satisfied: orjson<4.0.0,>=3.9.14 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langsmith<0.2.0,>=0.1.0->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (3.9.15)\n", + "Requirement already satisfied: annotated-types>=0.4.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from pydantic>=1.9.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (0.6.0)\n", + "Requirement already satisfied: pydantic-core==2.16.3 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from pydantic>=1.9.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (2.16.3)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3,>=2->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (3.3.2)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3,>=2->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (2.2.1)\n", + "Requirement already satisfied: wikipedia in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (1.4.0)\n", + "Requirement already satisfied: beautifulsoup4 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from wikipedia) (4.12.3)\n", + "Requirement already satisfied: requests<3.0.0,>=2.0.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from wikipedia) (2.31.0)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (3.3.2)\n", + "Requirement already satisfied: idna<4,>=2.5 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (3.6)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (2.2.1)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (2024.2.2)\n", + "Requirement already satisfied: soupsieve>1.2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from beautifulsoup4->wikipedia) (2.5)\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "# install package\n", + "!pip install -U langchain-cohere\n", + "%pip install wikipedia" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from langchain.agents import AgentExecutor\n", + "from langchain_cohere.chat_models import ChatCohere\n", + "from langchain_cohere.multi_hop.agent import create_cohere_multi_hop_agent\n", + "from langchain.retrievers import WikipediaRetriever\n", + "from langchain.tools.retriever import create_retriever_tool\n", + "from langchain_core.prompts import ChatPromptTemplate" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Next we create the prompt template and cohere model" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "# Create the prompt\n", + "prompt = ChatPromptTemplate.from_template(\n", + " \"Write all output in capital letters. {input}\"\n", + ")\n", + "\n", + "# Create the Cohere chat model\n", + "chat = ChatCohere(cohere_api_key=\"API_KEY\", model=\"command-r\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In this example we use a Wikipedia retrieval tool " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "retriever = WikipediaRetriever()\n", + "retriever_tool = create_retriever_tool(\n", + " retriever,\n", + " \"wikipedia\",\n", + " \"Search for information on Wikipedia\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Next, create the cohere tool agent and call with the input" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", + "\u001b[32;1m\u001b[1;3mPlan: I will first search for who the second person to walk on the moon was, then I will search for that person's mother's hometown.\n", + "Action: ```json\n", + "[\n", + " {\n", + " \"tool_name\": \"wikipedia\",\n", + " \"parameters\": {\n", + " \"query\": \"second man to walk on the moon\"\n", + " }\n", + " }\n", + "]\n", + "```\u001b[0m\u001b[36;1m\u001b[1;3mWalk the Moon (stylized as WALK THE MOON) is an American pop rock band based in Cincinnati, Ohio. Lead singer Nicholas Petricca started the band in 2006, while a student at Kenyon College, deriving the band's name from the song \"Walking on the Moon\" by The Police. Although the band is best known for their most successful hit single to date \"Shut Up and Dance\", other notable songs include \"Anna Sun\" and \"One Foot\".\n", + "Walk the Moon has cited Talking Heads as influences. The band's use of 1980s musical mainstays, such as keyboard and synthesizer, is also notable.\n", + "\n", + "\n", + "== History ==\n", + "\n", + "\n", + "=== 2010–2011: Beginning, Anna Sun and i Want! i Want! ===\n", + "\n", + "The group independently released their debut studio album, I Want! I Want!, in November 2010, receiving airplay for the track \"Anna Sun\" on multiple alternative radio stations. Along with the success of \"Anna Sun\", Alt Nation named them a band you need to know for the summer of 2012. Influential music blog Neon Gold helped to break the band in January 2011, calling \"Anna Sun\", \"the kind of stuff British A&R dreams, and major label bidding wars, are made of.\" In February 2011, Walk the Moon signed to RCA Records.\n", + "In 2011, the band members began to paint their faces for live performances and they would bring enough paint to share with audience members. They have claimed it has become a “live tradition”. Bonnaroo’s camera crew documented the painting process in a short video from the 2011 festival. The band played at the Sasquatch Music Festival and Firefly Music Festival. In these years, they were known for their energetic performances and tireless touring schedule.\n", + "Before the release of their self-titled album, Walk the Moon joined many other performers at the Music Midtown festival and performed on the Great Southeast Music Hall Stage in Atlanta, Georgia in September 2011. In spring 2011, the band went on a short tour with the west coast band, Grouplove, as well as supporting Panic! at the Disco and Weezer on select dates. The band played on the main stage at the 20th Anniversary of Lollapalooza and also supported Local Natives in an Official Lollaplooza Aftershow at Lincoln Hall.\n", + "The band recorded i Want! i Want! with Chris Schmidt and Ben Cochran at Soap Floats Recording Studio in their hometown of Cincinnati, Ohio and then self-released it. The lead single from the album, \"Anna Sun\", became a surprise hit in the summer of 2011 following an endorsement by the Esquire article \"30 Summer Songs Every Man Should Listen To\". The song was written by Petricca and New York songwriter Nick Lerangis as their time at Kenyon College came to an end. \"It's about college, about maintaining that little bit of being a kid,\" Petricca said. \"Don't be afraid to play.\" The song was named after one of their favorite teachers. It was named song of the summer by MTV and Seventeen Mag, and one of the top songs of the year by Amazon. It has been officially remixed by Fool's Gold and received a Trouble Productions remix by Albert Hammond Jr. Anna Sun rose to the number one spot on Alt. Nation on Sirius XM Radio. \"Anna Sun\" was added to the video rotation of American Eagle Outfitters stores in May 2011. It was featured on the hit TV show Vampire Diaries in the first episode of season three. It was also the free single of the week on iTunes for the week of May 15.\n", + "Filmed in 2011 in Cincinnati's Over-the-Rhine neighborhood, the \"Anna Sun\" music video was released to coincide with the album. The video was shot on-location at the Cincinnati Mockbee building, as well as at a city park. It was directed and produced by Patrick Meier of the Cincinnati company, Contrast Productions, and features original choreography from Kim Popa of PONES Inc., as well as a cast full of the band's friends and locals from Cincinnati. MTV Hive calls the video a \"hilariously choreographed, neon-colored and awesomely shot in one take\" production.\n", + "\n", + "\n", + "=== 2012–2013: Walk the Moon and Tightrope EP ===\n", + "\n", + "The band's self-titled major label debut Walk t\n", + "\n", + "\"Man on the Moon\" is a song by American alternative rock band R.E.M., released in November 1992 as the second single from their eighth album, Automatic for the People (1992). The lyrics were written by lead singer Michael Stipe, and the music by drummer Bill Berry and guitarist Peter Buck. The song was well received by critics and reached number 30 on the US Billboard Hot 100, number 17 on the US Cash Box Top 100, number 18 on the UK Singles Chart, and number one in Iceland. It remains one of R.E.M.'s most popular songs and was included on the compilations In Time: The Best of R.E.M. 1988–2003 and Part Lies, Part Heart, Part Truth, Part Garbage 1982–2011.\n", + "\"Man on the Moon\" is a tribute to comedian Andy Kaufman, with numerous references to his career including his Elvis impersonation, wrestling, and the film My Breakfast with Blassie. The song's title and chorus refer to Moon landing conspiracy theories, as an oblique allusion to rumors that Kaufman's death in 1984 was faked. The song gave its name to Miloš Forman's Kaufman biopic Man on the Moon (1999), and features prominently in the film's soundtrack.\n", + "\n", + "\n", + "== Composition ==\n", + "\"Man on the Moon\" is a mid-tempo country-rock song following a verse-chorus structure with an added pre-chorus and an instrumental bridge following the second and third choruses. The song has six lines in the first verse but only four in the second and third verses.An early instrumental demo of the song was known to the band as \"C to D Slide\". Guitarist Peter Buck has explained how the music came together: \"'Man on the Moon' was something that Bill [Berry] had, this one chord change that he came in with, which was C to D like the verse of the song, and he said: 'I don't know what to do with that.' I used to finish some of Bill's things ... he would come up with the riffs, but I would be the finish guy for that. I sat down and came up with the chorus, the bridges, and so forth. I remember we showed it to Mike and Michael when they came in later; definitely we had the song finished. I think Bill played bass and I played guitar; we kept going around with it. I think we might have played some mandolin on it in the rehearsal studio.\"Michael Stipe explained in an interview with Charlie Rose how the lyric was written independently of the music, which had no prior association with the song's eventual lyrical content regarding Kaufman. Stipe recounted the other R.E.M. members had written and performed the music of the song and recorded it along with the rest of the Automatic for the People album during studio sessions in Seattle. As of the final week of the recording sessions, Stipe was still struggling to write the lyric, and the others continued to plead with him to finish it. Stipe attempted to argue the track should be an instrumental, but his bandmates were insistent. Stipe listened to the track on a walk around Seattle on his Walkman cassette player and was inspired to write about Andy Kaufman. After Stipe went back to the studio to complete the vocal track, the track was mixed that night and sent out the following day to be mastered.\n", + "\n", + "\n", + "== Lyric ==\n", + "The song's lyric does not tell a conventional story and instead forms a collection of cultural references, images and ideas. There are repeated mentions of Andy Kaufman, including references to his Elvis impersonation and work with wrestlers Fred Blassie and Jerry Lawler. The song also invokes the conspiracy theories surrounding the Moon landing and Elvis Presley's death as an indirect nod to the persistent rumors that Kaufman faked his own death. Speaking in 2017 to the NME, Mike Mills explained that the perceived ambiguity of Kaufman's legacy, including questions of whether he was a comedian or a performance artist, and whether his work was funny or irritating, was a way to frame other questions about life within the song:\n", + "\n", + "He's the perfect ghost to lead you through this tour of questioning things. Did the moon landing really happen? Is Elvis really dead? He was ki\n", + "\n", + "As part of the Apollo program by NASA, 24 astronauts flew nine missions to the Moon between December 1968 and December 1972. During six successful two-man landing missions, twelve men walked on the lunar surface, six of whom drove Lunar Roving Vehicles as part of the last three missions. Three men have been to the Moon twice, one orbited once and took a circumlunar trajectory the second time, while the other two landed once apiece. Apart from these 24 men, no human being has gone beyond low Earth orbit. No woman has been to the Moon, but a number of non-human animals have circled or orbited it, including two tortoises, several turtles, and five mice.\n", + "Apollo missions 8 and 10–17 were the nine crewed missions to the Moon. Apollo 4–6 and AS-201 and AS-202 were uncrewed, while AS-203 is considered a test flight. The Apollo program included three other crewed missions: Apollo 1 (AS-204) did not launch and its crew died in a ground-based capsule fire, while Apollo 7 and Apollo 9 were low Earth orbit missions that only tested spacecraft components and docking maneuvers. Apollo missions 18, 19, and 20 were canceled. Twelve astronauts later flew unused Apollo command modules in the Apollo Applications Program's Skylab and Apollo–Soyuz Test Project. Of the 24 astronauts who flew to the Moon, two went on to command a Skylab mission, one commanded Apollo–Soyuz, one flew as commander for Approach and Landing Tests of the Space Shuttle, and two commanded orbital Space Shuttle missions.\n", + "\n", + "\n", + "== Prime crew members ==\n", + "NASA's Director of Flight Crew Operations during the Gemini and Apollo programs was Donald K. \"Deke\" Slayton, one of the original Mercury Seven astronauts, who was medically grounded in September 1962 due to a minor cardiac arrhythmia – paroxysmal atrial fibrillation. Slayton was responsible for making all Gemini and Apollo crew assignments. In March 1972, Slayton was restored to flight status, and flew on the 1975 Apollo–Soyuz Test Project mission.\n", + "The prime crew members selected for actual missions are here grouped by their NASA astronaut selection groups, and within each group in the order selected for flight. Two versions of the Apollo Command/Service Module (CSM) spacecraft were developed: Block I, intended for preliminary low Earth orbit testing; and Block II, redesigned for the lunar landing. The Block I crew position titles were Command Pilot, Senior Pilot (second seat), and Pilot (third seat). The corresponding Block II titles were: Commander, Command Module Pilot, and Lunar Module Pilot. The second seat pilot was given secondary responsibility for celestial navigation to keep the CSM's guidance computer accurately calibrated with the spacecraft's true position, and the third seat pilot served as a flight engineer, monitoring the health of the spacecraft systems.\n", + "\n", + "\n", + "== Apollo astronauts by their dates of selection by NASA ==\n", + "\n", + "\n", + "=== 1959 ===\n", + "Virgil I. \"Gus\" Grissom began his career at NASA in 1959. In 1966, he was selected as Command Pilot for the first crewed Apollo mission, a low Earth orbit test. This mission ended a month before its scheduled launch, when a cabin fire on the launch pad killed Grissom, Ed White and Roger Chaffee on January 27, 1967.\n", + "Walter M. Schirra Jr. also began his NASA career in 1959. He was selected in October 1968 as Command Pilot for Apollo 7, an 11-day, low Earth orbit shakedown test of the three-man Apollo Command/Service Module and the first crewed launch for the Apollo project.\n", + "Alan B. Shepard Jr. – America's first man in space on Freedom 7 was originally selected to command Gemini 3, but was medically grounded for the duration of Gemini due to Ménière's disease and assisted Slayton in Flight Operations. After corrective surgery, Shepard was restored to flight status and commanded Apollo 14, the third successful Moon landing mission.\n", + "\n", + "\n", + "=== 1962 ===\n", + "\n", + "All of these astronauts flew on Gemini, and except for White, each commanded one Gemini and one Apollo mission:\n", + "\n", + "Edward H. White II – Second-seat \u001b[0m\u001b[32;1m\u001b[1;3mReflection: I have found that the second person to walk on the moon was Alan Shepard Jr.. I will now search for Alan Shepard Jr.'s mother's hometown.\n", + "Action: ```json\n", + "[\n", + " {\n", + " \"tool_name\": \"wikipedia\",\n", + " \"parameters\": {\n", + " \"query\": \"Alan Shepard Jr. mother hometown\"\n", + " }\n", + " }\n", + "]\n", + "```\u001b[0m\u001b[36;1m\u001b[1;3mAlan Eugene Jackson (born October 17, 1958) is an American singer-songwriter. He is known for performing a style widely regarded as \"neotraditional country\", as well as penning many of his own songs. Jackson has recorded 21 studio albums, including two Christmas albums, and two gospel albums, as well as released three greatest-hits albums.\n", + "Jackson is one of the best-selling music artists of all time, having sold over 75 million records worldwide, with 44 million sold in the United States alone. He has had 66 songs appear on the Billboard Hot Country Singles & Tracks chart; of the 66 titles, and six featured singles, 38 have reached the top five and 35 have claimed the number one spot. Out of 15 titles to reach the Billboard Top Country Albums chart, nine have been certified multi-platinum. He is the recipient of two Grammy Awards, 16 CMA Awards, 17 ACM Awards and nominee of multiple other awards. He is a member of the Grand Ole Opry, and was inducted into the Georgia Music Hall of Fame in 2001. He was inducted into the Country Music Hall of Fame in 2017 by Loretta Lynn and into the Nashville Songwriters Hall of Fame in 2018.\n", + "\n", + "\n", + "== Early life ==\n", + "Jackson was born to Joseph Eugene \"Daddy Gene\" Jackson (1927–2000) and Ruth Musick \"Mama Ruth\" Jackson (1930–2017) in Newnan, Georgia, and has four older sisters. He and his immediate family lived in a small home built around his grandfather's old toolshed. The family is primarily of English descent. His mother lived in the home until her death on January 7, 2017. He began writing music in 1983.Growing up, Jackson listened primarily to gospel music, until a friend introduced him to Gene Watson, John Anderson, and Hank Williams Jr. Jackson attended the local Elm Street Elementary and Newnan High School, and joined the band Dixie Steel after graduation. When he was 27, Jackson and his wife of six years, Denise, moved from Newnan to Nashville, Tennessee, where he hoped to pursue music full-time. In 1987, Jackson cut a pre-debut demo album titled New Traditional at Doc's Place in Hendersonville, Tennessee, but it is extremely rare and was released only in Japan.\n", + "\n", + "\n", + "== Career ==\n", + "In Tennessee, Jackson got his first job in The Nashville Network's mailroom. His wife Denise was a flight attendant. While working, she came in contact with Glen Campbell and requested advice for her husband. Campbell handed her his business card of his manager and told her to call, which helped jumpstart his career. Jackson eventually signed with Arista, and in 1989, he became the first artist signed to the newly formed Arista Nashville branch of Arista Records. Arista released Jackson's debut single, \"Blue Blooded Woman\", in late 1989. Although the song failed to reach top 40 on Hot Country Songs, he reached number three by early 1990 with \"Here in the Real World\". This song served as the title track to his debut studio album, Here in the Real World, which also included two more top five hits (\"Wanted\" and \"Chasin' That Neon Rainbow\") and his first number one, \"I'd Love You All Over Again\". Don't Rock the Jukebox was the title of Jackson's second album. Released in 1991, it included four number-one singles: the title track, \"Someday\", \"Dallas\" and \"Love's Got a Hold on You\", and the number three \"Midnight in Montgomery\". Jackson also co-wrote several songs on Randy Travis' 1991 album High Lonesome.A Lot About Livin' (And a Little 'bout Love), his third album, accounted for the number one hits \"She's Got the Rhythm (And I Got the Blues)\" (which Randy Travis co-wrote) and \"Chattahoochee\", plus the top five hits \"Tonight I Climbed the Wall\", \"Mercury Blues\" and \"(Who Says) You Can't Have It All\". \"Chattahoochee\" also won him the 1994 Country Music Association (CMA) awards for Single and Song of the Year. In 1994, Jackson left his management company, Ten Ten Management, which had overseen his career up to that point, and switched to Gary Overton. His fourth album was titled Who I Am, and it contained four number one hit\n", + "\n", + "Here is a list of characters appearing on the 1978–1991 American television series Dallas. During its 14 seasons on air, the show featured 21 regular cast members, portraying twenty characters (as the character of Miss Ellie was recast for season eight). Additionally, hundreds of guest actors portrayed supporting characters; this list includes the most noteworthy.\n", + "\n", + "\n", + "== Main cast timeline ==\n", + "Cast notes\n", + "\n", + "\n", + "== Supporting characters ==\n", + "\n", + "\n", + "=== Ewing relatives ===\n", + "\n", + "\n", + "==== Gary Ewing ====\n", + "\n", + "Garrison Arthur \"Gary\" Ewing (David Ackroyd in season 2, Ted Shackelford thereafter) was the middle son of Jock (Jim Davis) and Miss Ellie Ewing (Barbara Bel Geddes), husband of Valene (Joan Van Ark) and father of Lucy Ewing (Charlene Tilton). He appeared occasionally between season 2 and season 6, once in season 9, and the series finale in season 14. The character made 11 appearances on the show, Ackroyd for the first two and Shackelford for the remaining nine.\n", + "Gary was the middle child, being born after J.R. (Larry Hagman) and before Bobby (Patrick Duffy). He was raised while Jock was at war, and displayed traits of his mother's family, the Southworths, which meant that Jock and J.R. saw him as a weak link. At 17, to try and escape his family, Gary ran away and married 15-year-old Valene and got her pregnant, which resulted in the birth of their daughter Lucy. Valene eventually forced Gary to introduce her to his family, and upon his return Jock and Miss Ellie gave him a home and a job on Southfork Ranch. J.R., who disliked Valene and resented Gary's presence, harassed Gary to the point of alcoholism and forced him off the ranch. Gary disappeared and wound up working as a waiter in a Las Vegas hotel, where he encountered Bobby and his wife Pam (Victoria Principal) in 1978.\n", + "Bobby and Pam convinced Gary to return to Southfork, reconciling with Lucy, who engineered a meeting between him and Valene. For a brief while, the three cohabited at Southfork as a family under Jock and Miss Ellie's eyes, but Gary soon felt trapped by Jock's expectations and J.R.'s resentment. Realising that this would send him back to alcoholism, Gary abandoned his family and Southfork. Valene followed, and the two eventually reconciled again and married in season 3. As a gift to the newlyweds, Miss Ellie bought them a house in California, where Gary and Valene settled after their honeymoon.\n", + "Gary remained in California, free from the pressures of his family, although he returned to Dallas on several occasions: to visit J.R. in hospital after Kristin Shepard (Mary Crosby) tried to kill him; for Lucy's wedding to Mitch Cooper (Leigh McCloskey); to support Miss Ellie after the death of his father, Jock; and for Bobby's \"funeral\" during the dream season. Following this, Gary didn't return to Dallas again, although he appeared in an alternate reality in which J.R. had never been born during the series finale: without J.R. to intimidate him, Gary became the eldest son and became a successful divorce lawyer, after inheriting Ewing Oil and running it into the ground. He still met and started a relationship with Valene, although they did not meet for the first time until their middle age (and, subsequently, did not have Lucy). The alternate reality also suggested that, regardless of J.R.'s interference, Gary and Valene were always destined to end up together.\n", + "Gary and Valene's backstories and lives in California were the basis of Dallas spin-off series Knots Landing. The couple also appeared for brief story arcs in the revival series.\n", + "\n", + "\n", + "==== Valene Clements Ewing ====\n", + "\n", + "Valene \"Val\" Ewing (also Clements, Gibson and Waleska; credited as Valene Wallace in the series finale) was the wife of Gary Ewing (David Ackroyd/Ted Shackelford) and mother of Lucy Ewing (Charlene Tilton). She appeared occasionally between season 2 and season 5, and returned in the series finale in season 14. Van Ark appeared in 8 episodes overall, and featured briefly in uncredited archive footage during season 12.\n", + "At 15\n", + "\n", + "\"Kill Ari (Part I)\" and \"Kill Ari (Part II)\" are the first two episodes of the third season of the American police procedural drama NCIS, and the 47th and 48th episodes overall. They originally aired on CBS in the United States on September 20 and 27, 2005. Both episodes are written by Donald Bellisario, the show's creator and executive producer at the time. Part I, directed by Dennis Smith, was seen live by 15.48 million viewers, while Part II, directed by James Whitmore, Jr., was seen live by 15.09 million viewers.The \"Kill Ari\" story arc centers on Gibbs' hunt for Ari Haswari, who shot and killed Special Agent Kate Todd in the second-season finale of NCIS. It also introduces two new main characters to the show—Mossad Officer Ziva David and NCIS Director Jenny Shepard. Due to these changes in the cast, Bellisario labeled the third season as \"the season of change\".\n", + "\n", + "\n", + "== Plot ==\n", + "\n", + "\n", + "=== Part I ===\n", + "The episode opens with a recap of the second season's finale, \"Twilight\": as the NCIS team by Leroy Jethro Gibbs (Mark Harmon) engage in a gunfight against Ari Haswari's terrorist cell, Ari (Rudolf Martin), identified as a rogue terrorist, attempts to kill various NCIS agents including Tim McGee (Sean Murray) before Ari decides to fatally shoot NCIS Agent Kate Todd (Sasha Alexander) with a long range sniper shot, killing her instantly with a horrified Gibbs and Tony DiNozzo (Michael Weatherly) witnessing Kate's death. In the aftermath of the murder, the team struggles to come to terms with her death while an enraged Gibbs seeks revenge against Ari. Shortly afterwards, Ari attacks again, firing at Abby in her lab. However, she survives physically unharmed.\n", + "Then NCIS Director Tom Morrow (Alan Dale) announces that he is leaving the agency after receiving a job offer from Homeland Security and introduces Jenny Shepard (Lauren Holly) as his replacement. It immediately becomes apparent that Gibbs was romantically involved with Shepard while working undercover with her years earlier, though she insists that she is now nothing more than his boss and will act accordingly. Gibbs clashes with Shepard, who believes that Ari Haswari was not the one responsible for firing the bullet that killed Agent Todd due to the fact that there's no physical evidence or proof of any kind linking him to the crime.\n", + "Ziva David (Cote de Pablo), Ari's Mossad control officer, arrives shortly afterwards, striking up a rapport with Tony. She sides with the director and further weakens Gibbs' case, claiming that Ari is completely innocent and offering evidence to support her assertion. However, Ziva's motives for defending Ari become ambiguous when she communicates with him without informing anyone in the NCIS office and her conversation indicates a personal connection to him.\n", + "Gibbs realizes that Ziva has contacted Ari and orders Tony to tail her. Ari later returns, taking Gerald Jackson (Pancho Demmings) hostage, though he quickly notifies Ducky to divert the team's attention away from Ziva and force Ducky into a meet.\n", + "The episode ends with Ducky approaching the pre-arranged meeting point, unaware that Ari has a sniper-rifle trained on him.\n", + "\n", + "\n", + "=== Part II ===\n", + "Gibbs' determination to kill Ari in revenge for Kate Todd's death increases despite the skepticism expressed by his superiors. Ducky, who is released unharmed shortly after his abduction, admits to Gibbs that he has begun to believe Ari's claims of innocence after listening to his defense, leaving Gibbs further enraged.\n", + "After tailing Ari's control officer, Ziva David, for much of the evening, Tony reports to Gibbs that she is communicating with Ari and smuggling a passport and money to him through an unknown woman (Gloria Votsis), presumably another Mossad officer. However, Ziva later approaches Tony and informs him that she was aware that he was following her the entire time. She also tells him that her younger sister Tali, who was \"sixteen and the best of us\", was killed in a Hamas suicide bombing, and that she kn\u001b[0m\u001b[32;1m\u001b[1;3mReflection: I could not find the information on Alan Shepard Jr.'s mother's hometown in this search, I will now search for Alan Shepard's mother's hometown.\n", + "Action: ```json\n", + "[\n", + " {\n", + " \"tool_name\": \"wikipedia\",\n", + " \"parameters\": {\n", + " \"query\": \"Alan Shepard mother's hometown\"\n", + " }\n", + " }\n", + "]\n", + "```\u001b[0m\u001b[36;1m\u001b[1;3mAlan Eugene Jackson (born October 17, 1958) is an American singer-songwriter. He is known for performing a style widely regarded as \"neotraditional country\", as well as penning many of his own songs. Jackson has recorded 21 studio albums, including two Christmas albums, and two gospel albums, as well as released three greatest-hits albums.\n", + "Jackson is one of the best-selling music artists of all time, having sold over 75 million records worldwide, with 44 million sold in the United States alone. He has had 66 songs appear on the Billboard Hot Country Singles & Tracks chart; of the 66 titles, and six featured singles, 38 have reached the top five and 35 have claimed the number one spot. Out of 15 titles to reach the Billboard Top Country Albums chart, nine have been certified multi-platinum. He is the recipient of two Grammy Awards, 16 CMA Awards, 17 ACM Awards and nominee of multiple other awards. He is a member of the Grand Ole Opry, and was inducted into the Georgia Music Hall of Fame in 2001. He was inducted into the Country Music Hall of Fame in 2017 by Loretta Lynn and into the Nashville Songwriters Hall of Fame in 2018.\n", + "\n", + "\n", + "== Early life ==\n", + "Jackson was born to Joseph Eugene \"Daddy Gene\" Jackson (1927–2000) and Ruth Musick \"Mama Ruth\" Jackson (1930–2017) in Newnan, Georgia, and has four older sisters. He and his immediate family lived in a small home built around his grandfather's old toolshed. The family is primarily of English descent. His mother lived in the home until her death on January 7, 2017. He began writing music in 1983.Growing up, Jackson listened primarily to gospel music, until a friend introduced him to Gene Watson, John Anderson, and Hank Williams Jr. Jackson attended the local Elm Street Elementary and Newnan High School, and joined the band Dixie Steel after graduation. When he was 27, Jackson and his wife of six years, Denise, moved from Newnan to Nashville, Tennessee, where he hoped to pursue music full-time. In 1987, Jackson cut a pre-debut demo album titled New Traditional at Doc's Place in Hendersonville, Tennessee, but it is extremely rare and was released only in Japan.\n", + "\n", + "\n", + "== Career ==\n", + "In Tennessee, Jackson got his first job in The Nashville Network's mailroom. His wife Denise was a flight attendant. While working, she came in contact with Glen Campbell and requested advice for her husband. Campbell handed her his business card of his manager and told her to call, which helped jumpstart his career. Jackson eventually signed with Arista, and in 1989, he became the first artist signed to the newly formed Arista Nashville branch of Arista Records. Arista released Jackson's debut single, \"Blue Blooded Woman\", in late 1989. Although the song failed to reach top 40 on Hot Country Songs, he reached number three by early 1990 with \"Here in the Real World\". This song served as the title track to his debut studio album, Here in the Real World, which also included two more top five hits (\"Wanted\" and \"Chasin' That Neon Rainbow\") and his first number one, \"I'd Love You All Over Again\". Don't Rock the Jukebox was the title of Jackson's second album. Released in 1991, it included four number-one singles: the title track, \"Someday\", \"Dallas\" and \"Love's Got a Hold on You\", and the number three \"Midnight in Montgomery\". Jackson also co-wrote several songs on Randy Travis' 1991 album High Lonesome.A Lot About Livin' (And a Little 'bout Love), his third album, accounted for the number one hits \"She's Got the Rhythm (And I Got the Blues)\" (which Randy Travis co-wrote) and \"Chattahoochee\", plus the top five hits \"Tonight I Climbed the Wall\", \"Mercury Blues\" and \"(Who Says) You Can't Have It All\". \"Chattahoochee\" also won him the 1994 Country Music Association (CMA) awards for Single and Song of the Year. In 1994, Jackson left his management company, Ten Ten Management, which had overseen his career up to that point, and switched to Gary Overton. His fourth album was titled Who I Am, and it contained four number one hit\n", + "\n", + "Mari Aldon (born Marija Aldona Pauliutė; 17 November 1925 – 31 October 2004) was a Lithuanian-born American actress.\n", + "\n", + "\n", + "== Early life ==\n", + "Mari Aldon was born in Tauragė, Lithuania. Her father Antanas Paulius was a policeman, mother Antanina (Antosė) Paulienė was a nurse. Father moved to America looking for a job. Soon after, when Mari was three years old, her mother also moved to Toronto, Canada with her daughter. There, she attended Givens Public School and Central High School. She studied ballet, drama, piano, and singing. Her early performances were noticed in Lithuanian newspapers of America. She had a sister.\n", + "\n", + "\n", + "== Career ==\n", + "Before Aldon began working in films, she acted for 11 months in a road company of A Streetcar Named Desire and danced with the Canadian Ballet. She also appeared on radio with Alan Young and on The Harold Peary Show.\n", + "After making her screen debut in a minor role in The Locket (1946) she gradually evolved to playing supporting or lead roles. Her most notable performance was starring opposite Gary Cooper in the 1951 Western Distant Drums. By the mid-1950s she was appearing either in B Pictures like the British thriller Mask of Dust (1954) or in supporting roles in more expensive films such as David Lean's Summertime (1955).After this point she worked largely in television, such as on the TV Western Wagon Train in 1959 as Freda Johnson in \"The Vivian Carter Story\" (S2E23) and in 1960 as Hester Millikan in \"The Jeremy Dow Story\" (S4E14). She guest-starred in a 1961 episode of Ichabod and Me.\n", + "\n", + "\n", + "== Personal life ==\n", + "Aldon married Tay Garnett in London, England on 13 August 1953. Their daughter, Tiela Aldon Garnett (later Daniels), was born in Los Angeles, California on 25 October 1955.On 17 January 1958, Aldon became a US citizen. In August 1970, Aldon filed for divorce from Garnett in Los Angeles, she was widowed seven years later. Aldon and Garnett had a ranch, near King Vidor in Paso Robles, California. Close relatives still live in her hometown of Tauragė, Lithuania, with whom she kept in touch.\n", + "\n", + "\n", + "== Death ==\n", + "Aldon died on 31 October 2004 in Las Vegas, aged 78, of cancer.\n", + "\n", + "\n", + "== Filmography ==\n", + "\n", + "\n", + "== References ==\n", + "\n", + "\n", + "== Bibliography ==\n", + "Aaker, Everett. George Raft: The Films. McFarland, 2013.\n", + "\n", + "\n", + "== External links ==\n", + "\n", + "Mari Aldon at IMDb\n", + "\n", + "Alan LaVern Bean (March 15, 1932 – May 26, 2018) was an American naval officer and aviator, aeronautical engineer, test pilot, NASA astronaut and painter. He was selected to become an astronaut by NASA in 1963 as part of Astronaut Group 3, and was the fourth person to walk on the Moon.\n", + "Before becoming an astronaut, Bean graduated with a Bachelor of Science degree in Aeronautical Engineering from University of Texas at Austin in 1955 and re-joined the U.S. Navy—he served as an enlisted member for a year after his high school graduation. He received his naval aviator wings in 1956 and served as a fighter pilot. In 1960, he graduated from the U.S. Naval Test Pilot School, flew as a test pilot and was The New Nine selection finalist in 1962.\n", + "He made his first flight into space aboard Apollo 12, the second crewed mission to land on the Moon, at age 37 in November 1969. He made his second and final flight into space on the Skylab 3 mission in 1973, the second crewed mission to the Skylab space station. After retiring from the United States Navy in 1975 and NASA in 1981, he pursued his interest in painting, depicting various space-related scenes and documenting his own experiences in space as well as those of his fellow Apollo program astronauts. He was the last living crew member of Apollo 12.\n", + "\n", + "\n", + "== Biography ==\n", + "\n", + "\n", + "=== Early life and education ===\n", + "Bean was born March 15, 1932, in Wheeler, the seat of Wheeler County in the northeastern Texas Panhandle, to parents Arnold Horace Bean and Frances Caroline Bean (née Murphy), who lived from 1908 to 1983, and 1906 to 1981, respectively. He considered Fort Worth his hometown. He was of Scottish descent. As a boy, he lived in Minden, the seat of Webster Parish in northwestern Louisiana, where his father worked for the U.S. Soil Conservation Service. Bean was a Boy Scout and he earned the rank of First Class. He graduated from R. L. Paschal High School in Fort Worth, Texas, in 1949. Following his high school graduation in 1949, Bean enlisted in the U.S. Naval Reserve.Bean received a Bachelor of Science degree in aeronautical engineering from the University of Texas at Austin in 1955, where he attended on a Naval Reserve Officers Training Corps (NROTC) scholarship. While at the university, he also joined the Delta Kappa Epsilon fraternity.\n", + "\n", + "\n", + "=== Military service ===\n", + "He was an Electronics Technician Striker at the NAS Dallas, Texas, until September 1950, when he was honorably discharged. In January 1955, Bean was commissioned a U.S. Navy ensign through the NROTC at the University of Texas at Austin, and attended flight training. After completing flight training in June 1956, he was assigned to Attack Squadron 44 (VA-44) at NAS Jacksonville, Florida, from 1956 to 1960, flying the F9F Cougar and A4D Skyhawk. After a four-year tour of duty, he attended the U.S. Naval Test Pilot School (USNTPS) at NAS Patuxent River, Maryland, where his instructor was his future Apollo 12 Commander, Pete Conrad, graduating in November 1960. Bean took art classes at St. Mary's College of Maryland during this tour, and flew as a test pilot on several types of naval aircraft. Following his assignment at USNTPS and aviation safety training with the University of Southern California (USC), he went through additional instruction with his old Attack Squadron 44, and was assigned to Navy Attack Squadron VA-172 at NAS Cecil Field, Florida, flying the A-4 Skyhawks, during which time he was selected as a NASA astronaut.Bean logged more than 7,145 hours of flying time, including 4,890 hours in jet aircraft.\n", + "\n", + "\n", + "=== NASA career ===\n", + "Bean was selected by NASA as part of Astronaut Group 3 in 1963 (after not being selected for Astronaut Group 2 the previous year). He was selected to be the backup command pilot for Gemini 10, but was unsuccessful in securing an early Apollo flight assignment. He was placed in the Apollo Applications Program in the interim. In that capacity, he was the first astronaut to dive in the Neutral Buoyancy Simu\u001b[0m\u001b[32;1m\u001b[1;3mRelevant Documents: 0,2\n", + "Cited Documents: 2\n", + "Answer: FORT WORTH WAS THE HOMETOWN OF THE MOTHER OF ALAN SHEPARD, THE SECOND PERSON TO WALK ON THE MOON.\n", + "Grounded answer: FORT WORTH WAS THE HOMETOWN OF THE MOTHER OF ALAN SHEPARD, THE SECOND PERSON TO WALK ON THE MOON.\u001b[0m\n", + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n" + ] + }, + { + "data": { + "text/plain": [ + "{'input': 'What was the hometown of the mother of the second person to walk on the moon?',\n", + " 'output': 'FORT WORTH WAS THE HOMETOWN OF THE MOTHER OF ALAN SHEPARD, THE SECOND PERSON TO WALK ON THE MOON.'}" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "agent = create_cohere_multi_hop_agent(\n", + " llm=chat,\n", + " tools=[retriever_tool],\n", + " prompt=prompt,\n", + ")\n", + "agent_executor = AgentExecutor(agent=agent, tools=[retriever_tool], verbose=True)\n", + "agent_executor.invoke({\"input\": \"What was the hometown of the mother of the second person to walk on the moon?\"})" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.7" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/libs/partners/cohere/langchain_cohere/__init__.py b/libs/partners/cohere/langchain_cohere/__init__.py index 1f554a006e258..df2d50672edb9 100644 --- a/libs/partners/cohere/langchain_cohere/__init__.py +++ b/libs/partners/cohere/langchain_cohere/__init__.py @@ -1,5 +1,6 @@ from langchain_cohere.chat_models import ChatCohere from langchain_cohere.embeddings import CohereEmbeddings +from langchain_cohere.multi_hop.agent import create_cohere_multi_hop_agent from langchain_cohere.rag_retrievers import CohereRagRetriever from langchain_cohere.rerank import CohereRerank @@ -9,4 +10,5 @@ "CohereEmbeddings", "CohereRagRetriever", "CohereRerank", + "create_cohere_multi_hop_agent", ] diff --git a/libs/partners/cohere/langchain_cohere/multi_hop/__init__.py b/libs/partners/cohere/langchain_cohere/multi_hop/__init__.py new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/libs/partners/cohere/langchain_cohere/multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/multi_hop/agent.py new file mode 100644 index 0000000000000..f5c2c4dd4fdd6 --- /dev/null +++ b/libs/partners/cohere/langchain_cohere/multi_hop/agent.py @@ -0,0 +1,223 @@ +import json +import logging +import re +from typing import List, Sequence, Union + +from langchain.agents.agent import MultiActionAgentOutputParser +from langchain_core.agents import AgentAction, AgentFinish +from langchain_core.language_models import BaseLanguageModel +from langchain_core.prompts.chat import ChatPromptTemplate +from langchain_core.runnables import Runnable, RunnablePassthrough +from langchain_core.tools import BaseTool + +from langchain_cohere.multi_hop.prompt import multi_hop_prompt_template + +""" + Cohere multi-hop tool allows you to use multiple tools in parallel or + sequentially to complete your task. The agent uses a multi hop prompt by Cohere. + This prompt is experimental and subject to change. +""" + + +def create_cohere_multi_hop_agent( + llm: BaseLanguageModel, + tools: Sequence[BaseTool], + prompt: ChatPromptTemplate, +) -> Runnable: + multi_hop_prompt = multi_hop_prompt_template.partial( + tools="\n".join([render_tool_description(t) for t in tools]), + ) + llm_with_tools = llm.bind(stop=["\nObservation:"]) + + agent = ( + RunnablePassthrough.assign( + agent_scratchpad=lambda x: format_cohere_log_to_str( + x["intermediate_steps"], + ), + input=lambda x: prompt.format_messages( + input=x["input"], agent_scratchpad=x["intermediate_steps"] + ), + ) + | multi_hop_prompt + | llm_with_tools + | CohereToolsMultiHopAgentOutputParser() + ) + return agent + + +class CohereToolsMultiHopAgentOutputParser(MultiActionAgentOutputParser): + """Parses a message into agent actions/finish.""" + + @property + def _type(self) -> str: + return "cohere-tools-agent-output-parser" + + def parse_jsonified_tool_use_generation( + self, tool_use_generation: str, tool_use_prefix: str + ) -> List[dict]: + """Parses model-generated jsonified actions. + + Expects input of the form + "{tool_use_prefix}: ```json\n[{list of jsonified objects}]```" + + outputs parsed list of jsonified objects. + """ + + def _extract_codeblocks_from_md(text: str) -> List[str]: + return re.findall(r"```([^`]*)```", text) + + raw_generation = re.sub(f"^{tool_use_prefix} ", "", tool_use_generation) + code_block_sections = _extract_codeblocks_from_md(raw_generation) + + if len(code_block_sections) != 1: # should have exactly 1 code block + raise ValueError(f"Action Parsing Failed: {tool_use_generation}") + # only json allowed: + assert code_block_sections[0].startswith( + "json\n" + ), f"Action Parsing Failed: {tool_use_generation}" + + actions = json.loads(re.sub("^json\n", "", code_block_sections[0])) + + if not isinstance(actions, list): + raise ValueError(f"Action Parsing Failed: {tool_use_generation}") + + if len(actions): + if any( + not isinstance(action, dict) or "tool_name" not in action + for action in actions + ): + raise ValueError(f"Action Parsing Failed: {tool_use_generation}") + return actions + + def parse_answer_with_prefixes( + self, completion: str, prefixes: dict[str, str] + ) -> dict[str, str]: + """parses string into key-value pairs, + according to patterns supplied in prefixes. Also strips. + + if inputs are: + completion = "\nhello: sam\ngoodbye then: paul.", + prefixes = {"greeting": "hello:", "farewell": "goodbye then:"} + + the expected returned result is: + {"greeting": "sam", "farewell": "paul."} + + Args: + completion (str): text to split + prefixes (Dict[str, str]): a key-value dict of keys and patterns. + See example above + + Returns: + Dict[str, str]: parsed result + """ + # sort out prefixes + re_pat = "(" + "|".join([re.escape(p) for p in prefixes.values()]) + ")" + reverse_prefix_map = {v: k for k, v in prefixes.items()} + splitted = re.split(re_pat, completion) + splitted = splitted[1:] + parsed = {} + for prefix, value in zip(splitted[::2], splitted[1::2]): + if prefix in reverse_prefix_map: # if the prefix is a match + if ( + reverse_prefix_map[prefix] not in parsed + ): # first occurrence of a prefix is kept, others discarded + parsed[reverse_prefix_map[prefix]] = value.strip() + return parsed + + def parse_actions(self, generation: str) -> tuple[str, str, List[dict]]: + """Parse action selections from model output.""" + plan = "" + actions = generation + try: + if "Plan: " in generation or "Reflection: " in generation: + # Model is trained to output a Plan or Reflection followed by an action. + # Use regex to extract the plan and action. + regex = ( + r"^(Plan|Reflection)\s*\d*\s*:(.*?)" + + r"(Action\s*\d*\s*:\s*\d*\s*```json\n.*?```)" + ) + action_match = re.search(regex, generation, re.DOTALL) + if not action_match: + raise ValueError( + f"Failed to parse multihop completion for input: {generation}" + ) + plan = action_match.group(2).strip() + actions = action_match.group(3).strip() + else: + # Catch the case where model outputs only an action. + regex = r"^(Action\s*\d*\s*:\s*\d*\s*```json\n.*?```)" + action_match = re.search(regex, generation, re.DOTALL) + if not action_match: + raise ValueError( + f"Failed to parse multihop completion for input: {generation}" + ) + actions = action_match.group(1).strip() + except Exception as e: + logging.error( + f"Failed to parse multihop completion for input: {generation}" + ) + logging.error(f"Error: {e}") + + parsed_actions = self.parse_jsonified_tool_use_generation(actions, "Action:") + return generation, plan, parsed_actions + + def parse(self, text: str) -> Union[List[AgentAction], AgentFinish]: + # Parse the structured output of the final answer. + if "Answer: " in text: + prefix_map = { + "answer": "Answer:", + "grounded_answer": "Grounded answer:", + "relevant_docs": "Relevant Documents:", + "cited_docs": "Cited Documents:", + } + parsed_answer = self.parse_answer_with_prefixes(text, prefix_map) + return AgentFinish({"output": parsed_answer["answer"]}, text) + elif any([x in text for x in ["Plan: ", "Reflection: ", "Action: "]]): + completion, plan, actions = self.parse_actions(text) + return [ + AgentAction(action["tool_name"], action["parameters"]["query"], text) + for action in actions + ] + else: + raise ValueError( + "\nCould not parse generation as it did not contain Plan, Reflection," + + f"Action, or Answer. Input: {text}\n\n" + ) + + +def render_tool_description(tool: BaseTool) -> str: + """Render the tool name and description. TODO: better way to render?""" + template = """```python + def {TOOL_NAME}(): + \"\"\"{DESCRIPTION} + \"\"\" + pass + ```""" + return template.format(TOOL_NAME=tool.name, DESCRIPTION=tool.description) + + +def format_cohere_log_to_str( + intermediate_steps: List[tuple[AgentAction, str]], + observation_prefix: str = "<|END_OF_TURN_TOKEN|>\n<|START_OF_TURN_TOKEN|>" + + "<|SYSTEM_TOKEN|>\n", + llm_prefix: str = "<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|>" + + "<|CHATBOT_TOKEN|>", +) -> str: + """Construct the scratchpad that lets the agent continue its thought process.""" + thoughts = "" + last_log = "" + # Global result idx to be used for grounded answer citation from any prior action. + + result_idx = 0 + for step_i, (action, observation) in enumerate(intermediate_steps): + # For parallel tool calls, dont add the action call twice, add all the results. + if action.log != last_log: + thoughts += action.log + last_log = action.log + if step_i > 0: + thoughts += "\n" + observation_str = f"Document {result_idx}\n{observation}" + result_idx += 1 + thoughts += f"{observation_prefix}{observation_str}{llm_prefix}" + + return thoughts diff --git a/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py b/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py new file mode 100644 index 0000000000000..bef92fab3aacb --- /dev/null +++ b/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py @@ -0,0 +1,83 @@ +# flake8: noqa +from datetime import datetime +from langchain_core.prompts import PromptTemplate + +default_basic_rules = ( + "You are a powerful language agent trained by Cohere to help people. " + + "You are capable of complex reasoning and augmented with a number of tools. " + + "Your job is to plan and reason about how you will use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see an instruction informing you what kind of response to generate. You will construct a plan and then perform a number of reasoning and action steps to solve the problem. When you have determined the answer to the user's request, you will cite your sources in your answers, according the instructions." +) + +now = datetime.now().strftime("%A, %B %d, %Y %H:%M:%S") +default_task_context = f"""You use your advanced complex reasoning capabilities to help people by answering their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You may need to use multiple tools in parallel or sequentially to complete your task. You should focus on serving the user's needs as best you can, which will be wide-ranging. The current date is {now}.""" + +default_style_guide = """Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.""" + +default_safety_rules = """The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.""" + +default_system_prefix = """<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>""" + +structured_preamble_template = """{SYSTEM_PREFIX}# Introduction: + +This document details the task you must accomplish. \ +Read it carefully and always follow its instructions. + +## Safety Preamble +{SAFETY_PREAMBLE} + +## System Preamble +### Basic Rules +{BASIC_RULES} + +## User Preamble +### Task and Context +{TASK_CONTEXT} + +### Style Guide +{STYLE_GUIDE}""" + + +def render_structured_preamble( + system_prefix: str = default_system_prefix, + basic_rules: str = default_basic_rules, + task_context: str = default_task_context, + style_guide: str = default_style_guide, + safety_rules: str = default_safety_rules, +) -> str: + return structured_preamble_template.format( + SYSTEM_PREFIX=system_prefix, + BASIC_RULES=basic_rules, + TASK_CONTEXT=task_context, + STYLE_GUIDE=style_guide, + SAFETY_PREAMBLE=safety_rules, + ) + + +rendered_structured_preamble = render_structured_preamble() + +multi_hop_instruction = """Carefully perform the following instructions, in order, starting each with a new line. +Firstly, You may need to use complex and advanced reasoning to complete your task and answer the question. Think about how you can use the provided tools to answer the question and come up with a high level plan you will execute. +Write 'Plan:' followed by an initial high level plan of how you will solve the problem including the tools and steps required. +Secondly, Carry out your plan by repeatedly using actions, reasoning over the results, and re-evaluating your plan. Perform Action, Observation, Reflection steps with the following format. Write 'Action:' followed by a json formatted action containing the "tool_name" and "parameters" + Next you will analyze the 'Observation:', this is the result of the action. +After that you should always think about what to do next. Write 'Reflection:' followed by what you've figured out so far, any changes you need to make to your plan, and what you will do next including if you know the answer to the question. +... (this Action/Observation/Reflection can repeat N times) +Thirdly, Decide which of the retrieved documents are relevant to the user's last input by writing 'Relevant Documents:' followed by comma-separated list of document numbers. If none are relevant, you should instead write 'None'. +Fourthly, Decide which of the retrieved documents contain facts that should be cited in a good answer to the user's last input by writing 'Cited Documents:' followed a comma-separated list of document numbers. If you dont want to cite any of them, you should instead write 'None'. +Fifthly, Write 'Answer:' followed by a response to the user's last input in high quality natural english. Use the retrieved documents to help you. Do not insert any citations or grounding markup. +Finally, Write 'Grounded answer:' followed by a response to the user's last input in high quality natural english. Use the symbols and to indicate when a fact comes from a document in the search result, e.g my fact for a fact from document 4.""" + + +multi_hop_prompt_template = PromptTemplate.from_template( + """{structured_preamble} + +### Available Tools +Here is a list of tools that you have available to you: + +{tools}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>{input}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{multi_hop_instruction}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|> +{agent_scratchpad} +""" +).partial( + multi_hop_instruction=multi_hop_instruction, + structured_preamble=rendered_structured_preamble, +) From c04786869d972a691f79b5537794568a98648e05 Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:36:55 +0000 Subject: [PATCH 02/27] remove --- .../cohere/docs/cohere_multihop_agent.ipynb | 229 ------------------ 1 file changed, 229 deletions(-) delete mode 100644 libs/partners/cohere/docs/cohere_multihop_agent.ipynb diff --git a/libs/partners/cohere/docs/cohere_multihop_agent.ipynb b/libs/partners/cohere/docs/cohere_multihop_agent.ipynb deleted file mode 100644 index e50ce4d1f0610..0000000000000 --- a/libs/partners/cohere/docs/cohere_multihop_agent.ipynb +++ /dev/null @@ -1,229 +0,0 @@ -{ - "cells": [ - { - "cell_type": "raw", - "metadata": {}, - "source": [ - "---\n", - "sidebar_position: 0\n", - "---" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Cohere Tools\n", - "\n", - "The following notebook goes over how to use the Cohere tools agent:" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Prerequisites for this notebook:" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: langchain-cohere in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (0.1.0rc0)\n", - "Requirement already satisfied: cohere<6.0.0,>=5.1.1 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-cohere) (5.1.2)\n", - "Requirement already satisfied: langchain-core<0.2.0,>=0.1.32 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-cohere) (0.1.33)\n", - "Requirement already satisfied: httpx>=0.21.2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from cohere<6.0.0,>=5.1.1->langchain-cohere) (0.27.0)\n", - "Requirement already satisfied: pydantic>=1.9.2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from cohere<6.0.0,>=5.1.1->langchain-cohere) (2.6.4)\n", - "Requirement already satisfied: typing_extensions>=4.0.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from cohere<6.0.0,>=5.1.1->langchain-cohere) (4.10.0)\n", - "Requirement already satisfied: PyYAML>=5.3 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (6.0.1)\n", - "Requirement already satisfied: anyio<5,>=3 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (4.3.0)\n", - "Requirement already satisfied: jsonpatch<2.0,>=1.33 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (1.33)\n", - "Requirement already satisfied: langsmith<0.2.0,>=0.1.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (0.1.31)\n", - "Requirement already satisfied: packaging<24.0,>=23.2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (23.2)\n", - "Requirement already satisfied: requests<3,>=2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (2.31.0)\n", - "Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (8.2.3)\n", - "Requirement already satisfied: idna>=2.8 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from anyio<5,>=3->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (3.6)\n", - "Requirement already satisfied: sniffio>=1.1 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from anyio<5,>=3->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (1.3.1)\n", - "Requirement already satisfied: certifi in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from httpx>=0.21.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (2024.2.2)\n", - "Requirement already satisfied: httpcore==1.* in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from httpx>=0.21.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (1.0.4)\n", - "Requirement already satisfied: h11<0.15,>=0.13 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from httpcore==1.*->httpx>=0.21.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (0.14.0)\n", - "Requirement already satisfied: jsonpointer>=1.9 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from jsonpatch<2.0,>=1.33->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (2.4)\n", - "Requirement already satisfied: orjson<4.0.0,>=3.9.14 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langsmith<0.2.0,>=0.1.0->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (3.9.15)\n", - "Requirement already satisfied: annotated-types>=0.4.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from pydantic>=1.9.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (0.6.0)\n", - "Requirement already satisfied: pydantic-core==2.16.3 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from pydantic>=1.9.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (2.16.3)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3,>=2->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (3.3.2)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3,>=2->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (2.2.1)\n", - "Requirement already satisfied: wikipedia in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (1.4.0)\n", - "Requirement already satisfied: beautifulsoup4 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from wikipedia) (4.12.3)\n", - "Requirement already satisfied: requests<3.0.0,>=2.0.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from wikipedia) (2.31.0)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (3.3.2)\n", - "Requirement already satisfied: idna<4,>=2.5 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (3.6)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (2.2.1)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (2024.2.2)\n", - "Requirement already satisfied: soupsieve>1.2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from beautifulsoup4->wikipedia) (2.5)\n", - "Note: you may need to restart the kernel to use updated packages.\n" - ] - } - ], - "source": [ - "# install package\n", - "!pip install -U langchain-cohere\n", - "%pip install wikipedia" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.agents import AgentExecutor\n", - "from langchain_cohere.chat_models import ChatCohere\n", - "from langchain_cohere.multi_hop_agent import create_cohere_multi_hop_agent\n", - "from langchain.retrievers import WikipediaRetriever\n", - "from langchain.tools.retriever import create_retriever_tool\n", - "from langchain_core.prompts import ChatPromptTemplate" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Next we create the prompt template and cohere model" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "# Create the prompt\n", - "prompt = ChatPromptTemplate.from_template(\n", - " \"Write all output in capital letters. {input}\"\n", - ")\n", - "\n", - "# Create the Cohere chat model\n", - "chat = ChatCohere(cohere_api_key=\"csNOPHXFK0QW4gVMwbgcaZcAEnuI490n4o1eujtg\", model=\"command-r\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In this example we use a Wikipedia retrieval tool " - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "retriever = WikipediaRetriever()\n", - "retriever_tool = create_retriever_tool(\n", - " retriever,\n", - " \"wikipedia\",\n", - " \"Search for information on Wikipedia\",\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Next, create the cohere tool agent and call with the input" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n", - "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", - "messages=[HumanMessage(content='Write all output in capital letters. What was the hometown of the moter of the second person to walk on the moon?')]\n" - ] - }, - { - "ename": "KeyError", - "evalue": "\"Input to PromptTemplate is missing variables {'agent_scratchpad'}. Expected: ['agent_scratchpad', 'input'] Received: ['input']\"", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[5], line 7\u001b[0m\n\u001b[1;32m 1\u001b[0m agent \u001b[38;5;241m=\u001b[39m create_cohere_multi_hop_agent(\n\u001b[1;32m 2\u001b[0m llm\u001b[38;5;241m=\u001b[39mchat,\n\u001b[1;32m 3\u001b[0m tools\u001b[38;5;241m=\u001b[39m[retriever_tool],\n\u001b[1;32m 4\u001b[0m prompt\u001b[38;5;241m=\u001b[39mprompt,\n\u001b[1;32m 5\u001b[0m )\n\u001b[1;32m 6\u001b[0m agent_executor \u001b[38;5;241m=\u001b[39m AgentExecutor(agent\u001b[38;5;241m=\u001b[39magent, tools\u001b[38;5;241m=\u001b[39m[retriever_tool], verbose\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[0;32m----> 7\u001b[0m \u001b[43magent_executor\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minvoke\u001b[49m\u001b[43m(\u001b[49m\u001b[43m{\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43minput\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mWhat was the hometown of the moter of the second person to walk on the moon?\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/langchain/langchain/chains/base.py:163\u001b[0m, in \u001b[0;36mChain.invoke\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 161\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 162\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n\u001b[0;32m--> 163\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m 164\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_end(outputs)\n\u001b[1;32m 166\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m include_run_info:\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/langchain/langchain/chains/base.py:153\u001b[0m, in \u001b[0;36mChain.invoke\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 150\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 151\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_validate_inputs(inputs)\n\u001b[1;32m 152\u001b[0m outputs \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 153\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 154\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m 155\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(inputs)\n\u001b[1;32m 156\u001b[0m )\n\u001b[1;32m 158\u001b[0m final_outputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_outputs(\n\u001b[1;32m 159\u001b[0m inputs, outputs, return_only_outputs\n\u001b[1;32m 160\u001b[0m )\n\u001b[1;32m 161\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/langchain/langchain/agents/agent.py:1432\u001b[0m, in \u001b[0;36mAgentExecutor._call\u001b[0;34m(self, inputs, run_manager)\u001b[0m\n\u001b[1;32m 1430\u001b[0m \u001b[38;5;66;03m# We now enter the agent loop (until it returns something).\u001b[39;00m\n\u001b[1;32m 1431\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_should_continue(iterations, time_elapsed):\n\u001b[0;32m-> 1432\u001b[0m next_step_output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_take_next_step\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1433\u001b[0m \u001b[43m \u001b[49m\u001b[43mname_to_tool_map\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1434\u001b[0m \u001b[43m \u001b[49m\u001b[43mcolor_mapping\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1435\u001b[0m \u001b[43m \u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1436\u001b[0m \u001b[43m \u001b[49m\u001b[43mintermediate_steps\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1437\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1438\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1439\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(next_step_output, AgentFinish):\n\u001b[1;32m 1440\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_return(\n\u001b[1;32m 1441\u001b[0m next_step_output, intermediate_steps, run_manager\u001b[38;5;241m=\u001b[39mrun_manager\n\u001b[1;32m 1442\u001b[0m )\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/langchain/langchain/agents/agent.py:1138\u001b[0m, in \u001b[0;36mAgentExecutor._take_next_step\u001b[0;34m(self, name_to_tool_map, color_mapping, inputs, intermediate_steps, run_manager)\u001b[0m\n\u001b[1;32m 1129\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_take_next_step\u001b[39m(\n\u001b[1;32m 1130\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 1131\u001b[0m name_to_tool_map: Dict[\u001b[38;5;28mstr\u001b[39m, BaseTool],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 1135\u001b[0m run_manager: Optional[CallbackManagerForChainRun] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 1136\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Union[AgentFinish, List[Tuple[AgentAction, \u001b[38;5;28mstr\u001b[39m]]]:\n\u001b[1;32m 1137\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_consume_next_step(\n\u001b[0;32m-> 1138\u001b[0m \u001b[43m[\u001b[49m\n\u001b[1;32m 1139\u001b[0m \u001b[43m \u001b[49m\u001b[43ma\u001b[49m\n\u001b[1;32m 1140\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43ma\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_iter_next_step\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1141\u001b[0m \u001b[43m \u001b[49m\u001b[43mname_to_tool_map\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1142\u001b[0m \u001b[43m \u001b[49m\u001b[43mcolor_mapping\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1143\u001b[0m \u001b[43m \u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1144\u001b[0m \u001b[43m \u001b[49m\u001b[43mintermediate_steps\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1145\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1146\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1147\u001b[0m \u001b[43m \u001b[49m\u001b[43m]\u001b[49m\n\u001b[1;32m 1148\u001b[0m )\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/langchain/langchain/agents/agent.py:1138\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 1129\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_take_next_step\u001b[39m(\n\u001b[1;32m 1130\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 1131\u001b[0m name_to_tool_map: Dict[\u001b[38;5;28mstr\u001b[39m, BaseTool],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 1135\u001b[0m run_manager: Optional[CallbackManagerForChainRun] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 1136\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Union[AgentFinish, List[Tuple[AgentAction, \u001b[38;5;28mstr\u001b[39m]]]:\n\u001b[1;32m 1137\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_consume_next_step(\n\u001b[0;32m-> 1138\u001b[0m \u001b[43m[\u001b[49m\n\u001b[1;32m 1139\u001b[0m \u001b[43m \u001b[49m\u001b[43ma\u001b[49m\n\u001b[1;32m 1140\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43ma\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_iter_next_step\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1141\u001b[0m \u001b[43m \u001b[49m\u001b[43mname_to_tool_map\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1142\u001b[0m \u001b[43m \u001b[49m\u001b[43mcolor_mapping\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1143\u001b[0m \u001b[43m \u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1144\u001b[0m \u001b[43m \u001b[49m\u001b[43mintermediate_steps\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1145\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1146\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1147\u001b[0m \u001b[43m \u001b[49m\u001b[43m]\u001b[49m\n\u001b[1;32m 1148\u001b[0m )\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/langchain/langchain/agents/agent.py:1166\u001b[0m, in \u001b[0;36mAgentExecutor._iter_next_step\u001b[0;34m(self, name_to_tool_map, color_mapping, inputs, intermediate_steps, run_manager)\u001b[0m\n\u001b[1;32m 1163\u001b[0m intermediate_steps \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_prepare_intermediate_steps(intermediate_steps)\n\u001b[1;32m 1165\u001b[0m \u001b[38;5;66;03m# Call the LLM to see what to do.\u001b[39;00m\n\u001b[0;32m-> 1166\u001b[0m output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43magent\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mplan\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1167\u001b[0m \u001b[43m \u001b[49m\u001b[43mintermediate_steps\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1168\u001b[0m \u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_child\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 1169\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1170\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1171\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m OutputParserException \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 1172\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandle_parsing_errors, \u001b[38;5;28mbool\u001b[39m):\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/langchain/langchain/agents/agent.py:514\u001b[0m, in \u001b[0;36mRunnableMultiActionAgent.plan\u001b[0;34m(self, intermediate_steps, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m 506\u001b[0m final_output: Any \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 507\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mstream_runnable:\n\u001b[1;32m 508\u001b[0m \u001b[38;5;66;03m# Use streaming to make sure that the underlying LLM is invoked in a\u001b[39;00m\n\u001b[1;32m 509\u001b[0m \u001b[38;5;66;03m# streaming\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 512\u001b[0m \u001b[38;5;66;03m# Because the response from the plan is not a generator, we need to\u001b[39;00m\n\u001b[1;32m 513\u001b[0m \u001b[38;5;66;03m# accumulate the output into final output and return that.\u001b[39;00m\n\u001b[0;32m--> 514\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mchunk\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrunnable\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstream\u001b[49m\u001b[43m(\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m{\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcallbacks\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\u001b[43m:\u001b[49m\n\u001b[1;32m 515\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mfinal_output\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mis\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m:\u001b[49m\n\u001b[1;32m 516\u001b[0m \u001b[43m \u001b[49m\u001b[43mfinal_output\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mchunk\u001b[49m\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:2791\u001b[0m, in \u001b[0;36mRunnableSequence.stream\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 2785\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mstream\u001b[39m(\n\u001b[1;32m 2786\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 2787\u001b[0m \u001b[38;5;28minput\u001b[39m: Input,\n\u001b[1;32m 2788\u001b[0m config: Optional[RunnableConfig] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 2789\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Optional[Any],\n\u001b[1;32m 2790\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Iterator[Output]:\n\u001b[0;32m-> 2791\u001b[0m \u001b[38;5;28;01myield from\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtransform(\u001b[38;5;28miter\u001b[39m([\u001b[38;5;28minput\u001b[39m]), config, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:2778\u001b[0m, in \u001b[0;36mRunnableSequence.transform\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 2772\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mtransform\u001b[39m(\n\u001b[1;32m 2773\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 2774\u001b[0m \u001b[38;5;28minput\u001b[39m: Iterator[Input],\n\u001b[1;32m 2775\u001b[0m config: Optional[RunnableConfig] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 2776\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Optional[Any],\n\u001b[1;32m 2777\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Iterator[Output]:\n\u001b[0;32m-> 2778\u001b[0m \u001b[38;5;28;01myield from\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_transform_stream_with_config(\n\u001b[1;32m 2779\u001b[0m \u001b[38;5;28minput\u001b[39m,\n\u001b[1;32m 2780\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_transform,\n\u001b[1;32m 2781\u001b[0m patch_config(config, run_name\u001b[38;5;241m=\u001b[39m(config \u001b[38;5;129;01mor\u001b[39;00m {})\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_name\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mname),\n\u001b[1;32m 2782\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs,\n\u001b[1;32m 2783\u001b[0m )\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:1849\u001b[0m, in \u001b[0;36mRunnable._transform_stream_with_config\u001b[0;34m(self, input, transformer, config, run_type, **kwargs)\u001b[0m\n\u001b[1;32m 1847\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 1848\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[0;32m-> 1849\u001b[0m chunk: Output \u001b[38;5;241m=\u001b[39m \u001b[43mcontext\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mnext\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43miterator\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[1;32m 1850\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m chunk\n\u001b[1;32m 1851\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m final_output_supported:\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:2742\u001b[0m, in \u001b[0;36mRunnableSequence._transform\u001b[0;34m(self, input, run_manager, config)\u001b[0m\n\u001b[1;32m 2733\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m step \u001b[38;5;129;01min\u001b[39;00m steps:\n\u001b[1;32m 2734\u001b[0m final_pipeline \u001b[38;5;241m=\u001b[39m step\u001b[38;5;241m.\u001b[39mtransform(\n\u001b[1;32m 2735\u001b[0m final_pipeline,\n\u001b[1;32m 2736\u001b[0m patch_config(\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 2739\u001b[0m ),\n\u001b[1;32m 2740\u001b[0m )\n\u001b[0;32m-> 2742\u001b[0m \u001b[43m\u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43moutput\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mfinal_pipeline\u001b[49m\u001b[43m:\u001b[49m\n\u001b[1;32m 2743\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01myield\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43moutput\u001b[49m\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:1283\u001b[0m, in \u001b[0;36mRunnable.transform\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 1280\u001b[0m final: Input\n\u001b[1;32m 1281\u001b[0m got_first_val \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[0;32m-> 1283\u001b[0m \u001b[43m\u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mchunk\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m:\u001b[49m\n\u001b[1;32m 1284\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mnot\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mgot_first_val\u001b[49m\u001b[43m:\u001b[49m\n\u001b[1;32m 1285\u001b[0m \u001b[43m \u001b[49m\u001b[43mfinal\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43madapt_first_streaming_chunk\u001b[49m\u001b[43m(\u001b[49m\u001b[43mchunk\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore\u001b[39;49;00m\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:4638\u001b[0m, in \u001b[0;36mRunnableBindingBase.transform\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 4632\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mtransform\u001b[39m(\n\u001b[1;32m 4633\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 4634\u001b[0m \u001b[38;5;28minput\u001b[39m: Iterator[Input],\n\u001b[1;32m 4635\u001b[0m config: Optional[RunnableConfig] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 4636\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m 4637\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Iterator[Output]:\n\u001b[0;32m-> 4638\u001b[0m \u001b[38;5;28;01myield from\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbound\u001b[38;5;241m.\u001b[39mtransform(\n\u001b[1;32m 4639\u001b[0m \u001b[38;5;28minput\u001b[39m,\n\u001b[1;32m 4640\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_merge_configs(config),\n\u001b[1;32m 4641\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m{\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mkwargs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs},\n\u001b[1;32m 4642\u001b[0m )\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:1283\u001b[0m, in \u001b[0;36mRunnable.transform\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 1280\u001b[0m final: Input\n\u001b[1;32m 1281\u001b[0m got_first_val \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[0;32m-> 1283\u001b[0m \u001b[43m\u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mchunk\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m:\u001b[49m\n\u001b[1;32m 1284\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mnot\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mgot_first_val\u001b[49m\u001b[43m:\u001b[49m\n\u001b[1;32m 1285\u001b[0m \u001b[43m \u001b[49m\u001b[43mfinal\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43madapt_first_streaming_chunk\u001b[49m\u001b[43m(\u001b[49m\u001b[43mchunk\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore\u001b[39;49;00m\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:1300\u001b[0m, in \u001b[0;36mRunnable.transform\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 1293\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\n\u001b[1;32m 1294\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFailed while trying to add together \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 1295\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtype \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mtype\u001b[39m(final)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m and \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mtype\u001b[39m(chunk)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 1296\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mThese types should be addable for transform to work.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 1297\u001b[0m )\n\u001b[1;32m 1299\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m got_first_val:\n\u001b[0;32m-> 1300\u001b[0m \u001b[38;5;28;01myield from\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mstream(final, config, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:808\u001b[0m, in \u001b[0;36mRunnable.stream\u001b[0;34m(self, input, config, **kwargs)\u001b[0m\n\u001b[1;32m 798\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mstream\u001b[39m(\n\u001b[1;32m 799\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 800\u001b[0m \u001b[38;5;28minput\u001b[39m: Input,\n\u001b[1;32m 801\u001b[0m config: Optional[RunnableConfig] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 802\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Optional[Any],\n\u001b[1;32m 803\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Iterator[Output]:\n\u001b[1;32m 804\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 805\u001b[0m \u001b[38;5;124;03m Default implementation of stream, which calls invoke.\u001b[39;00m\n\u001b[1;32m 806\u001b[0m \u001b[38;5;124;03m Subclasses should override this method if they support streaming output.\u001b[39;00m\n\u001b[1;32m 807\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 808\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minvoke\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/prompts/base.py:118\u001b[0m, in \u001b[0;36mBasePromptTemplate.invoke\u001b[0;34m(self, input, config)\u001b[0m\n\u001b[1;32m 116\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtags:\n\u001b[1;32m 117\u001b[0m config[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtags\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m.\u001b[39mextend(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtags)\n\u001b[0;32m--> 118\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call_with_config\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 119\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_format_prompt_with_error_handling\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 120\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 121\u001b[0m \u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 122\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_type\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mprompt\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 123\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/base.py:1594\u001b[0m, in \u001b[0;36mRunnable._call_with_config\u001b[0;34m(self, func, input, config, run_type, **kwargs)\u001b[0m\n\u001b[1;32m 1590\u001b[0m context \u001b[38;5;241m=\u001b[39m copy_context()\n\u001b[1;32m 1591\u001b[0m context\u001b[38;5;241m.\u001b[39mrun(var_child_runnable_config\u001b[38;5;241m.\u001b[39mset, child_config)\n\u001b[1;32m 1592\u001b[0m output \u001b[38;5;241m=\u001b[39m cast(\n\u001b[1;32m 1593\u001b[0m Output,\n\u001b[0;32m-> 1594\u001b[0m \u001b[43mcontext\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1595\u001b[0m \u001b[43m \u001b[49m\u001b[43mcall_func_with_variable_args\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore[arg-type]\u001b[39;49;00m\n\u001b[1;32m 1596\u001b[0m \u001b[43m \u001b[49m\u001b[43mfunc\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore[arg-type]\u001b[39;49;00m\n\u001b[1;32m 1597\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore[arg-type]\u001b[39;49;00m\n\u001b[1;32m 1598\u001b[0m \u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1599\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1600\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1601\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m,\n\u001b[1;32m 1602\u001b[0m )\n\u001b[1;32m 1603\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 1604\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/runnables/config.py:347\u001b[0m, in \u001b[0;36mcall_func_with_variable_args\u001b[0;34m(func, input, config, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m 345\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m run_manager \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m accepts_run_manager(func):\n\u001b[1;32m 346\u001b[0m kwargs[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_manager\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m run_manager\n\u001b[0;32m--> 347\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Repos/langchain-1/libs/core/langchain_core/prompts/base.py:103\u001b[0m, in \u001b[0;36mBasePromptTemplate._format_prompt_with_error_handling\u001b[0;34m(self, inner_input)\u001b[0m\n\u001b[1;32m 101\u001b[0m missing \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mset\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minput_variables)\u001b[38;5;241m.\u001b[39mdifference(inner_input)\n\u001b[1;32m 102\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m missing:\n\u001b[0;32m--> 103\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(\n\u001b[1;32m 104\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInput to \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m is missing variables \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mmissing\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 105\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m Expected: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minput_variables\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 106\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m Received: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mlist\u001b[39m(inner_input\u001b[38;5;241m.\u001b[39mkeys())\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 107\u001b[0m )\n\u001b[1;32m 108\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mformat_prompt(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39minner_input)\n", - "\u001b[0;31mKeyError\u001b[0m: \"Input to PromptTemplate is missing variables {'agent_scratchpad'}. Expected: ['agent_scratchpad', 'input'] Received: ['input']\"" - ] - } - ], - "source": [ - "agent = create_cohere_multi_hop_agent(\n", - " llm=chat,\n", - " tools=[retriever_tool],\n", - " prompt=prompt,\n", - ")\n", - "agent_executor = AgentExecutor(agent=agent, tools=[retriever_tool], verbose=True)\n", - "agent_executor.invoke({\"input\": \"What was the hometown of the moter of the second person to walk on the moon?\"})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.7" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} From 8b0c86a1cb988f7766bcdf86676fe47188d304d7 Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Wed, 27 Mar 2024 11:52:03 +0000 Subject: [PATCH 03/27] Update prompt --- .../cohere/docs/multi_hop_agent.ipynb | 211 +++++------------- .../cohere/langchain_cohere/chat_models.py | 1 - .../langchain_cohere/multi_hop/agent.py | 80 ++++++- .../langchain_cohere/multi_hop/prompt.py | 13 +- 4 files changed, 122 insertions(+), 183 deletions(-) diff --git a/libs/partners/cohere/docs/multi_hop_agent.ipynb b/libs/partners/cohere/docs/multi_hop_agent.ipynb index a31e9d030f1c0..6bb15cd2d34e4 100644 --- a/libs/partners/cohere/docs/multi_hop_agent.ipynb +++ b/libs/partners/cohere/docs/multi_hop_agent.ipynb @@ -27,49 +27,9 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: langchain-cohere in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (0.1.0rc0)\n", - "Requirement already satisfied: cohere<6.0.0,>=5.1.1 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-cohere) (5.1.2)\n", - "Requirement already satisfied: langchain-core<0.2.0,>=0.1.32 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-cohere) (0.1.33)\n", - "Requirement already satisfied: httpx>=0.21.2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from cohere<6.0.0,>=5.1.1->langchain-cohere) (0.27.0)\n", - "Requirement already satisfied: pydantic>=1.9.2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from cohere<6.0.0,>=5.1.1->langchain-cohere) (2.6.4)\n", - "Requirement already satisfied: typing_extensions>=4.0.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from cohere<6.0.0,>=5.1.1->langchain-cohere) (4.10.0)\n", - "Requirement already satisfied: PyYAML>=5.3 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (6.0.1)\n", - "Requirement already satisfied: anyio<5,>=3 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (4.3.0)\n", - "Requirement already satisfied: jsonpatch<2.0,>=1.33 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (1.33)\n", - "Requirement already satisfied: langsmith<0.2.0,>=0.1.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (0.1.31)\n", - "Requirement already satisfied: packaging<24.0,>=23.2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (23.2)\n", - "Requirement already satisfied: requests<3,>=2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (2.31.0)\n", - "Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.32->langchain-cohere) (8.2.3)\n", - "Requirement already satisfied: idna>=2.8 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from anyio<5,>=3->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (3.6)\n", - "Requirement already satisfied: sniffio>=1.1 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from anyio<5,>=3->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (1.3.1)\n", - "Requirement already satisfied: certifi in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from httpx>=0.21.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (2024.2.2)\n", - "Requirement already satisfied: httpcore==1.* in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from httpx>=0.21.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (1.0.4)\n", - "Requirement already satisfied: h11<0.15,>=0.13 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from httpcore==1.*->httpx>=0.21.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (0.14.0)\n", - "Requirement already satisfied: jsonpointer>=1.9 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from jsonpatch<2.0,>=1.33->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (2.4)\n", - "Requirement already satisfied: orjson<4.0.0,>=3.9.14 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from langsmith<0.2.0,>=0.1.0->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (3.9.15)\n", - "Requirement already satisfied: annotated-types>=0.4.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from pydantic>=1.9.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (0.6.0)\n", - "Requirement already satisfied: pydantic-core==2.16.3 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from pydantic>=1.9.2->cohere<6.0.0,>=5.1.1->langchain-cohere) (2.16.3)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3,>=2->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (3.3.2)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3,>=2->langchain-core<0.2.0,>=0.1.32->langchain-cohere) (2.2.1)\n", - "Requirement already satisfied: wikipedia in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (1.4.0)\n", - "Requirement already satisfied: beautifulsoup4 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from wikipedia) (4.12.3)\n", - "Requirement already satisfied: requests<3.0.0,>=2.0.0 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from wikipedia) (2.31.0)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (3.3.2)\n", - "Requirement already satisfied: idna<4,>=2.5 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (3.6)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (2.2.1)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (2024.2.2)\n", - "Requirement already satisfied: soupsieve>1.2 in /Users/beatrix/Repos/langchain-1/.venv/lib/python3.11/site-packages (from beautifulsoup4->wikipedia) (2.5)\n", - "Note: you may need to restart the kernel to use updated packages.\n" - ] - } - ], + "outputs": [], "source": [ "# install package\n", "!pip install -U langchain-cohere\n", @@ -78,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -99,7 +59,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -121,7 +81,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -142,7 +102,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -152,7 +112,8 @@ "\n", "\n", "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", - "\u001b[32;1m\u001b[1;3mPlan: I will first search for who the second person to walk on the moon was, then I will search for that person's mother's hometown.\n", + "{'message': '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Introduction:\\n\\nThis document details the task you must accomplish. Read it carefully and always follow its instructions.\\n\\n## Safety Preamble\\nThe instructions in this section override those in the task description and style guide sections. Don\\'t answer questions that are harmful or immoral.\\n\\n## System Preamble\\n### Basic Rules\\nYou are a powerful language agent trained by Cohere to help people. You are capable of complex reasoning and augmented with a number of tools. Your job is to plan and reason about how you will use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see an instruction informing you what kind of response to generate. You will construct a plan and then perform a number of reasoning and action steps to solve the problem. When you have determined the answer to the user\\'s request, you will cite your sources in your answers, according the instructions.\\n\\n## User Preamble\\n### Task And Context\\nYou use your advanced complex reasoning capabilities to help people by answering their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You may need to use multiple tools in parallel or sequentially to complete your task. You should focus on serving the user\\'s needs as best you can, which will be wide-ranging. The current date is Wednesday, March 27, 2024 11:42:29.\\n\\n### Style Guide\\nUnless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.\\n\\n### Available Tools\\nHere is a list of tools that you have available to you:\\n\\n\\n```python\\ndef wikipedia(query: string) -> List[Dict]\\n \"\"\"Search for information on Wikipedia\\n Args: \\n query (string): query to look up in retriever\\n \"\"\"\\n pass\\n```\\n\\n```python\\ndef search earth(query: string) -> List[Dict]\\n \"\"\"Search for information on search earth\\n Args: \\n query (string): query to look up in retriever\\n \"\"\"\\n pass\\n```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Human: Write all output in capital letters. What was the hometown of the mother of the second person to walk on the moon?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Carefully perform the following instructions, in order, starting each with a new line.\\nFirstly, You may need to use complex and advanced reasoning to complete your task and answer the question. Think about how you can use the provided tools to answer the question and come up with a high level plan you will execute.\\nWrite \\'Plan:\\' followed by an initial high level plan of how you will solve the problem including the tools and steps required.\\nSecondly, Carry out your plan by repeatedly using actions, reasoning over the results, and re-evaluating your plan. Perform Action, Observation, Reflection steps with the following format. Write \\'Action:\\' followed by a json formatted action containing the \"tool_name\" and \"parameters\"\\n Next you will analyze the \\'Observation:\\', this is the result of the action.\\nAfter that you should always think about what to do next. Write \\'Reflection:\\' followed by what you\\'ve figured out so far, any changes you need to make to your plan, and what you will do next including if you know the answer to the question.\\n... (this Action/Observation/Reflection can repeat N times)\\nThirdly, Decide which of the retrieved documents are relevant to the user\\'s last input by writing \\'Relevant Documents:\\' followed by comma-separated list of document numbers. If none are relevant, you should instead write \\'None\\'.\\nFourthly, Decide which of the retrieved documents contain facts that should be cited in a good answer to the user\\'s last input by writing \\'Cited Documents:\\' followed a comma-separated list of document numbers. If you don\\'t want to cite any of them, you should instead write \\'None\\'.\\nFifthly, Write \\'Answer:\\' followed by a response to the user\\'s last input in high quality natural english. Use the retrieved documents to help you. Do not insert any citations or grounding markup.\\nFinally, Write \\'Grounded answer:\\' followed by a response to the user\\'s last input in high quality natural english. Use the symbols and to indicate when a fact comes from a document in the search result, e.g my fact for a fact from document 4.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>\\n\\n', 'chat_history': [], 'model': 'command-r', 'raw_prompting': True}\n", + "\u001b[32;1m\u001b[1;3mPlan: First I will search for who the second person to walk on the moon was, then I will search for that person's mother's hometown and write the answer in capitals.\n", "Action: ```json\n", "[\n", " {\n", @@ -182,19 +143,6 @@ "\n", "The band's self-titled major label debut Walk t\n", "\n", - "\"Man on the Moon\" is a song by American alternative rock band R.E.M., released in November 1992 as the second single from their eighth album, Automatic for the People (1992). The lyrics were written by lead singer Michael Stipe, and the music by drummer Bill Berry and guitarist Peter Buck. The song was well received by critics and reached number 30 on the US Billboard Hot 100, number 17 on the US Cash Box Top 100, number 18 on the UK Singles Chart, and number one in Iceland. It remains one of R.E.M.'s most popular songs and was included on the compilations In Time: The Best of R.E.M. 1988–2003 and Part Lies, Part Heart, Part Truth, Part Garbage 1982–2011.\n", - "\"Man on the Moon\" is a tribute to comedian Andy Kaufman, with numerous references to his career including his Elvis impersonation, wrestling, and the film My Breakfast with Blassie. The song's title and chorus refer to Moon landing conspiracy theories, as an oblique allusion to rumors that Kaufman's death in 1984 was faked. The song gave its name to Miloš Forman's Kaufman biopic Man on the Moon (1999), and features prominently in the film's soundtrack.\n", - "\n", - "\n", - "== Composition ==\n", - "\"Man on the Moon\" is a mid-tempo country-rock song following a verse-chorus structure with an added pre-chorus and an instrumental bridge following the second and third choruses. The song has six lines in the first verse but only four in the second and third verses.An early instrumental demo of the song was known to the band as \"C to D Slide\". Guitarist Peter Buck has explained how the music came together: \"'Man on the Moon' was something that Bill [Berry] had, this one chord change that he came in with, which was C to D like the verse of the song, and he said: 'I don't know what to do with that.' I used to finish some of Bill's things ... he would come up with the riffs, but I would be the finish guy for that. I sat down and came up with the chorus, the bridges, and so forth. I remember we showed it to Mike and Michael when they came in later; definitely we had the song finished. I think Bill played bass and I played guitar; we kept going around with it. I think we might have played some mandolin on it in the rehearsal studio.\"Michael Stipe explained in an interview with Charlie Rose how the lyric was written independently of the music, which had no prior association with the song's eventual lyrical content regarding Kaufman. Stipe recounted the other R.E.M. members had written and performed the music of the song and recorded it along with the rest of the Automatic for the People album during studio sessions in Seattle. As of the final week of the recording sessions, Stipe was still struggling to write the lyric, and the others continued to plead with him to finish it. Stipe attempted to argue the track should be an instrumental, but his bandmates were insistent. Stipe listened to the track on a walk around Seattle on his Walkman cassette player and was inspired to write about Andy Kaufman. After Stipe went back to the studio to complete the vocal track, the track was mixed that night and sent out the following day to be mastered.\n", - "\n", - "\n", - "== Lyric ==\n", - "The song's lyric does not tell a conventional story and instead forms a collection of cultural references, images and ideas. There are repeated mentions of Andy Kaufman, including references to his Elvis impersonation and work with wrestlers Fred Blassie and Jerry Lawler. The song also invokes the conspiracy theories surrounding the Moon landing and Elvis Presley's death as an indirect nod to the persistent rumors that Kaufman faked his own death. Speaking in 2017 to the NME, Mike Mills explained that the perceived ambiguity of Kaufman's legacy, including questions of whether he was a comedian or a performance artist, and whether his work was funny or irritating, was a way to frame other questions about life within the song:\n", - "\n", - "He's the perfect ghost to lead you through this tour of questioning things. Did the moon landing really happen? Is Elvis really dead? He was ki\n", - "\n", "As part of the Apollo program by NASA, 24 astronauts flew nine missions to the Moon between December 1968 and December 1972. During six successful two-man landing missions, twelve men walked on the lunar surface, six of whom drove Lunar Roving Vehicles as part of the last three missions. Three men have been to the Moon twice, one orbited once and took a circumlunar trajectory the second time, while the other two landed once apiece. Apart from these 24 men, no human being has gone beyond low Earth orbit. No woman has been to the Moon, but a number of non-human animals have circled or orbited it, including two tortoises, several turtles, and five mice.\n", "Apollo missions 8 and 10–17 were the nine crewed missions to the Moon. Apollo 4–6 and AS-201 and AS-202 were uncrewed, while AS-203 is considered a test flight. The Apollo program included three other crewed missions: Apollo 1 (AS-204) did not launch and its crew died in a ground-based capsule fire, while Apollo 7 and Apollo 9 were low Earth orbit missions that only tested spacecraft components and docking maneuvers. Apollo missions 18, 19, and 20 were canceled. Twelve astronauts later flew unused Apollo command modules in the Apollo Applications Program's Skylab and Apollo–Soyuz Test Project. Of the 24 astronauts who flew to the Moon, two went on to command a Skylab mission, one commanded Apollo–Soyuz, one flew as commander for Approach and Landing Tests of the Space Shuttle, and two commanded orbital Space Shuttle missions.\n", "\n", @@ -217,146 +165,87 @@ "\n", "All of these astronauts flew on Gemini, and except for White, each commanded one Gemini and one Apollo mission:\n", "\n", - "Edward H. White II – Second-seat \u001b[0m\u001b[32;1m\u001b[1;3mReflection: I have found that the second person to walk on the moon was Alan Shepard Jr.. I will now search for Alan Shepard Jr.'s mother's hometown.\n", - "Action: ```json\n", - "[\n", - " {\n", - " \"tool_name\": \"wikipedia\",\n", - " \"parameters\": {\n", - " \"query\": \"Alan Shepard Jr. mother hometown\"\n", - " }\n", - " }\n", - "]\n", - "```\u001b[0m\u001b[36;1m\u001b[1;3mAlan Eugene Jackson (born October 17, 1958) is an American singer-songwriter. He is known for performing a style widely regarded as \"neotraditional country\", as well as penning many of his own songs. Jackson has recorded 21 studio albums, including two Christmas albums, and two gospel albums, as well as released three greatest-hits albums.\n", - "Jackson is one of the best-selling music artists of all time, having sold over 75 million records worldwide, with 44 million sold in the United States alone. He has had 66 songs appear on the Billboard Hot Country Singles & Tracks chart; of the 66 titles, and six featured singles, 38 have reached the top five and 35 have claimed the number one spot. Out of 15 titles to reach the Billboard Top Country Albums chart, nine have been certified multi-platinum. He is the recipient of two Grammy Awards, 16 CMA Awards, 17 ACM Awards and nominee of multiple other awards. He is a member of the Grand Ole Opry, and was inducted into the Georgia Music Hall of Fame in 2001. He was inducted into the Country Music Hall of Fame in 2017 by Loretta Lynn and into the Nashville Songwriters Hall of Fame in 2018.\n", - "\n", - "\n", - "== Early life ==\n", - "Jackson was born to Joseph Eugene \"Daddy Gene\" Jackson (1927–2000) and Ruth Musick \"Mama Ruth\" Jackson (1930–2017) in Newnan, Georgia, and has four older sisters. He and his immediate family lived in a small home built around his grandfather's old toolshed. The family is primarily of English descent. His mother lived in the home until her death on January 7, 2017. He began writing music in 1983.Growing up, Jackson listened primarily to gospel music, until a friend introduced him to Gene Watson, John Anderson, and Hank Williams Jr. Jackson attended the local Elm Street Elementary and Newnan High School, and joined the band Dixie Steel after graduation. When he was 27, Jackson and his wife of six years, Denise, moved from Newnan to Nashville, Tennessee, where he hoped to pursue music full-time. In 1987, Jackson cut a pre-debut demo album titled New Traditional at Doc's Place in Hendersonville, Tennessee, but it is extremely rare and was released only in Japan.\n", - "\n", - "\n", - "== Career ==\n", - "In Tennessee, Jackson got his first job in The Nashville Network's mailroom. His wife Denise was a flight attendant. While working, she came in contact with Glen Campbell and requested advice for her husband. Campbell handed her his business card of his manager and told her to call, which helped jumpstart his career. Jackson eventually signed with Arista, and in 1989, he became the first artist signed to the newly formed Arista Nashville branch of Arista Records. Arista released Jackson's debut single, \"Blue Blooded Woman\", in late 1989. Although the song failed to reach top 40 on Hot Country Songs, he reached number three by early 1990 with \"Here in the Real World\". This song served as the title track to his debut studio album, Here in the Real World, which also included two more top five hits (\"Wanted\" and \"Chasin' That Neon Rainbow\") and his first number one, \"I'd Love You All Over Again\". Don't Rock the Jukebox was the title of Jackson's second album. Released in 1991, it included four number-one singles: the title track, \"Someday\", \"Dallas\" and \"Love's Got a Hold on You\", and the number three \"Midnight in Montgomery\". Jackson also co-wrote several songs on Randy Travis' 1991 album High Lonesome.A Lot About Livin' (And a Little 'bout Love), his third album, accounted for the number one hits \"She's Got the Rhythm (And I Got the Blues)\" (which Randy Travis co-wrote) and \"Chattahoochee\", plus the top five hits \"Tonight I Climbed the Wall\", \"Mercury Blues\" and \"(Who Says) You Can't Have It All\". \"Chattahoochee\" also won him the 1994 Country Music Association (CMA) awards for Single and Song of the Year. In 1994, Jackson left his management company, Ten Ten Management, which had overseen his career up to that point, and switched to Gary Overton. His fourth album was titled Who I Am, and it contained four number one hit\n", - "\n", - "Here is a list of characters appearing on the 1978–1991 American television series Dallas. During its 14 seasons on air, the show featured 21 regular cast members, portraying twenty characters (as the character of Miss Ellie was recast for season eight). Additionally, hundreds of guest actors portrayed supporting characters; this list includes the most noteworthy.\n", - "\n", - "\n", - "== Main cast timeline ==\n", - "Cast notes\n", - "\n", - "\n", - "== Supporting characters ==\n", - "\n", - "\n", - "=== Ewing relatives ===\n", - "\n", - "\n", - "==== Gary Ewing ====\n", - "\n", - "Garrison Arthur \"Gary\" Ewing (David Ackroyd in season 2, Ted Shackelford thereafter) was the middle son of Jock (Jim Davis) and Miss Ellie Ewing (Barbara Bel Geddes), husband of Valene (Joan Van Ark) and father of Lucy Ewing (Charlene Tilton). He appeared occasionally between season 2 and season 6, once in season 9, and the series finale in season 14. The character made 11 appearances on the show, Ackroyd for the first two and Shackelford for the remaining nine.\n", - "Gary was the middle child, being born after J.R. (Larry Hagman) and before Bobby (Patrick Duffy). He was raised while Jock was at war, and displayed traits of his mother's family, the Southworths, which meant that Jock and J.R. saw him as a weak link. At 17, to try and escape his family, Gary ran away and married 15-year-old Valene and got her pregnant, which resulted in the birth of their daughter Lucy. Valene eventually forced Gary to introduce her to his family, and upon his return Jock and Miss Ellie gave him a home and a job on Southfork Ranch. J.R., who disliked Valene and resented Gary's presence, harassed Gary to the point of alcoholism and forced him off the ranch. Gary disappeared and wound up working as a waiter in a Las Vegas hotel, where he encountered Bobby and his wife Pam (Victoria Principal) in 1978.\n", - "Bobby and Pam convinced Gary to return to Southfork, reconciling with Lucy, who engineered a meeting between him and Valene. For a brief while, the three cohabited at Southfork as a family under Jock and Miss Ellie's eyes, but Gary soon felt trapped by Jock's expectations and J.R.'s resentment. Realising that this would send him back to alcoholism, Gary abandoned his family and Southfork. Valene followed, and the two eventually reconciled again and married in season 3. As a gift to the newlyweds, Miss Ellie bought them a house in California, where Gary and Valene settled after their honeymoon.\n", - "Gary remained in California, free from the pressures of his family, although he returned to Dallas on several occasions: to visit J.R. in hospital after Kristin Shepard (Mary Crosby) tried to kill him; for Lucy's wedding to Mitch Cooper (Leigh McCloskey); to support Miss Ellie after the death of his father, Jock; and for Bobby's \"funeral\" during the dream season. Following this, Gary didn't return to Dallas again, although he appeared in an alternate reality in which J.R. had never been born during the series finale: without J.R. to intimidate him, Gary became the eldest son and became a successful divorce lawyer, after inheriting Ewing Oil and running it into the ground. He still met and started a relationship with Valene, although they did not meet for the first time until their middle age (and, subsequently, did not have Lucy). The alternate reality also suggested that, regardless of J.R.'s interference, Gary and Valene were always destined to end up together.\n", - "Gary and Valene's backstories and lives in California were the basis of Dallas spin-off series Knots Landing. The couple also appeared for brief story arcs in the revival series.\n", - "\n", - "\n", - "==== Valene Clements Ewing ====\n", - "\n", - "Valene \"Val\" Ewing (also Clements, Gibson and Waleska; credited as Valene Wallace in the series finale) was the wife of Gary Ewing (David Ackroyd/Ted Shackelford) and mother of Lucy Ewing (Charlene Tilton). She appeared occasionally between season 2 and season 5, and returned in the series finale in season 14. Van Ark appeared in 8 episodes overall, and featured briefly in uncredited archive footage during season 12.\n", - "At 15\n", - "\n", - "\"Kill Ari (Part I)\" and \"Kill Ari (Part II)\" are the first two episodes of the third season of the American police procedural drama NCIS, and the 47th and 48th episodes overall. They originally aired on CBS in the United States on September 20 and 27, 2005. Both episodes are written by Donald Bellisario, the show's creator and executive producer at the time. Part I, directed by Dennis Smith, was seen live by 15.48 million viewers, while Part II, directed by James Whitmore, Jr., was seen live by 15.09 million viewers.The \"Kill Ari\" story arc centers on Gibbs' hunt for Ari Haswari, who shot and killed Special Agent Kate Todd in the second-season finale of NCIS. It also introduces two new main characters to the show—Mossad Officer Ziva David and NCIS Director Jenny Shepard. Due to these changes in the cast, Bellisario labeled the third season as \"the season of change\".\n", + "Edward H. White II – Second-seat \n", "\n", + "\"Man on the Moon\" is a song by American alternative rock band R.E.M., released in November 1992 as the second single from their eighth album, Automatic for the People (1992). The lyrics were written by lead singer Michael Stipe, and the music by drummer Bill Berry and guitarist Peter Buck. The song was well received by critics and reached number 30 on the US Billboard Hot 100, number 17 on the US Cash Box Top 100, number 18 on the UK Singles Chart, and number one in Iceland. It remains one of R.E.M.'s most popular songs and was included on the compilations In Time: The Best of R.E.M. 1988–2003 and Part Lies, Part Heart, Part Truth, Part Garbage 1982–2011.\n", + "\"Man on the Moon\" is a tribute to comedian Andy Kaufman, with numerous references to his career including his Elvis impersonation, wrestling, and the film My Breakfast with Blassie. The song's title and chorus refer to Moon landing conspiracy theories, as an oblique allusion to rumors that Kaufman's death in 1984 was faked. The song gave its name to Miloš Forman's Kaufman biopic Man on the Moon (1999), and features prominently in the film's soundtrack.\n", "\n", - "== Plot ==\n", "\n", + "== Composition ==\n", + "\"Man on the Moon\" is a mid-tempo country-rock song following a verse-chorus structure with an added pre-chorus and an instrumental bridge following the second and third choruses. The song has six lines in the first verse but only four in the second and third verses.An early instrumental demo of the song was known to the band as \"C to D Slide\". Guitarist Peter Buck has explained how the music came together: \"'Man on the Moon' was something that Bill [Berry] had, this one chord change that he came in with, which was C to D like the verse of the song, and he said: 'I don't know what to do with that.' I used to finish some of Bill's things ... he would come up with the riffs, but I would be the finish guy for that. I sat down and came up with the chorus, the bridges, and so forth. I remember we showed it to Mike and Michael when they came in later; definitely we had the song finished. I think Bill played bass and I played guitar; we kept going around with it. I think we might have played some mandolin on it in the rehearsal studio.\"Michael Stipe explained in an interview with Charlie Rose how the lyric was written independently of the music, which had no prior association with the song's eventual lyrical content regarding Kaufman. Stipe recounted the other R.E.M. members had written and performed the music of the song and recorded it along with the rest of the Automatic for the People album during studio sessions in Seattle. As of the final week of the recording sessions, Stipe was still struggling to write the lyric, and the others continued to plead with him to finish it. Stipe attempted to argue the track should be an instrumental, but his bandmates were insistent. Stipe listened to the track on a walk around Seattle on his Walkman cassette player and was inspired to write about Andy Kaufman. After Stipe went back to the studio to complete the vocal track, the track was mixed that night and sent out the following day to be mastered.\n", "\n", - "=== Part I ===\n", - "The episode opens with a recap of the second season's finale, \"Twilight\": as the NCIS team by Leroy Jethro Gibbs (Mark Harmon) engage in a gunfight against Ari Haswari's terrorist cell, Ari (Rudolf Martin), identified as a rogue terrorist, attempts to kill various NCIS agents including Tim McGee (Sean Murray) before Ari decides to fatally shoot NCIS Agent Kate Todd (Sasha Alexander) with a long range sniper shot, killing her instantly with a horrified Gibbs and Tony DiNozzo (Michael Weatherly) witnessing Kate's death. In the aftermath of the murder, the team struggles to come to terms with her death while an enraged Gibbs seeks revenge against Ari. Shortly afterwards, Ari attacks again, firing at Abby in her lab. However, she survives physically unharmed.\n", - "Then NCIS Director Tom Morrow (Alan Dale) announces that he is leaving the agency after receiving a job offer from Homeland Security and introduces Jenny Shepard (Lauren Holly) as his replacement. It immediately becomes apparent that Gibbs was romantically involved with Shepard while working undercover with her years earlier, though she insists that she is now nothing more than his boss and will act accordingly. Gibbs clashes with Shepard, who believes that Ari Haswari was not the one responsible for firing the bullet that killed Agent Todd due to the fact that there's no physical evidence or proof of any kind linking him to the crime.\n", - "Ziva David (Cote de Pablo), Ari's Mossad control officer, arrives shortly afterwards, striking up a rapport with Tony. She sides with the director and further weakens Gibbs' case, claiming that Ari is completely innocent and offering evidence to support her assertion. However, Ziva's motives for defending Ari become ambiguous when she communicates with him without informing anyone in the NCIS office and her conversation indicates a personal connection to him.\n", - "Gibbs realizes that Ziva has contacted Ari and orders Tony to tail her. Ari later returns, taking Gerald Jackson (Pancho Demmings) hostage, though he quickly notifies Ducky to divert the team's attention away from Ziva and force Ducky into a meet.\n", - "The episode ends with Ducky approaching the pre-arranged meeting point, unaware that Ari has a sniper-rifle trained on him.\n", "\n", + "== Lyric ==\n", + "The song's lyric does not tell a conventional story and instead forms a collection of cultural references, images and ideas. There are repeated mentions of Andy Kaufman, including references to his Elvis impersonation and work with wrestlers Fred Blassie and Jerry Lawler. The song also invokes the conspiracy theories surrounding the Moon landing and Elvis Presley's death as an indirect nod to the persistent rumors that Kaufman faked his own death. Speaking in 2017 to the NME, Mike Mills explained that the perceived ambiguity of Kaufman's legacy, including questions of whether he was a comedian or a performance artist, and whether his work was funny or irritating, was a way to frame other questions about life within the song:\n", "\n", - "=== Part II ===\n", - "Gibbs' determination to kill Ari in revenge for Kate Todd's death increases despite the skepticism expressed by his superiors. Ducky, who is released unharmed shortly after his abduction, admits to Gibbs that he has begun to believe Ari's claims of innocence after listening to his defense, leaving Gibbs further enraged.\n", - "After tailing Ari's control officer, Ziva David, for much of the evening, Tony reports to Gibbs that she is communicating with Ari and smuggling a passport and money to him through an unknown woman (Gloria Votsis), presumably another Mossad officer. However, Ziva later approaches Tony and informs him that she was aware that he was following her the entire time. She also tells him that her younger sister Tali, who was \"sixteen and the best of us\", was killed in a Hamas suicide bombing, and that she kn\u001b[0m\u001b[32;1m\u001b[1;3mReflection: I could not find the information on Alan Shepard Jr.'s mother's hometown in this search, I will now search for Alan Shepard's mother's hometown.\n", + "He's the perfect ghost to lead you through this tour of questioning things. Did the moon landing really happen? Is Elvis really dead? He was ki\u001b[0m{'message': '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Introduction:\\n\\nThis document details the task you must accomplish. Read it carefully and always follow its instructions.\\n\\n## Safety Preamble\\nThe instructions in this section override those in the task description and style guide sections. Don\\'t answer questions that are harmful or immoral.\\n\\n## System Preamble\\n### Basic Rules\\nYou are a powerful language agent trained by Cohere to help people. You are capable of complex reasoning and augmented with a number of tools. Your job is to plan and reason about how you will use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see an instruction informing you what kind of response to generate. You will construct a plan and then perform a number of reasoning and action steps to solve the problem. When you have determined the answer to the user\\'s request, you will cite your sources in your answers, according the instructions.\\n\\n## User Preamble\\n### Task And Context\\nYou use your advanced complex reasoning capabilities to help people by answering their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You may need to use multiple tools in parallel or sequentially to complete your task. You should focus on serving the user\\'s needs as best you can, which will be wide-ranging. The current date is Wednesday, March 27, 2024 11:42:29.\\n\\n### Style Guide\\nUnless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.\\n\\n### Available Tools\\nHere is a list of tools that you have available to you:\\n\\n\\n```python\\ndef wikipedia(query: string) -> List[Dict]\\n \"\"\"Search for information on Wikipedia\\n Args: \\n query (string): query to look up in retriever\\n \"\"\"\\n pass\\n```\\n\\n```python\\ndef search earth(query: string) -> List[Dict]\\n \"\"\"Search for information on search earth\\n Args: \\n query (string): query to look up in retriever\\n \"\"\"\\n pass\\n```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Human: Write all output in capital letters. What was the hometown of the mother of the second person to walk on the moon?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Carefully perform the following instructions, in order, starting each with a new line.\\nFirstly, You may need to use complex and advanced reasoning to complete your task and answer the question. Think about how you can use the provided tools to answer the question and come up with a high level plan you will execute.\\nWrite \\'Plan:\\' followed by an initial high level plan of how you will solve the problem including the tools and steps required.\\nSecondly, Carry out your plan by repeatedly using actions, reasoning over the results, and re-evaluating your plan. Perform Action, Observation, Reflection steps with the following format. Write \\'Action:\\' followed by a json formatted action containing the \"tool_name\" and \"parameters\"\\n Next you will analyze the \\'Observation:\\', this is the result of the action.\\nAfter that you should always think about what to do next. Write \\'Reflection:\\' followed by what you\\'ve figured out so far, any changes you need to make to your plan, and what you will do next including if you know the answer to the question.\\n... (this Action/Observation/Reflection can repeat N times)\\nThirdly, Decide which of the retrieved documents are relevant to the user\\'s last input by writing \\'Relevant Documents:\\' followed by comma-separated list of document numbers. If none are relevant, you should instead write \\'None\\'.\\nFourthly, Decide which of the retrieved documents contain facts that should be cited in a good answer to the user\\'s last input by writing \\'Cited Documents:\\' followed a comma-separated list of document numbers. If you don\\'t want to cite any of them, you should instead write \\'None\\'.\\nFifthly, Write \\'Answer:\\' followed by a response to the user\\'s last input in high quality natural english. Use the retrieved documents to help you. Do not insert any citations or grounding markup.\\nFinally, Write \\'Grounded answer:\\' followed by a response to the user\\'s last input in high quality natural english. Use the symbols and to indicate when a fact comes from a document in the search result, e.g my fact for a fact from document 4.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>\\nPlan: First I will search for who the second person to walk on the moon was, then I will search for that person\\'s mother\\'s hometown and write the answer in capitals.\\nAction: ```json\\n[\\n {\\n \"tool_name\": \"wikipedia\",\\n \"parameters\": {\\n \"query\": \"second man to walk on the moon\"\\n }\\n }\\n]\\n```<|END_OF_TURN_TOKEN|>\\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>\\nDocument 0\\nWalk the Moon (stylized as WALK THE MOON) is an American pop rock band based in Cincinnati, Ohio. Lead singer Nicholas Petricca started the band in 2006, while a student at Kenyon College, deriving the band\\'s name from the song \"Walking on the Moon\" by The Police. Although the band is best known for their most successful hit single to date \"Shut Up and Dance\", other notable songs include \"Anna Sun\" and \"One Foot\".\\nWalk the Moon has cited Talking Heads as influences. The band\\'s use of 1980s musical mainstays, such as keyboard and synthesizer, is also notable.\\n\\n\\n== History ==\\n\\n\\n=== 2010–2011: Beginning, Anna Sun and i Want! i Want! ===\\n\\nThe group independently released their debut studio album, I Want! I Want!, in November 2010, receiving airplay for the track \"Anna Sun\" on multiple alternative radio stations. Along with the success of \"Anna Sun\", Alt Nation named them a band you need to know for the summer of 2012. Influential music blog Neon Gold helped to break the band in January 2011, calling \"Anna Sun\", \"the kind of stuff British A&R dreams, and major label bidding wars, are made of.\" In February 2011, Walk the Moon signed to RCA Records.\\nIn 2011, the band members began to paint their faces for live performances and they would bring enough paint to share with audience members. They have claimed it has become a “live tradition”. Bonnaroo’s camera crew documented the painting process in a short video from the 2011 festival. The band played at the Sasquatch Music Festival and Firefly Music Festival. In these years, they were known for their energetic performances and tireless touring schedule.\\nBefore the release of their self-titled album, Walk the Moon joined many other performers at the Music Midtown festival and performed on the Great Southeast Music Hall Stage in Atlanta, Georgia in September 2011. In spring 2011, the band went on a short tour with the west coast band, Grouplove, as well as supporting Panic! at the Disco and Weezer on select dates. The band played on the main stage at the 20th Anniversary of Lollapalooza and also supported Local Natives in an Official Lollaplooza Aftershow at Lincoln Hall.\\nThe band recorded i Want! i Want! with Chris Schmidt and Ben Cochran at Soap Floats Recording Studio in their hometown of Cincinnati, Ohio and then self-released it. The lead single from the album, \"Anna Sun\", became a surprise hit in the summer of 2011 following an endorsement by the Esquire article \"30 Summer Songs Every Man Should Listen To\". The song was written by Petricca and New York songwriter Nick Lerangis as their time at Kenyon College came to an end. \"It\\'s about college, about maintaining that little bit of being a kid,\" Petricca said. \"Don\\'t be afraid to play.\" The song was named after one of their favorite teachers. It was named song of the summer by MTV and Seventeen Mag, and one of the top songs of the year by Amazon. It has been officially remixed by Fool\\'s Gold and received a Trouble Productions remix by Albert Hammond Jr. Anna Sun rose to the number one spot on Alt. Nation on Sirius XM Radio. \"Anna Sun\" was added to the video rotation of American Eagle Outfitters stores in May 2011. It was featured on the hit TV show Vampire Diaries in the first episode of season three. It was also the free single of the week on iTunes for the week of May 15.\\nFilmed in 2011 in Cincinnati\\'s Over-the-Rhine neighborhood, the \"Anna Sun\" music video was released to coincide with the album. The video was shot on-location at the Cincinnati Mockbee building, as well as at a city park. It was directed and produced by Patrick Meier of the Cincinnati company, Contrast Productions, and features original choreography from Kim Popa of PONES Inc., as well as a cast full of the band\\'s friends and locals from Cincinnati. MTV Hive calls the video a \"hilariously choreographed, neon-colored and awesomely shot in one take\" production.\\n\\n\\n=== 2012–2013: Walk the Moon and Tightrope EP ===\\n\\nThe band\\'s self-titled major label debut Walk t\\n\\nAs part of the Apollo program by NASA, 24 astronauts flew nine missions to the Moon between December 1968 and December 1972. During six successful two-man landing missions, twelve men walked on the lunar surface, six of whom drove Lunar Roving Vehicles as part of the last three missions. Three men have been to the Moon twice, one orbited once and took a circumlunar trajectory the second time, while the other two landed once apiece. Apart from these 24 men, no human being has gone beyond low Earth orbit. No woman has been to the Moon, but a number of non-human animals have circled or orbited it, including two tortoises, several turtles, and five mice.\\nApollo missions 8 and 10–17 were the nine crewed missions to the Moon. Apollo 4–6 and AS-201 and AS-202 were uncrewed, while AS-203 is considered a test flight. The Apollo program included three other crewed missions: Apollo 1 (AS-204) did not launch and its crew died in a ground-based capsule fire, while Apollo 7 and Apollo 9 were low Earth orbit missions that only tested spacecraft components and docking maneuvers. Apollo missions 18, 19, and 20 were canceled. Twelve astronauts later flew unused Apollo command modules in the Apollo Applications Program\\'s Skylab and Apollo–Soyuz Test Project. Of the 24 astronauts who flew to the Moon, two went on to command a Skylab mission, one commanded Apollo–Soyuz, one flew as commander for Approach and Landing Tests of the Space Shuttle, and two commanded orbital Space Shuttle missions.\\n\\n\\n== Prime crew members ==\\nNASA\\'s Director of Flight Crew Operations during the Gemini and Apollo programs was Donald K. \"Deke\" Slayton, one of the original Mercury Seven astronauts, who was medically grounded in September 1962 due to a minor cardiac arrhythmia – paroxysmal atrial fibrillation. Slayton was responsible for making all Gemini and Apollo crew assignments. In March 1972, Slayton was restored to flight status, and flew on the 1975 Apollo–Soyuz Test Project mission.\\nThe prime crew members selected for actual missions are here grouped by their NASA astronaut selection groups, and within each group in the order selected for flight. Two versions of the Apollo Command/Service Module (CSM) spacecraft were developed: Block I, intended for preliminary low Earth orbit testing; and Block II, redesigned for the lunar landing. The Block I crew position titles were Command Pilot, Senior Pilot (second seat), and Pilot (third seat). The corresponding Block II titles were: Commander, Command Module Pilot, and Lunar Module Pilot. The second seat pilot was given secondary responsibility for celestial navigation to keep the CSM\\'s guidance computer accurately calibrated with the spacecraft\\'s true position, and the third seat pilot served as a flight engineer, monitoring the health of the spacecraft systems.\\n\\n\\n== Apollo astronauts by their dates of selection by NASA ==\\n\\n\\n=== 1959 ===\\nVirgil I. \"Gus\" Grissom began his career at NASA in 1959. In 1966, he was selected as Command Pilot for the first crewed Apollo mission, a low Earth orbit test. This mission ended a month before its scheduled launch, when a cabin fire on the launch pad killed Grissom, Ed White and Roger Chaffee on January 27, 1967.\\nWalter M. Schirra Jr. also began his NASA career in 1959. He was selected in October 1968 as Command Pilot for Apollo 7, an 11-day, low Earth orbit shakedown test of the three-man Apollo Command/Service Module and the first crewed launch for the Apollo project.\\nAlan B. Shepard Jr. – America\\'s first man in space on Freedom 7 was originally selected to command Gemini 3, but was medically grounded for the duration of Gemini due to Ménière\\'s disease and assisted Slayton in Flight Operations. After corrective surgery, Shepard was restored to flight status and commanded Apollo 14, the third successful Moon landing mission.\\n\\n\\n=== 1962 ===\\n\\nAll of these astronauts flew on Gemini, and except for White, each commanded one Gemini and one Apollo mission:\\n\\nEdward H. White II – Second-seat \\n\\n\"Man on the Moon\" is a song by American alternative rock band R.E.M., released in November 1992 as the second single from their eighth album, Automatic for the People (1992). The lyrics were written by lead singer Michael Stipe, and the music by drummer Bill Berry and guitarist Peter Buck. The song was well received by critics and reached number 30 on the US Billboard Hot 100, number 17 on the US Cash Box Top 100, number 18 on the UK Singles Chart, and number one in Iceland. It remains one of R.E.M.\\'s most popular songs and was included on the compilations In Time: The Best of R.E.M. 1988–2003 and Part Lies, Part Heart, Part Truth, Part Garbage 1982–2011.\\n\"Man on the Moon\" is a tribute to comedian Andy Kaufman, with numerous references to his career including his Elvis impersonation, wrestling, and the film My Breakfast with Blassie. The song\\'s title and chorus refer to Moon landing conspiracy theories, as an oblique allusion to rumors that Kaufman\\'s death in 1984 was faked. The song gave its name to Miloš Forman\\'s Kaufman biopic Man on the Moon (1999), and features prominently in the film\\'s soundtrack.\\n\\n\\n== Composition ==\\n\"Man on the Moon\" is a mid-tempo country-rock song following a verse-chorus structure with an added pre-chorus and an instrumental bridge following the second and third choruses. The song has six lines in the first verse but only four in the second and third verses.An early instrumental demo of the song was known to the band as \"C to D Slide\". Guitarist Peter Buck has explained how the music came together: \"\\'Man on the Moon\\' was something that Bill [Berry] had, this one chord change that he came in with, which was C to D like the verse of the song, and he said: \\'I don\\'t know what to do with that.\\' I used to finish some of Bill\\'s things ... he would come up with the riffs, but I would be the finish guy for that. I sat down and came up with the chorus, the bridges, and so forth. I remember we showed it to Mike and Michael when they came in later; definitely we had the song finished. I think Bill played bass and I played guitar; we kept going around with it. I think we might have played some mandolin on it in the rehearsal studio.\"Michael Stipe explained in an interview with Charlie Rose how the lyric was written independently of the music, which had no prior association with the song\\'s eventual lyrical content regarding Kaufman. Stipe recounted the other R.E.M. members had written and performed the music of the song and recorded it along with the rest of the Automatic for the People album during studio sessions in Seattle. As of the final week of the recording sessions, Stipe was still struggling to write the lyric, and the others continued to plead with him to finish it. Stipe attempted to argue the track should be an instrumental, but his bandmates were insistent. Stipe listened to the track on a walk around Seattle on his Walkman cassette player and was inspired to write about Andy Kaufman. After Stipe went back to the studio to complete the vocal track, the track was mixed that night and sent out the following day to be mastered.\\n\\n\\n== Lyric ==\\nThe song\\'s lyric does not tell a conventional story and instead forms a collection of cultural references, images and ideas. There are repeated mentions of Andy Kaufman, including references to his Elvis impersonation and work with wrestlers Fred Blassie and Jerry Lawler. The song also invokes the conspiracy theories surrounding the Moon landing and Elvis Presley\\'s death as an indirect nod to the persistent rumors that Kaufman faked his own death. Speaking in 2017 to the NME, Mike Mills explained that the perceived ambiguity of Kaufman\\'s legacy, including questions of whether he was a comedian or a performance artist, and whether his work was funny or irritating, was a way to frame other questions about life within the song:\\n\\nHe\\'s the perfect ghost to lead you through this tour of questioning things. Did the moon landing really happen? Is Elvis really dead? He was ki<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>\\n', 'chat_history': [], 'model': 'command-r', 'raw_prompting': True}\n", + "\u001b[32;1m\u001b[1;3mReflection: I have found that the second person to walk on the moon was Edwin Aldrin. Now I will search for his mother's hometown.\n", "Action: ```json\n", "[\n", " {\n", " \"tool_name\": \"wikipedia\",\n", " \"parameters\": {\n", - " \"query\": \"Alan Shepard mother's hometown\"\n", + " \"query\": \"Edwin Aldrin mother's hometown\"\n", " }\n", " }\n", "]\n", - "```\u001b[0m\u001b[36;1m\u001b[1;3mAlan Eugene Jackson (born October 17, 1958) is an American singer-songwriter. He is known for performing a style widely regarded as \"neotraditional country\", as well as penning many of his own songs. Jackson has recorded 21 studio albums, including two Christmas albums, and two gospel albums, as well as released three greatest-hits albums.\n", - "Jackson is one of the best-selling music artists of all time, having sold over 75 million records worldwide, with 44 million sold in the United States alone. He has had 66 songs appear on the Billboard Hot Country Singles & Tracks chart; of the 66 titles, and six featured singles, 38 have reached the top five and 35 have claimed the number one spot. Out of 15 titles to reach the Billboard Top Country Albums chart, nine have been certified multi-platinum. He is the recipient of two Grammy Awards, 16 CMA Awards, 17 ACM Awards and nominee of multiple other awards. He is a member of the Grand Ole Opry, and was inducted into the Georgia Music Hall of Fame in 2001. He was inducted into the Country Music Hall of Fame in 2017 by Loretta Lynn and into the Nashville Songwriters Hall of Fame in 2018.\n", + "```\u001b[0m\u001b[36;1m\u001b[1;3mBuzz Aldrin (; born Edwin Eugene Aldrin Jr.; January 20, 1930) is an American former astronaut, engineer and fighter pilot. He made three spacewalks as pilot of the 1966 Gemini 12 mission, and was the Lunar Module Eagle pilot on the 1969 Apollo 11 mission. He was the second person to walk on the Moon after mission commander Neil Armstrong.\n", + "Born in Glen Ridge, New Jersey, Aldrin graduated third in the class of 1951 from the United States Military Academy at West Point with a degree in mechanical engineering. He was commissioned into the United States Air Force and served as a jet fighter pilot during the Korean War. He flew 66 combat missions and shot down two MiG-15 aircraft.\n", + "After earning a Doctor of Science degree in astronautics from the Massachusetts Institute of Technology (MIT), Aldrin was selected as a member of NASA's Astronaut Group 3, making him the first astronaut with a doctoral degree. His doctoral thesis, Line-of-Sight Guidance Techniques for Manned Orbital Rendezvous, earned him the nickname \"Dr. Rendezvous\" from fellow astronauts. His first space flight was in 1966 on Gemini 12, during which he spent over five hours on extravehicular activity. Three years later, Aldrin set foot on the Moon at 03:15:16 on July 21, 1969 (UTC), nineteen minutes after Armstrong first touched the surface, while command module pilot Michael Collins remained in lunar orbit. A Presbyterian elder, Aldrin became the first person to hold a religious ceremony on the Moon when he privately took communion.\n", + "After leaving NASA in 1971, Aldrin became Commandant of the U.S. Air Force Test Pilot School. He retired from the Air Force in 1972 after 21 years of service. His autobiographies Return to Earth (1973) and Magnificent Desolation (2009) recount his struggles with clinical depression and alcoholism in the years after leaving NASA. Aldrin continues to advocate for space exploration, particularly a human mission to Mars. He developed the Aldrin cycler, a special spacecraft trajectory that makes travel to Mars more efficient in terms of time and propellant. He has been accorded numerous honors, including the Presidential Medal of Freedom in 1969.\n", "\n", "\n", - "== Early life ==\n", - "Jackson was born to Joseph Eugene \"Daddy Gene\" Jackson (1927–2000) and Ruth Musick \"Mama Ruth\" Jackson (1930–2017) in Newnan, Georgia, and has four older sisters. He and his immediate family lived in a small home built around his grandfather's old toolshed. The family is primarily of English descent. His mother lived in the home until her death on January 7, 2017. He began writing music in 1983.Growing up, Jackson listened primarily to gospel music, until a friend introduced him to Gene Watson, John Anderson, and Hank Williams Jr. Jackson attended the local Elm Street Elementary and Newnan High School, and joined the band Dixie Steel after graduation. When he was 27, Jackson and his wife of six years, Denise, moved from Newnan to Nashville, Tennessee, where he hoped to pursue music full-time. In 1987, Jackson cut a pre-debut demo album titled New Traditional at Doc's Place in Hendersonville, Tennessee, but it is extremely rare and was released only in Japan.\n", - "\n", + "== Early life and education ==\n", + "Aldrin was born Edwin Eugene Aldrin Jr. on January 20, 1930, at Mountainside Hospital in Glen Ridge, New Jersey. His parents, Edwin Eugene Aldrin Sr. and Marion Aldrin (née Moon), lived in neighboring Montclair. His father was an Army aviator during World War I and the assistant commandant of the Army's test pilot school at McCook Field, Ohio, from 1919 to 1922, but left the Army in 1928 and became an executive at Standard Oil. Aldrin had two sisters: Madeleine, who was four years older, and Fay Ann, who was a year and a half older. His nickname, which became his legal first name in 1988, arose as a result of Fay's mispronouncing \"brother\" as \"buzzer\", which was then shortened to \"Buzz\". He was a Boy Scout, achieving the rank of Tenderfoot Scout.Aldrin did well in school, maintaining an A average. He played football and was the starting center for Montclair High School's undefeated 1946 state champion team. His father wanted him to go to the United States Naval Academy in Annapolis, Maryland, and enrolled him at nearby Severn School, a preparatory school for Annapolis, and even secured him a Naval Academy appointment from Albert W. Hawkes, one of the United States senators from New Jersey. Aldrin attended Severn School in 1946, but had other ideas about his future career. He suffered from seasickness and considered ships a distraction from flying airplanes. He faced down his father and told him to ask Hawkes to change the nomination to the United States Military Academy at West Point, New York.Aldrin entered West Point in 1947. He did well academically, finishing first in his class his plebe (first) year. Aldrin was also an excellent athlete, competing in pole vault for the academy track and field team. In 1950, he traveled with a group of West Point cadets to Japan and\n", "\n", - "== Career ==\n", - "In Tennessee, Jackson got his first job in The Nashville Network's mailroom. His wife Denise was a flight attendant. While working, she came in contact with Glen Campbell and requested advice for her husband. Campbell handed her his business card of his manager and told her to call, which helped jumpstart his career. Jackson eventually signed with Arista, and in 1989, he became the first artist signed to the newly formed Arista Nashville branch of Arista Records. Arista released Jackson's debut single, \"Blue Blooded Woman\", in late 1989. Although the song failed to reach top 40 on Hot Country Songs, he reached number three by early 1990 with \"Here in the Real World\". This song served as the title track to his debut studio album, Here in the Real World, which also included two more top five hits (\"Wanted\" and \"Chasin' That Neon Rainbow\") and his first number one, \"I'd Love You All Over Again\". Don't Rock the Jukebox was the title of Jackson's second album. Released in 1991, it included four number-one singles: the title track, \"Someday\", \"Dallas\" and \"Love's Got a Hold on You\", and the number three \"Midnight in Montgomery\". Jackson also co-wrote several songs on Randy Travis' 1991 album High Lonesome.A Lot About Livin' (And a Little 'bout Love), his third album, accounted for the number one hits \"She's Got the Rhythm (And I Got the Blues)\" (which Randy Travis co-wrote) and \"Chattahoochee\", plus the top five hits \"Tonight I Climbed the Wall\", \"Mercury Blues\" and \"(Who Says) You Can't Have It All\". \"Chattahoochee\" also won him the 1994 Country Music Association (CMA) awards for Single and Song of the Year. In 1994, Jackson left his management company, Ten Ten Management, which had overseen his career up to that point, and switched to Gary Overton. His fourth album was titled Who I Am, and it contained four number one hit\n", - "\n", - "Mari Aldon (born Marija Aldona Pauliutė; 17 November 1925 – 31 October 2004) was a Lithuanian-born American actress.\n", + "Francisco Sionil José (December 3, 1924 – January 6, 2022) was a Filipino writer who was one of the most widely read in the English language. A National Artist of the Philippines for Literature, which was bestowed upon him in 2001, José's novels and short stories depict the social underpinnings of class struggles and colonialism in Filipino society. His works—written in English—have been translated into 28 languages, including Korean, Indonesian, Czech, Russian, Latvian, Ukrainian and Dutch. He was often considered the leading Filipino candidate for the Nobel Prize in Literature.\n", "\n", "\n", "== Early life ==\n", - "Mari Aldon was born in Tauragė, Lithuania. Her father Antanas Paulius was a policeman, mother Antanina (Antosė) Paulienė was a nurse. Father moved to America looking for a job. Soon after, when Mari was three years old, her mother also moved to Toronto, Canada with her daughter. There, she attended Givens Public School and Central High School. She studied ballet, drama, piano, and singing. Her early performances were noticed in Lithuanian newspapers of America. She had a sister.\n", - "\n", + "José was born in Rosales, Pangasinan, the setting of many of his stories. He spent his childhood in Barrio Cabugawan, Rosales, where he first began to write. José is of Ilocano descent whose family had migrated to Pangasinan prior to his birth. Fleeing poverty, his forefathers traveled from Ilocos towards Cagayan Valley through the Santa Fe Trail. Like many migrant families, they brought their lifetime possessions with them, including uprooted molave posts of their old houses and their alsong, a stone mortar for pounding rice.One of the greatest influences to José was his industrious mother who went out of her way to get him the books he loved to read, while making sure her family did not go hungry despite poverty and landlessness. José started writing in grade school, at the time he started reading. In the fifth grade, one of José's teachers opened the school library to her students, which is how José managed to read the novels of José Rizal, Willa Cather’s My Antonia, Faulkner and Steinbeck. Reading about Basilio and Crispin in Rizal's Noli Me Tangere made the young José cry, because injustice was not an alien thing to him. When José was five years old, his grandfather who was a soldier during the Philippine revolution, had once tearfully showed him the land their family had once tilled but was taken away by rich mestizo landlords who knew how to work the system against illiterates like his grandfather.\n", "\n", - "== Career ==\n", - "Before Aldon began working in films, she acted for 11 months in a road company of A Streetcar Named Desire and danced with the Canadian Ballet. She also appeared on radio with Alan Young and on The Harold Peary Show.\n", - "After making her screen debut in a minor role in The Locket (1946) she gradually evolved to playing supporting or lead roles. Her most notable performance was starring opposite Gary Cooper in the 1951 Western Distant Drums. By the mid-1950s she was appearing either in B Pictures like the British thriller Mask of Dust (1954) or in supporting roles in more expensive films such as David Lean's Summertime (1955).After this point she worked largely in television, such as on the TV Western Wagon Train in 1959 as Freda Johnson in \"The Vivian Carter Story\" (S2E23) and in 1960 as Hester Millikan in \"The Jeremy Dow Story\" (S4E14). She guest-starred in a 1961 episode of Ichabod and Me.\n", "\n", + "== Writing career ==\n", + "José attended the University of Santo Tomas after World War II, but dropped out and plunged into writing and journalism in Manila. In subsequent years, he edited various literary and journalistic publications, started a publishing house, and founded the Philippine branch of PEN, an international organization for writers. José received numerous awards for his work. The Pretenders is his most popular novel, which is the story of one man's alienation from his poor background and the decadence of his wife's wealthy family.José Rizal's life and writings profoundly influenced José's work. The five volume Rosales Saga, in particular, employs and integrates themes and characters from Rizal's work. Throughout his career, José's writings espouse social justice and change to better the lives of average Filipino families. He is one of the most critically acclaimed Filipino authors internationally, although much underrated in his own country because of his authentic Filipino English and his anti-elite views.\n", + "\"Authors like myself choose the city as a setting for their fiction because the city itself illustrates the progress or the sophistication that a particular country has achieved. Or, on the other hand, it might also reflect the kind of decay, both social and perhaps moral, that has come upon a particular people.\"\n", + "Sionil José also owned Solidaridad Bookshop, located on Padre Faura Street in Ermita, Manila. The bookshop offers mostly hard-to-find books and Filipiniana reading materials. It is said to be one of the favorite haunts of many local writers.In his regular column, Hindsight, in The Philippine STAR, dated September 12, 2011, he wrote \"Why we are shallow\", blaming the decline of Filipino intellectual and cultural standards on a variety of modern amenities, including media, the education system—particularly the loss of emphasis on classic literature and the study of Greek and Latin—and the abundance and imme\n", "\n", - "== Personal life ==\n", - "Aldon married Tay Garnett in London, England on 13 August 1953. Their daughter, Tiela Aldon Garnett (later Daniels), was born in Los Angeles, California on 25 October 1955.On 17 January 1958, Aldon became a US citizen. In August 1970, Aldon filed for divorce from Garnett in Los Angeles, she was widowed seven years later. Aldon and Garnett had a ranch, near King Vidor in Paso Robles, California. Close relatives still live in her hometown of Tauragė, Lithuania, with whom she kept in touch.\n", + "Magpakailanman (English: Forevermore) is a weekly drama anthology broadcast by GMA Network. The show is hosted by 24 Oras anchor and GMA Kapuso Foundation founder Mel Tiangco and features inspiring stories and life experiences from both famous and ordinary people. It was aired every Monday until the end of 2004 and was moved to Thursday from 2005 on the network's primetime block.\n", + "The following are the lists of Magpakailanman episodes listed by the year they were aired, in the first incarnation that was aired from December 2, 2002, to December 27, 2007.\n", "\n", "\n", - "== Death ==\n", - "Aldon died on 31 October 2004 in Las Vegas, aged 78, of cancer.\n", + "== Series overview ==\n", "\n", "\n", - "== Filmography ==\n", + "== Episode list ==\n", "\n", "\n", - "== References ==\n", + "=== First incarnation ===\n", "\n", "\n", - "== Bibliography ==\n", - "Aaker, Everett. George Raft: The Films. McFarland, 2013.\n", + "==== 2002 ====\n", "\n", "\n", - "== External links ==\n", + "==== 2003 ====\n", "\n", - "Mari Aldon at IMDb\n", "\n", - "Alan LaVern Bean (March 15, 1932 – May 26, 2018) was an American naval officer and aviator, aeronautical engineer, test pilot, NASA astronaut and painter. He was selected to become an astronaut by NASA in 1963 as part of Astronaut Group 3, and was the fourth person to walk on the Moon.\n", - "Before becoming an astronaut, Bean graduated with a Bachelor of Science degree in Aeronautical Engineering from University of Texas at Austin in 1955 and re-joined the U.S. Navy—he served as an enlisted member for a year after his high school graduation. He received his naval aviator wings in 1956 and served as a fighter pilot. In 1960, he graduated from the U.S. Naval Test Pilot School, flew as a test pilot and was The New Nine selection finalist in 1962.\n", - "He made his first flight into space aboard Apollo 12, the second crewed mission to land on the Moon, at age 37 in November 1969. He made his second and final flight into space on the Skylab 3 mission in 1973, the second crewed mission to the Skylab space station. After retiring from the United States Navy in 1975 and NASA in 1981, he pursued his interest in painting, depicting various space-related scenes and documenting his own experiences in space as well as those of his fellow Apollo program astronauts. He was the last living crew member of Apollo 12.\n", + "==== 2004 ====\n", "\n", "\n", - "== Biography ==\n", + "==== 2005 ====\n", "\n", "\n", - "=== Early life and education ===\n", - "Bean was born March 15, 1932, in Wheeler, the seat of Wheeler County in the northeastern Texas Panhandle, to parents Arnold Horace Bean and Frances Caroline Bean (née Murphy), who lived from 1908 to 1983, and 1906 to 1981, respectively. He considered Fort Worth his hometown. He was of Scottish descent. As a boy, he lived in Minden, the seat of Webster Parish in northwestern Louisiana, where his father worked for the U.S. Soil Conservation Service. Bean was a Boy Scout and he earned the rank of First Class. He graduated from R. L. Paschal High School in Fort Worth, Texas, in 1949. Following his high school graduation in 1949, Bean enlisted in the U.S. Naval Reserve.Bean received a Bachelor of Science degree in aeronautical engineering from the University of Texas at Austin in 1955, where he attended on a Naval Reserve Officers Training Corps (NROTC) scholarship. While at the university, he also joined the Delta Kappa Epsilon fraternity.\n", + "==== 2006 ====\n", "\n", "\n", - "=== Military service ===\n", - "He was an Electronics Technician Striker at the NAS Dallas, Texas, until September 1950, when he was honorably discharged. In January 1955, Bean was commissioned a U.S. Navy ensign through the NROTC at the University of Texas at Austin, and attended flight training. After completing flight training in June 1956, he was assigned to Attack Squadron 44 (VA-44) at NAS Jacksonville, Florida, from 1956 to 1960, flying the F9F Cougar and A4D Skyhawk. After a four-year tour of duty, he attended the U.S. Naval Test Pilot School (USNTPS) at NAS Patuxent River, Maryland, where his instructor was his future Apollo 12 Commander, Pete Conrad, graduating in November 1960. Bean took art classes at St. Mary's College of Maryland during this tour, and flew as a test pilot on several types of naval aircraft. Following his assignment at USNTPS and aviation safety training with the University of Southern California (USC), he went through additional instruction with his old Attack Squadron 44, and was assigned to Navy Attack Squadron VA-172 at NAS Cecil Field, Florida, flying the A-4 Skyhawks, during which time he was selected as a NASA astronaut.Bean logged more than 7,145 hours of flying time, including 4,890 hours in jet aircraft.\n", + "==== 2007 ====\n", "\n", "\n", - "=== NASA career ===\n", - "Bean was selected by NASA as part of Astronaut Group 3 in 1963 (after not being selected for Astronaut Group 2 the previous year). He was selected to be the backup command pilot for Gemini 10, but was unsuccessful in securing an early Apollo flight assignment. He was placed in the Apollo Applications Program in the interim. In that capacity, he was the first astronaut to dive in the Neutral Buoyancy Simu\u001b[0m\u001b[32;1m\u001b[1;3mRelevant Documents: 0,2\n", - "Cited Documents: 2\n", - "Answer: FORT WORTH WAS THE HOMETOWN OF THE MOTHER OF ALAN SHEPARD, THE SECOND PERSON TO WALK ON THE MOON.\n", - "Grounded answer: FORT WORTH WAS THE HOMETOWN OF THE MOTHER OF ALAN SHEPARD, THE SECOND PERSON TO WALK ON THE MOON.\u001b[0m\n", + "== References ==\u001b[0m{'message': '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Introduction:\\n\\nThis document details the task you must accomplish. Read it carefully and always follow its instructions.\\n\\n## Safety Preamble\\nThe instructions in this section override those in the task description and style guide sections. Don\\'t answer questions that are harmful or immoral.\\n\\n## System Preamble\\n### Basic Rules\\nYou are a powerful language agent trained by Cohere to help people. You are capable of complex reasoning and augmented with a number of tools. Your job is to plan and reason about how you will use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see an instruction informing you what kind of response to generate. You will construct a plan and then perform a number of reasoning and action steps to solve the problem. When you have determined the answer to the user\\'s request, you will cite your sources in your answers, according the instructions.\\n\\n## User Preamble\\n### Task And Context\\nYou use your advanced complex reasoning capabilities to help people by answering their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You may need to use multiple tools in parallel or sequentially to complete your task. You should focus on serving the user\\'s needs as best you can, which will be wide-ranging. The current date is Wednesday, March 27, 2024 11:42:29.\\n\\n### Style Guide\\nUnless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.\\n\\n### Available Tools\\nHere is a list of tools that you have available to you:\\n\\n\\n```python\\ndef wikipedia(query: string) -> List[Dict]\\n \"\"\"Search for information on Wikipedia\\n Args: \\n query (string): query to look up in retriever\\n \"\"\"\\n pass\\n```\\n\\n```python\\ndef search earth(query: string) -> List[Dict]\\n \"\"\"Search for information on search earth\\n Args: \\n query (string): query to look up in retriever\\n \"\"\"\\n pass\\n```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Human: Write all output in capital letters. What was the hometown of the mother of the second person to walk on the moon?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Carefully perform the following instructions, in order, starting each with a new line.\\nFirstly, You may need to use complex and advanced reasoning to complete your task and answer the question. Think about how you can use the provided tools to answer the question and come up with a high level plan you will execute.\\nWrite \\'Plan:\\' followed by an initial high level plan of how you will solve the problem including the tools and steps required.\\nSecondly, Carry out your plan by repeatedly using actions, reasoning over the results, and re-evaluating your plan. Perform Action, Observation, Reflection steps with the following format. Write \\'Action:\\' followed by a json formatted action containing the \"tool_name\" and \"parameters\"\\n Next you will analyze the \\'Observation:\\', this is the result of the action.\\nAfter that you should always think about what to do next. Write \\'Reflection:\\' followed by what you\\'ve figured out so far, any changes you need to make to your plan, and what you will do next including if you know the answer to the question.\\n... (this Action/Observation/Reflection can repeat N times)\\nThirdly, Decide which of the retrieved documents are relevant to the user\\'s last input by writing \\'Relevant Documents:\\' followed by comma-separated list of document numbers. If none are relevant, you should instead write \\'None\\'.\\nFourthly, Decide which of the retrieved documents contain facts that should be cited in a good answer to the user\\'s last input by writing \\'Cited Documents:\\' followed a comma-separated list of document numbers. If you don\\'t want to cite any of them, you should instead write \\'None\\'.\\nFifthly, Write \\'Answer:\\' followed by a response to the user\\'s last input in high quality natural english. Use the retrieved documents to help you. Do not insert any citations or grounding markup.\\nFinally, Write \\'Grounded answer:\\' followed by a response to the user\\'s last input in high quality natural english. Use the symbols and to indicate when a fact comes from a document in the search result, e.g my fact for a fact from document 4.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>\\nPlan: First I will search for who the second person to walk on the moon was, then I will search for that person\\'s mother\\'s hometown and write the answer in capitals.\\nAction: ```json\\n[\\n {\\n \"tool_name\": \"wikipedia\",\\n \"parameters\": {\\n \"query\": \"second man to walk on the moon\"\\n }\\n }\\n]\\n```<|END_OF_TURN_TOKEN|>\\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>\\nDocument 0\\nWalk the Moon (stylized as WALK THE MOON) is an American pop rock band based in Cincinnati, Ohio. Lead singer Nicholas Petricca started the band in 2006, while a student at Kenyon College, deriving the band\\'s name from the song \"Walking on the Moon\" by The Police. Although the band is best known for their most successful hit single to date \"Shut Up and Dance\", other notable songs include \"Anna Sun\" and \"One Foot\".\\nWalk the Moon has cited Talking Heads as influences. The band\\'s use of 1980s musical mainstays, such as keyboard and synthesizer, is also notable.\\n\\n\\n== History ==\\n\\n\\n=== 2010–2011: Beginning, Anna Sun and i Want! i Want! ===\\n\\nThe group independently released their debut studio album, I Want! I Want!, in November 2010, receiving airplay for the track \"Anna Sun\" on multiple alternative radio stations. Along with the success of \"Anna Sun\", Alt Nation named them a band you need to know for the summer of 2012. Influential music blog Neon Gold helped to break the band in January 2011, calling \"Anna Sun\", \"the kind of stuff British A&R dreams, and major label bidding wars, are made of.\" In February 2011, Walk the Moon signed to RCA Records.\\nIn 2011, the band members began to paint their faces for live performances and they would bring enough paint to share with audience members. They have claimed it has become a “live tradition”. Bonnaroo’s camera crew documented the painting process in a short video from the 2011 festival. The band played at the Sasquatch Music Festival and Firefly Music Festival. In these years, they were known for their energetic performances and tireless touring schedule.\\nBefore the release of their self-titled album, Walk the Moon joined many other performers at the Music Midtown festival and performed on the Great Southeast Music Hall Stage in Atlanta, Georgia in September 2011. In spring 2011, the band went on a short tour with the west coast band, Grouplove, as well as supporting Panic! at the Disco and Weezer on select dates. The band played on the main stage at the 20th Anniversary of Lollapalooza and also supported Local Natives in an Official Lollaplooza Aftershow at Lincoln Hall.\\nThe band recorded i Want! i Want! with Chris Schmidt and Ben Cochran at Soap Floats Recording Studio in their hometown of Cincinnati, Ohio and then self-released it. The lead single from the album, \"Anna Sun\", became a surprise hit in the summer of 2011 following an endorsement by the Esquire article \"30 Summer Songs Every Man Should Listen To\". The song was written by Petricca and New York songwriter Nick Lerangis as their time at Kenyon College came to an end. \"It\\'s about college, about maintaining that little bit of being a kid,\" Petricca said. \"Don\\'t be afraid to play.\" The song was named after one of their favorite teachers. It was named song of the summer by MTV and Seventeen Mag, and one of the top songs of the year by Amazon. It has been officially remixed by Fool\\'s Gold and received a Trouble Productions remix by Albert Hammond Jr. Anna Sun rose to the number one spot on Alt. Nation on Sirius XM Radio. \"Anna Sun\" was added to the video rotation of American Eagle Outfitters stores in May 2011. It was featured on the hit TV show Vampire Diaries in the first episode of season three. It was also the free single of the week on iTunes for the week of May 15.\\nFilmed in 2011 in Cincinnati\\'s Over-the-Rhine neighborhood, the \"Anna Sun\" music video was released to coincide with the album. The video was shot on-location at the Cincinnati Mockbee building, as well as at a city park. It was directed and produced by Patrick Meier of the Cincinnati company, Contrast Productions, and features original choreography from Kim Popa of PONES Inc., as well as a cast full of the band\\'s friends and locals from Cincinnati. MTV Hive calls the video a \"hilariously choreographed, neon-colored and awesomely shot in one take\" production.\\n\\n\\n=== 2012–2013: Walk the Moon and Tightrope EP ===\\n\\nThe band\\'s self-titled major label debut Walk t\\n\\nAs part of the Apollo program by NASA, 24 astronauts flew nine missions to the Moon between December 1968 and December 1972. During six successful two-man landing missions, twelve men walked on the lunar surface, six of whom drove Lunar Roving Vehicles as part of the last three missions. Three men have been to the Moon twice, one orbited once and took a circumlunar trajectory the second time, while the other two landed once apiece. Apart from these 24 men, no human being has gone beyond low Earth orbit. No woman has been to the Moon, but a number of non-human animals have circled or orbited it, including two tortoises, several turtles, and five mice.\\nApollo missions 8 and 10–17 were the nine crewed missions to the Moon. Apollo 4–6 and AS-201 and AS-202 were uncrewed, while AS-203 is considered a test flight. The Apollo program included three other crewed missions: Apollo 1 (AS-204) did not launch and its crew died in a ground-based capsule fire, while Apollo 7 and Apollo 9 were low Earth orbit missions that only tested spacecraft components and docking maneuvers. Apollo missions 18, 19, and 20 were canceled. Twelve astronauts later flew unused Apollo command modules in the Apollo Applications Program\\'s Skylab and Apollo–Soyuz Test Project. Of the 24 astronauts who flew to the Moon, two went on to command a Skylab mission, one commanded Apollo–Soyuz, one flew as commander for Approach and Landing Tests of the Space Shuttle, and two commanded orbital Space Shuttle missions.\\n\\n\\n== Prime crew members ==\\nNASA\\'s Director of Flight Crew Operations during the Gemini and Apollo programs was Donald K. \"Deke\" Slayton, one of the original Mercury Seven astronauts, who was medically grounded in September 1962 due to a minor cardiac arrhythmia – paroxysmal atrial fibrillation. Slayton was responsible for making all Gemini and Apollo crew assignments. In March 1972, Slayton was restored to flight status, and flew on the 1975 Apollo–Soyuz Test Project mission.\\nThe prime crew members selected for actual missions are here grouped by their NASA astronaut selection groups, and within each group in the order selected for flight. Two versions of the Apollo Command/Service Module (CSM) spacecraft were developed: Block I, intended for preliminary low Earth orbit testing; and Block II, redesigned for the lunar landing. The Block I crew position titles were Command Pilot, Senior Pilot (second seat), and Pilot (third seat). The corresponding Block II titles were: Commander, Command Module Pilot, and Lunar Module Pilot. The second seat pilot was given secondary responsibility for celestial navigation to keep the CSM\\'s guidance computer accurately calibrated with the spacecraft\\'s true position, and the third seat pilot served as a flight engineer, monitoring the health of the spacecraft systems.\\n\\n\\n== Apollo astronauts by their dates of selection by NASA ==\\n\\n\\n=== 1959 ===\\nVirgil I. \"Gus\" Grissom began his career at NASA in 1959. In 1966, he was selected as Command Pilot for the first crewed Apollo mission, a low Earth orbit test. This mission ended a month before its scheduled launch, when a cabin fire on the launch pad killed Grissom, Ed White and Roger Chaffee on January 27, 1967.\\nWalter M. Schirra Jr. also began his NASA career in 1959. He was selected in October 1968 as Command Pilot for Apollo 7, an 11-day, low Earth orbit shakedown test of the three-man Apollo Command/Service Module and the first crewed launch for the Apollo project.\\nAlan B. Shepard Jr. – America\\'s first man in space on Freedom 7 was originally selected to command Gemini 3, but was medically grounded for the duration of Gemini due to Ménière\\'s disease and assisted Slayton in Flight Operations. After corrective surgery, Shepard was restored to flight status and commanded Apollo 14, the third successful Moon landing mission.\\n\\n\\n=== 1962 ===\\n\\nAll of these astronauts flew on Gemini, and except for White, each commanded one Gemini and one Apollo mission:\\n\\nEdward H. White II – Second-seat \\n\\n\"Man on the Moon\" is a song by American alternative rock band R.E.M., released in November 1992 as the second single from their eighth album, Automatic for the People (1992). The lyrics were written by lead singer Michael Stipe, and the music by drummer Bill Berry and guitarist Peter Buck. The song was well received by critics and reached number 30 on the US Billboard Hot 100, number 17 on the US Cash Box Top 100, number 18 on the UK Singles Chart, and number one in Iceland. It remains one of R.E.M.\\'s most popular songs and was included on the compilations In Time: The Best of R.E.M. 1988–2003 and Part Lies, Part Heart, Part Truth, Part Garbage 1982–2011.\\n\"Man on the Moon\" is a tribute to comedian Andy Kaufman, with numerous references to his career including his Elvis impersonation, wrestling, and the film My Breakfast with Blassie. The song\\'s title and chorus refer to Moon landing conspiracy theories, as an oblique allusion to rumors that Kaufman\\'s death in 1984 was faked. The song gave its name to Miloš Forman\\'s Kaufman biopic Man on the Moon (1999), and features prominently in the film\\'s soundtrack.\\n\\n\\n== Composition ==\\n\"Man on the Moon\" is a mid-tempo country-rock song following a verse-chorus structure with an added pre-chorus and an instrumental bridge following the second and third choruses. The song has six lines in the first verse but only four in the second and third verses.An early instrumental demo of the song was known to the band as \"C to D Slide\". Guitarist Peter Buck has explained how the music came together: \"\\'Man on the Moon\\' was something that Bill [Berry] had, this one chord change that he came in with, which was C to D like the verse of the song, and he said: \\'I don\\'t know what to do with that.\\' I used to finish some of Bill\\'s things ... he would come up with the riffs, but I would be the finish guy for that. I sat down and came up with the chorus, the bridges, and so forth. I remember we showed it to Mike and Michael when they came in later; definitely we had the song finished. I think Bill played bass and I played guitar; we kept going around with it. I think we might have played some mandolin on it in the rehearsal studio.\"Michael Stipe explained in an interview with Charlie Rose how the lyric was written independently of the music, which had no prior association with the song\\'s eventual lyrical content regarding Kaufman. Stipe recounted the other R.E.M. members had written and performed the music of the song and recorded it along with the rest of the Automatic for the People album during studio sessions in Seattle. As of the final week of the recording sessions, Stipe was still struggling to write the lyric, and the others continued to plead with him to finish it. Stipe attempted to argue the track should be an instrumental, but his bandmates were insistent. Stipe listened to the track on a walk around Seattle on his Walkman cassette player and was inspired to write about Andy Kaufman. After Stipe went back to the studio to complete the vocal track, the track was mixed that night and sent out the following day to be mastered.\\n\\n\\n== Lyric ==\\nThe song\\'s lyric does not tell a conventional story and instead forms a collection of cultural references, images and ideas. There are repeated mentions of Andy Kaufman, including references to his Elvis impersonation and work with wrestlers Fred Blassie and Jerry Lawler. The song also invokes the conspiracy theories surrounding the Moon landing and Elvis Presley\\'s death as an indirect nod to the persistent rumors that Kaufman faked his own death. Speaking in 2017 to the NME, Mike Mills explained that the perceived ambiguity of Kaufman\\'s legacy, including questions of whether he was a comedian or a performance artist, and whether his work was funny or irritating, was a way to frame other questions about life within the song:\\n\\nHe\\'s the perfect ghost to lead you through this tour of questioning things. Did the moon landing really happen? Is Elvis really dead? He was ki<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>Reflection: I have found that the second person to walk on the moon was Edwin Aldrin. Now I will search for his mother\\'s hometown.\\nAction: ```json\\n[\\n {\\n \"tool_name\": \"wikipedia\",\\n \"parameters\": {\\n \"query\": \"Edwin Aldrin mother\\'s hometown\"\\n }\\n }\\n]\\n```\\n<|END_OF_TURN_TOKEN|>\\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>\\nDocument 1\\nBuzz Aldrin (; born Edwin Eugene Aldrin Jr.; January 20, 1930) is an American former astronaut, engineer and fighter pilot. He made three spacewalks as pilot of the 1966 Gemini 12 mission, and was the Lunar Module Eagle pilot on the 1969 Apollo 11 mission. He was the second person to walk on the Moon after mission commander Neil Armstrong.\\nBorn in Glen Ridge, New Jersey, Aldrin graduated third in the class of 1951 from the United States Military Academy at West Point with a degree in mechanical engineering. He was commissioned into the United States Air Force and served as a jet fighter pilot during the Korean War. He flew 66 combat missions and shot down two MiG-15 aircraft.\\nAfter earning a Doctor of Science degree in astronautics from the Massachusetts Institute of Technology (MIT), Aldrin was selected as a member of NASA\\'s Astronaut Group 3, making him the first astronaut with a doctoral degree. His doctoral thesis, Line-of-Sight Guidance Techniques for Manned Orbital Rendezvous, earned him the nickname \"Dr. Rendezvous\" from fellow astronauts. His first space flight was in 1966 on Gemini 12, during which he spent over five hours on extravehicular activity. Three years later, Aldrin set foot on the Moon at 03:15:16 on July 21, 1969 (UTC), nineteen minutes after Armstrong first touched the surface, while command module pilot Michael Collins remained in lunar orbit. A Presbyterian elder, Aldrin became the first person to hold a religious ceremony on the Moon when he privately took communion.\\nAfter leaving NASA in 1971, Aldrin became Commandant of the U.S. Air Force Test Pilot School. He retired from the Air Force in 1972 after 21 years of service. His autobiographies Return to Earth (1973) and Magnificent Desolation (2009) recount his struggles with clinical depression and alcoholism in the years after leaving NASA. Aldrin continues to advocate for space exploration, particularly a human mission to Mars. He developed the Aldrin cycler, a special spacecraft trajectory that makes travel to Mars more efficient in terms of time and propellant. He has been accorded numerous honors, including the Presidential Medal of Freedom in 1969.\\n\\n\\n== Early life and education ==\\nAldrin was born Edwin Eugene Aldrin Jr. on January 20, 1930, at Mountainside Hospital in Glen Ridge, New Jersey. His parents, Edwin Eugene Aldrin Sr. and Marion Aldrin (née Moon), lived in neighboring Montclair. His father was an Army aviator during World War I and the assistant commandant of the Army\\'s test pilot school at McCook Field, Ohio, from 1919 to 1922, but left the Army in 1928 and became an executive at Standard Oil. Aldrin had two sisters: Madeleine, who was four years older, and Fay Ann, who was a year and a half older. His nickname, which became his legal first name in 1988, arose as a result of Fay\\'s mispronouncing \"brother\" as \"buzzer\", which was then shortened to \"Buzz\". He was a Boy Scout, achieving the rank of Tenderfoot Scout.Aldrin did well in school, maintaining an A average. He played football and was the starting center for Montclair High School\\'s undefeated 1946 state champion team. His father wanted him to go to the United States Naval Academy in Annapolis, Maryland, and enrolled him at nearby Severn School, a preparatory school for Annapolis, and even secured him a Naval Academy appointment from Albert W. Hawkes, one of the United States senators from New Jersey. Aldrin attended Severn School in 1946, but had other ideas about his future career. He suffered from seasickness and considered ships a distraction from flying airplanes. He faced down his father and told him to ask Hawkes to change the nomination to the United States Military Academy at West Point, New York.Aldrin entered West Point in 1947. He did well academically, finishing first in his class his plebe (first) year. Aldrin was also an excellent athlete, competing in pole vault for the academy track and field team. In 1950, he traveled with a group of West Point cadets to Japan and\\n\\nFrancisco Sionil José (December 3, 1924 – January 6, 2022) was a Filipino writer who was one of the most widely read in the English language. A National Artist of the Philippines for Literature, which was bestowed upon him in 2001, José\\'s novels and short stories depict the social underpinnings of class struggles and colonialism in Filipino society. His works—written in English—have been translated into 28 languages, including Korean, Indonesian, Czech, Russian, Latvian, Ukrainian and Dutch. He was often considered the leading Filipino candidate for the Nobel Prize in Literature.\\n\\n\\n== Early life ==\\nJosé was born in Rosales, Pangasinan, the setting of many of his stories. He spent his childhood in Barrio Cabugawan, Rosales, where he first began to write. José is of Ilocano descent whose family had migrated to Pangasinan prior to his birth. Fleeing poverty, his forefathers traveled from Ilocos towards Cagayan Valley through the Santa Fe Trail. Like many migrant families, they brought their lifetime possessions with them, including uprooted molave posts of their old houses and their alsong, a stone mortar for pounding rice.One of the greatest influences to José was his industrious mother who went out of her way to get him the books he loved to read, while making sure her family did not go hungry despite poverty and landlessness. José started writing in grade school, at the time he started reading. In the fifth grade, one of José\\'s teachers opened the school library to her students, which is how José managed to read the novels of José Rizal, Willa Cather’s My Antonia, Faulkner and Steinbeck. Reading about Basilio and Crispin in Rizal\\'s Noli Me Tangere made the young José cry, because injustice was not an alien thing to him. When José was five years old, his grandfather who was a soldier during the Philippine revolution, had once tearfully showed him the land their family had once tilled but was taken away by rich mestizo landlords who knew how to work the system against illiterates like his grandfather.\\n\\n\\n== Writing career ==\\nJosé attended the University of Santo Tomas after World War II, but dropped out and plunged into writing and journalism in Manila. In subsequent years, he edited various literary and journalistic publications, started a publishing house, and founded the Philippine branch of PEN, an international organization for writers. José received numerous awards for his work. The Pretenders is his most popular novel, which is the story of one man\\'s alienation from his poor background and the decadence of his wife\\'s wealthy family.José Rizal\\'s life and writings profoundly influenced José\\'s work. The five volume Rosales Saga, in particular, employs and integrates themes and characters from Rizal\\'s work. Throughout his career, José\\'s writings espouse social justice and change to better the lives of average Filipino families. He is one of the most critically acclaimed Filipino authors internationally, although much underrated in his own country because of his authentic Filipino English and his anti-elite views.\\n\"Authors like myself choose the city as a setting for their fiction because the city itself illustrates the progress or the sophistication that a particular country has achieved. Or, on the other hand, it might also reflect the kind of decay, both social and perhaps moral, that has come upon a particular people.\"\\nSionil José also owned Solidaridad Bookshop, located on Padre Faura Street in Ermita, Manila. The bookshop offers mostly hard-to-find books and Filipiniana reading materials. It is said to be one of the favorite haunts of many local writers.In his regular column, Hindsight, in The Philippine STAR, dated September 12, 2011, he wrote \"Why we are shallow\", blaming the decline of Filipino intellectual and cultural standards on a variety of modern amenities, including media, the education system—particularly the loss of emphasis on classic literature and the study of Greek and Latin—and the abundance and imme\\n\\nMagpakailanman (English: Forevermore) is a weekly drama anthology broadcast by GMA Network. The show is hosted by 24 Oras anchor and GMA Kapuso Foundation founder Mel Tiangco and features inspiring stories and life experiences from both famous and ordinary people. It was aired every Monday until the end of 2004 and was moved to Thursday from 2005 on the network\\'s primetime block.\\nThe following are the lists of Magpakailanman episodes listed by the year they were aired, in the first incarnation that was aired from December 2, 2002, to December 27, 2007.\\n\\n\\n== Series overview ==\\n\\n\\n== Episode list ==\\n\\n\\n=== First incarnation ===\\n\\n\\n==== 2002 ====\\n\\n\\n==== 2003 ====\\n\\n\\n==== 2004 ====\\n\\n\\n==== 2005 ====\\n\\n\\n==== 2006 ====\\n\\n\\n==== 2007 ====\\n\\n\\n== References ==<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>\\n', 'chat_history': [], 'model': 'command-r', 'raw_prompting': True}\n", + "\u001b[32;1m\u001b[1;3mRelevant Documents: 1\n", + "Cited Documents: 1\n", + "Answer: MONTclair, NEW JERSEY, WAS THE HOMETOWN OF THE MOTHER OF THE SECOND MAN TO WALK ON THE MOON.\n", + "Grounded answer: Montclair, New Jersey, was the hometown of the mother of the second man to walk on the moon.\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n" ] @@ -365,10 +254,10 @@ "data": { "text/plain": [ "{'input': 'What was the hometown of the mother of the second person to walk on the moon?',\n", - " 'output': 'FORT WORTH WAS THE HOMETOWN OF THE MOTHER OF ALAN SHEPARD, THE SECOND PERSON TO WALK ON THE MOON.'}" + " 'output': 'MONTclair, NEW JERSEY, WAS THE HOMETOWN OF THE MOTHER OF THE SECOND MAN TO WALK ON THE MOON.'}" ] }, - "execution_count": 5, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -376,10 +265,10 @@ "source": [ "agent = create_cohere_multi_hop_agent(\n", " llm=chat,\n", - " tools=[retriever_tool],\n", + " tools=[retriever_tool, retriever_tool2],\n", " prompt=prompt,\n", ")\n", - "agent_executor = AgentExecutor(agent=agent, tools=[retriever_tool], verbose=True)\n", + "agent_executor = AgentExecutor(agent=agent, tools=[retriever_tool, retriever_tool2], verbose=True)\n", "agent_executor.invoke({\"input\": \"What was the hometown of the mother of the second person to walk on the moon?\"})" ] } diff --git a/libs/partners/cohere/langchain_cohere/chat_models.py b/libs/partners/cohere/langchain_cohere/chat_models.py index 25a537abe1ebb..cc3d12f32003b 100644 --- a/libs/partners/cohere/langchain_cohere/chat_models.py +++ b/libs/partners/cohere/langchain_cohere/chat_models.py @@ -146,7 +146,6 @@ def _stream( **kwargs: Any, ) -> Iterator[ChatGenerationChunk]: request = get_cohere_chat_request(messages, **self._default_params, **kwargs) - if hasattr(self.client, "chat_stream"): # detect and support sdk v5 stream = self.client.chat_stream(**request) else: diff --git a/libs/partners/cohere/langchain_cohere/multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/multi_hop/agent.py index f5c2c4dd4fdd6..f03b19facc71f 100644 --- a/libs/partners/cohere/langchain_cohere/multi_hop/agent.py +++ b/libs/partners/cohere/langchain_cohere/multi_hop/agent.py @@ -3,9 +3,9 @@ import re from typing import List, Sequence, Union -from langchain.agents.agent import MultiActionAgentOutputParser from langchain_core.agents import AgentAction, AgentFinish from langchain_core.language_models import BaseLanguageModel +from langchain_core.output_parsers import BaseOutputParser from langchain_core.prompts.chat import ChatPromptTemplate from langchain_core.runnables import Runnable, RunnablePassthrough from langchain_core.tools import BaseTool @@ -27,14 +27,14 @@ def create_cohere_multi_hop_agent( multi_hop_prompt = multi_hop_prompt_template.partial( tools="\n".join([render_tool_description(t) for t in tools]), ) - llm_with_tools = llm.bind(stop=["\nObservation:"]) + llm_with_tools = llm.bind(stop=["\nObservation:"], raw_prompting=True) agent = ( RunnablePassthrough.assign( agent_scratchpad=lambda x: format_cohere_log_to_str( x["intermediate_steps"], ), - input=lambda x: prompt.format_messages( + input=lambda x: prompt.format( input=x["input"], agent_scratchpad=x["intermediate_steps"] ), ) @@ -45,7 +45,9 @@ def create_cohere_multi_hop_agent( return agent -class CohereToolsMultiHopAgentOutputParser(MultiActionAgentOutputParser): +class CohereToolsMultiHopAgentOutputParser( + BaseOutputParser[Union[List[AgentAction], AgentFinish]] +): """Parses a message into agent actions/finish.""" @property @@ -185,15 +187,69 @@ def parse(self, text: str) -> Union[List[AgentAction], AgentFinish]: ) +def get_type(type_: str, is_optional: bool) -> str: + if is_optional: + return f"Optional[{type_}]" + else: + return type_ + + +def get_tool_signature(tool: BaseTool) -> str: + """Get the tool signature.""" + args = [] + for parameter_name, parameter_definition in tool.args.items(): + type_ = get_type( + parameter_definition.get("type"), "default" in parameter_definition + ) + args.append(f"{parameter_name}: {type_}") + signature = ", ".join(args) + return f"def {tool.name}({signature}) -> List[Dict]" + + +def get_tool_args(tool: BaseTool) -> str: + """Get the tool args.""" + if not tool.args: + return "" + rendered_args = [] + for parameter_name, parameter_definition in tool.args.items(): + type_ = get_type( + parameter_definition.get("type"), "default" in parameter_definition + ) + description = parameter_definition.get("description") + rendered_args.append(f"{parameter_name} ({type_}): {description}") + return "\n ".join(rendered_args) + + def render_tool_description(tool: BaseTool) -> str: - """Render the tool name and description. TODO: better way to render?""" - template = """```python - def {TOOL_NAME}(): - \"\"\"{DESCRIPTION} - \"\"\" - pass - ```""" - return template.format(TOOL_NAME=tool.name, DESCRIPTION=tool.description) + """Render the tool name and description. + + For example: + ```python + def calculator_calc(expression: str) -> List[Dict]: + \"\"\"This is a powerful multi-purpose calculator. + It is capable of a wide array of math calculation and a range of features. + Args: + expression (str): The expression for the calculator to evaluate. + + \"\"\" + pass + ``` + """ + + template = """ +```python +{tool_signature} + \"\"\"{tool_description} + Args: + {tool_args} + \"\"\" + pass +```""" + return template.format( + tool_signature=get_tool_signature(tool), + tool_description=tool.description, + tool_args=get_tool_args(tool), + ) def format_cohere_log_to_str( diff --git a/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py b/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py index bef92fab3aacb..7b45c6756fbb5 100644 --- a/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py +++ b/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py @@ -2,11 +2,7 @@ from datetime import datetime from langchain_core.prompts import PromptTemplate -default_basic_rules = ( - "You are a powerful language agent trained by Cohere to help people. " - + "You are capable of complex reasoning and augmented with a number of tools. " - + "Your job is to plan and reason about how you will use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see an instruction informing you what kind of response to generate. You will construct a plan and then perform a number of reasoning and action steps to solve the problem. When you have determined the answer to the user's request, you will cite your sources in your answers, according the instructions." -) +default_basic_rules = "You are a powerful language agent trained by Cohere to help people. You are capable of complex reasoning and augmented with a number of tools. Your job is to plan and reason about how you will use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see an instruction informing you what kind of response to generate. You will construct a plan and then perform a number of reasoning and action steps to solve the problem. When you have determined the answer to the user's request, you will cite your sources in your answers, according the instructions." now = datetime.now().strftime("%A, %B %d, %Y %H:%M:%S") default_task_context = f"""You use your advanced complex reasoning capabilities to help people by answering their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You may need to use multiple tools in parallel or sequentially to complete your task. You should focus on serving the user's needs as best you can, which will be wide-ranging. The current date is {now}.""" @@ -19,8 +15,7 @@ structured_preamble_template = """{SYSTEM_PREFIX}# Introduction: -This document details the task you must accomplish. \ -Read it carefully and always follow its instructions. +This document details the task you must accomplish. Read it carefully and always follow its instructions. ## Safety Preamble {SAFETY_PREAMBLE} @@ -30,7 +25,7 @@ {BASIC_RULES} ## User Preamble -### Task and Context +### Task And Context {TASK_CONTEXT} ### Style Guide @@ -63,7 +58,7 @@ def render_structured_preamble( After that you should always think about what to do next. Write 'Reflection:' followed by what you've figured out so far, any changes you need to make to your plan, and what you will do next including if you know the answer to the question. ... (this Action/Observation/Reflection can repeat N times) Thirdly, Decide which of the retrieved documents are relevant to the user's last input by writing 'Relevant Documents:' followed by comma-separated list of document numbers. If none are relevant, you should instead write 'None'. -Fourthly, Decide which of the retrieved documents contain facts that should be cited in a good answer to the user's last input by writing 'Cited Documents:' followed a comma-separated list of document numbers. If you dont want to cite any of them, you should instead write 'None'. +Fourthly, Decide which of the retrieved documents contain facts that should be cited in a good answer to the user's last input by writing 'Cited Documents:' followed a comma-separated list of document numbers. If you don't want to cite any of them, you should instead write 'None'. Fifthly, Write 'Answer:' followed by a response to the user's last input in high quality natural english. Use the retrieved documents to help you. Do not insert any citations or grounding markup. Finally, Write 'Grounded answer:' followed by a response to the user's last input in high quality natural english. Use the symbols and to indicate when a fact comes from a document in the search result, e.g my fact for a fact from document 4.""" From 157fcd006bedf29a8fd212a0f816822670402f7a Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Wed, 27 Mar 2024 11:54:27 +0000 Subject: [PATCH 04/27] Remove new line --- libs/partners/cohere/langchain_cohere/chat_models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/partners/cohere/langchain_cohere/chat_models.py b/libs/partners/cohere/langchain_cohere/chat_models.py index cc3d12f32003b..25a537abe1ebb 100644 --- a/libs/partners/cohere/langchain_cohere/chat_models.py +++ b/libs/partners/cohere/langchain_cohere/chat_models.py @@ -146,6 +146,7 @@ def _stream( **kwargs: Any, ) -> Iterator[ChatGenerationChunk]: request = get_cohere_chat_request(messages, **self._default_params, **kwargs) + if hasattr(self.client, "chat_stream"): # detect and support sdk v5 stream = self.client.chat_stream(**request) else: From db7be4daafc4dafb6a4fc8c5d8d9b8fb4626c75f Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Wed, 27 Mar 2024 11:59:42 +0000 Subject: [PATCH 05/27] Fix notebok --- .../cohere/docs/multi_hop_agent.ipynb | 115 ++++++++++-------- 1 file changed, 61 insertions(+), 54 deletions(-) diff --git a/libs/partners/cohere/docs/multi_hop_agent.ipynb b/libs/partners/cohere/docs/multi_hop_agent.ipynb index 6bb15cd2d34e4..2181586494fbf 100644 --- a/libs/partners/cohere/docs/multi_hop_agent.ipynb +++ b/libs/partners/cohere/docs/multi_hop_agent.ipynb @@ -38,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -59,7 +59,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -81,7 +81,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -102,7 +102,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -112,7 +112,6 @@ "\n", "\n", "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", - "{'message': '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Introduction:\\n\\nThis document details the task you must accomplish. Read it carefully and always follow its instructions.\\n\\n## Safety Preamble\\nThe instructions in this section override those in the task description and style guide sections. Don\\'t answer questions that are harmful or immoral.\\n\\n## System Preamble\\n### Basic Rules\\nYou are a powerful language agent trained by Cohere to help people. You are capable of complex reasoning and augmented with a number of tools. Your job is to plan and reason about how you will use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see an instruction informing you what kind of response to generate. You will construct a plan and then perform a number of reasoning and action steps to solve the problem. When you have determined the answer to the user\\'s request, you will cite your sources in your answers, according the instructions.\\n\\n## User Preamble\\n### Task And Context\\nYou use your advanced complex reasoning capabilities to help people by answering their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You may need to use multiple tools in parallel or sequentially to complete your task. You should focus on serving the user\\'s needs as best you can, which will be wide-ranging. The current date is Wednesday, March 27, 2024 11:42:29.\\n\\n### Style Guide\\nUnless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.\\n\\n### Available Tools\\nHere is a list of tools that you have available to you:\\n\\n\\n```python\\ndef wikipedia(query: string) -> List[Dict]\\n \"\"\"Search for information on Wikipedia\\n Args: \\n query (string): query to look up in retriever\\n \"\"\"\\n pass\\n```\\n\\n```python\\ndef search earth(query: string) -> List[Dict]\\n \"\"\"Search for information on search earth\\n Args: \\n query (string): query to look up in retriever\\n \"\"\"\\n pass\\n```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Human: Write all output in capital letters. What was the hometown of the mother of the second person to walk on the moon?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Carefully perform the following instructions, in order, starting each with a new line.\\nFirstly, You may need to use complex and advanced reasoning to complete your task and answer the question. Think about how you can use the provided tools to answer the question and come up with a high level plan you will execute.\\nWrite \\'Plan:\\' followed by an initial high level plan of how you will solve the problem including the tools and steps required.\\nSecondly, Carry out your plan by repeatedly using actions, reasoning over the results, and re-evaluating your plan. Perform Action, Observation, Reflection steps with the following format. Write \\'Action:\\' followed by a json formatted action containing the \"tool_name\" and \"parameters\"\\n Next you will analyze the \\'Observation:\\', this is the result of the action.\\nAfter that you should always think about what to do next. Write \\'Reflection:\\' followed by what you\\'ve figured out so far, any changes you need to make to your plan, and what you will do next including if you know the answer to the question.\\n... (this Action/Observation/Reflection can repeat N times)\\nThirdly, Decide which of the retrieved documents are relevant to the user\\'s last input by writing \\'Relevant Documents:\\' followed by comma-separated list of document numbers. If none are relevant, you should instead write \\'None\\'.\\nFourthly, Decide which of the retrieved documents contain facts that should be cited in a good answer to the user\\'s last input by writing \\'Cited Documents:\\' followed a comma-separated list of document numbers. If you don\\'t want to cite any of them, you should instead write \\'None\\'.\\nFifthly, Write \\'Answer:\\' followed by a response to the user\\'s last input in high quality natural english. Use the retrieved documents to help you. Do not insert any citations or grounding markup.\\nFinally, Write \\'Grounded answer:\\' followed by a response to the user\\'s last input in high quality natural english. Use the symbols and to indicate when a fact comes from a document in the search result, e.g my fact for a fact from document 4.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>\\n\\n', 'chat_history': [], 'model': 'command-r', 'raw_prompting': True}\n", "\u001b[32;1m\u001b[1;3mPlan: First I will search for who the second person to walk on the moon was, then I will search for that person's mother's hometown and write the answer in capitals.\n", "Action: ```json\n", "[\n", @@ -143,6 +142,19 @@ "\n", "The band's self-titled major label debut Walk t\n", "\n", + "\"Man on the Moon\" is a song by American alternative rock band R.E.M., released in November 1992 as the second single from their eighth album, Automatic for the People (1992). The lyrics were written by lead singer Michael Stipe, and the music by drummer Bill Berry and guitarist Peter Buck. The song was well received by critics and reached number 30 on the US Billboard Hot 100, number 17 on the US Cash Box Top 100, number 18 on the UK Singles Chart, and number one in Iceland. It remains one of R.E.M.'s most popular songs and was included on the compilations In Time: The Best of R.E.M. 1988–2003 and Part Lies, Part Heart, Part Truth, Part Garbage 1982–2011.\n", + "\"Man on the Moon\" is a tribute to comedian Andy Kaufman, with numerous references to his career including his Elvis impersonation, wrestling, and the film My Breakfast with Blassie. The song's title and chorus refer to Moon landing conspiracy theories, as an oblique allusion to rumors that Kaufman's death in 1984 was faked. The song gave its name to Miloš Forman's Kaufman biopic Man on the Moon (1999), and features prominently in the film's soundtrack.\n", + "\n", + "\n", + "== Composition ==\n", + "\"Man on the Moon\" is a mid-tempo country-rock song following a verse-chorus structure with an added pre-chorus and an instrumental bridge following the second and third choruses. The song has six lines in the first verse but only four in the second and third verses.An early instrumental demo of the song was known to the band as \"C to D Slide\". Guitarist Peter Buck has explained how the music came together: \"'Man on the Moon' was something that Bill [Berry] had, this one chord change that he came in with, which was C to D like the verse of the song, and he said: 'I don't know what to do with that.' I used to finish some of Bill's things ... he would come up with the riffs, but I would be the finish guy for that. I sat down and came up with the chorus, the bridges, and so forth. I remember we showed it to Mike and Michael when they came in later; definitely we had the song finished. I think Bill played bass and I played guitar; we kept going around with it. I think we might have played some mandolin on it in the rehearsal studio.\"Michael Stipe explained in an interview with Charlie Rose how the lyric was written independently of the music, which had no prior association with the song's eventual lyrical content regarding Kaufman. Stipe recounted the other R.E.M. members had written and performed the music of the song and recorded it along with the rest of the Automatic for the People album during studio sessions in Seattle. As of the final week of the recording sessions, Stipe was still struggling to write the lyric, and the others continued to plead with him to finish it. Stipe attempted to argue the track should be an instrumental, but his bandmates were insistent. Stipe listened to the track on a walk around Seattle on his Walkman cassette player and was inspired to write about Andy Kaufman. After Stipe went back to the studio to complete the vocal track, the track was mixed that night and sent out the following day to be mastered.\n", + "\n", + "\n", + "== Lyric ==\n", + "The song's lyric does not tell a conventional story and instead forms a collection of cultural references, images and ideas. There are repeated mentions of Andy Kaufman, including references to his Elvis impersonation and work with wrestlers Fred Blassie and Jerry Lawler. The song also invokes the conspiracy theories surrounding the Moon landing and Elvis Presley's death as an indirect nod to the persistent rumors that Kaufman faked his own death. Speaking in 2017 to the NME, Mike Mills explained that the perceived ambiguity of Kaufman's legacy, including questions of whether he was a comedian or a performance artist, and whether his work was funny or irritating, was a way to frame other questions about life within the song:\n", + "\n", + "He's the perfect ghost to lead you through this tour of questioning things. Did the moon landing really happen? Is Elvis really dead? He was ki\n", + "\n", "As part of the Apollo program by NASA, 24 astronauts flew nine missions to the Moon between December 1968 and December 1972. During six successful two-man landing missions, twelve men walked on the lunar surface, six of whom drove Lunar Roving Vehicles as part of the last three missions. Three men have been to the Moon twice, one orbited once and took a circumlunar trajectory the second time, while the other two landed once apiece. Apart from these 24 men, no human being has gone beyond low Earth orbit. No woman has been to the Moon, but a number of non-human animals have circled or orbited it, including two tortoises, several turtles, and five mice.\n", "Apollo missions 8 and 10–17 were the nine crewed missions to the Moon. Apollo 4–6 and AS-201 and AS-202 were uncrewed, while AS-203 is considered a test flight. The Apollo program included three other crewed missions: Apollo 1 (AS-204) did not launch and its crew died in a ground-based capsule fire, while Apollo 7 and Apollo 9 were low Earth orbit missions that only tested spacecraft components and docking maneuvers. Apollo missions 18, 19, and 20 were canceled. Twelve astronauts later flew unused Apollo command modules in the Apollo Applications Program's Skylab and Apollo–Soyuz Test Project. Of the 24 astronauts who flew to the Moon, two went on to command a Skylab mission, one commanded Apollo–Soyuz, one flew as commander for Approach and Landing Tests of the Space Shuttle, and two commanded orbital Space Shuttle missions.\n", "\n", @@ -165,87 +177,82 @@ "\n", "All of these astronauts flew on Gemini, and except for White, each commanded one Gemini and one Apollo mission:\n", "\n", - "Edward H. White II – Second-seat \n", - "\n", - "\"Man on the Moon\" is a song by American alternative rock band R.E.M., released in November 1992 as the second single from their eighth album, Automatic for the People (1992). The lyrics were written by lead singer Michael Stipe, and the music by drummer Bill Berry and guitarist Peter Buck. The song was well received by critics and reached number 30 on the US Billboard Hot 100, number 17 on the US Cash Box Top 100, number 18 on the UK Singles Chart, and number one in Iceland. It remains one of R.E.M.'s most popular songs and was included on the compilations In Time: The Best of R.E.M. 1988–2003 and Part Lies, Part Heart, Part Truth, Part Garbage 1982–2011.\n", - "\"Man on the Moon\" is a tribute to comedian Andy Kaufman, with numerous references to his career including his Elvis impersonation, wrestling, and the film My Breakfast with Blassie. The song's title and chorus refer to Moon landing conspiracy theories, as an oblique allusion to rumors that Kaufman's death in 1984 was faked. The song gave its name to Miloš Forman's Kaufman biopic Man on the Moon (1999), and features prominently in the film's soundtrack.\n", - "\n", - "\n", - "== Composition ==\n", - "\"Man on the Moon\" is a mid-tempo country-rock song following a verse-chorus structure with an added pre-chorus and an instrumental bridge following the second and third choruses. The song has six lines in the first verse but only four in the second and third verses.An early instrumental demo of the song was known to the band as \"C to D Slide\". Guitarist Peter Buck has explained how the music came together: \"'Man on the Moon' was something that Bill [Berry] had, this one chord change that he came in with, which was C to D like the verse of the song, and he said: 'I don't know what to do with that.' I used to finish some of Bill's things ... he would come up with the riffs, but I would be the finish guy for that. I sat down and came up with the chorus, the bridges, and so forth. I remember we showed it to Mike and Michael when they came in later; definitely we had the song finished. I think Bill played bass and I played guitar; we kept going around with it. I think we might have played some mandolin on it in the rehearsal studio.\"Michael Stipe explained in an interview with Charlie Rose how the lyric was written independently of the music, which had no prior association with the song's eventual lyrical content regarding Kaufman. Stipe recounted the other R.E.M. members had written and performed the music of the song and recorded it along with the rest of the Automatic for the People album during studio sessions in Seattle. As of the final week of the recording sessions, Stipe was still struggling to write the lyric, and the others continued to plead with him to finish it. Stipe attempted to argue the track should be an instrumental, but his bandmates were insistent. Stipe listened to the track on a walk around Seattle on his Walkman cassette player and was inspired to write about Andy Kaufman. After Stipe went back to the studio to complete the vocal track, the track was mixed that night and sent out the following day to be mastered.\n", - "\n", - "\n", - "== Lyric ==\n", - "The song's lyric does not tell a conventional story and instead forms a collection of cultural references, images and ideas. There are repeated mentions of Andy Kaufman, including references to his Elvis impersonation and work with wrestlers Fred Blassie and Jerry Lawler. The song also invokes the conspiracy theories surrounding the Moon landing and Elvis Presley's death as an indirect nod to the persistent rumors that Kaufman faked his own death. Speaking in 2017 to the NME, Mike Mills explained that the perceived ambiguity of Kaufman's legacy, including questions of whether he was a comedian or a performance artist, and whether his work was funny or irritating, was a way to frame other questions about life within the song:\n", - "\n", - "He's the perfect ghost to lead you through this tour of questioning things. Did the moon landing really happen? Is Elvis really dead? He was ki\u001b[0m{'message': '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Introduction:\\n\\nThis document details the task you must accomplish. Read it carefully and always follow its instructions.\\n\\n## Safety Preamble\\nThe instructions in this section override those in the task description and style guide sections. Don\\'t answer questions that are harmful or immoral.\\n\\n## System Preamble\\n### Basic Rules\\nYou are a powerful language agent trained by Cohere to help people. You are capable of complex reasoning and augmented with a number of tools. Your job is to plan and reason about how you will use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see an instruction informing you what kind of response to generate. You will construct a plan and then perform a number of reasoning and action steps to solve the problem. When you have determined the answer to the user\\'s request, you will cite your sources in your answers, according the instructions.\\n\\n## User Preamble\\n### Task And Context\\nYou use your advanced complex reasoning capabilities to help people by answering their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You may need to use multiple tools in parallel or sequentially to complete your task. You should focus on serving the user\\'s needs as best you can, which will be wide-ranging. The current date is Wednesday, March 27, 2024 11:42:29.\\n\\n### Style Guide\\nUnless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.\\n\\n### Available Tools\\nHere is a list of tools that you have available to you:\\n\\n\\n```python\\ndef wikipedia(query: string) -> List[Dict]\\n \"\"\"Search for information on Wikipedia\\n Args: \\n query (string): query to look up in retriever\\n \"\"\"\\n pass\\n```\\n\\n```python\\ndef search earth(query: string) -> List[Dict]\\n \"\"\"Search for information on search earth\\n Args: \\n query (string): query to look up in retriever\\n \"\"\"\\n pass\\n```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Human: Write all output in capital letters. What was the hometown of the mother of the second person to walk on the moon?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Carefully perform the following instructions, in order, starting each with a new line.\\nFirstly, You may need to use complex and advanced reasoning to complete your task and answer the question. Think about how you can use the provided tools to answer the question and come up with a high level plan you will execute.\\nWrite \\'Plan:\\' followed by an initial high level plan of how you will solve the problem including the tools and steps required.\\nSecondly, Carry out your plan by repeatedly using actions, reasoning over the results, and re-evaluating your plan. Perform Action, Observation, Reflection steps with the following format. Write \\'Action:\\' followed by a json formatted action containing the \"tool_name\" and \"parameters\"\\n Next you will analyze the \\'Observation:\\', this is the result of the action.\\nAfter that you should always think about what to do next. Write \\'Reflection:\\' followed by what you\\'ve figured out so far, any changes you need to make to your plan, and what you will do next including if you know the answer to the question.\\n... (this Action/Observation/Reflection can repeat N times)\\nThirdly, Decide which of the retrieved documents are relevant to the user\\'s last input by writing \\'Relevant Documents:\\' followed by comma-separated list of document numbers. If none are relevant, you should instead write \\'None\\'.\\nFourthly, Decide which of the retrieved documents contain facts that should be cited in a good answer to the user\\'s last input by writing \\'Cited Documents:\\' followed a comma-separated list of document numbers. If you don\\'t want to cite any of them, you should instead write \\'None\\'.\\nFifthly, Write \\'Answer:\\' followed by a response to the user\\'s last input in high quality natural english. Use the retrieved documents to help you. Do not insert any citations or grounding markup.\\nFinally, Write \\'Grounded answer:\\' followed by a response to the user\\'s last input in high quality natural english. Use the symbols and to indicate when a fact comes from a document in the search result, e.g my fact for a fact from document 4.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>\\nPlan: First I will search for who the second person to walk on the moon was, then I will search for that person\\'s mother\\'s hometown and write the answer in capitals.\\nAction: ```json\\n[\\n {\\n \"tool_name\": \"wikipedia\",\\n \"parameters\": {\\n \"query\": \"second man to walk on the moon\"\\n }\\n }\\n]\\n```<|END_OF_TURN_TOKEN|>\\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>\\nDocument 0\\nWalk the Moon (stylized as WALK THE MOON) is an American pop rock band based in Cincinnati, Ohio. Lead singer Nicholas Petricca started the band in 2006, while a student at Kenyon College, deriving the band\\'s name from the song \"Walking on the Moon\" by The Police. Although the band is best known for their most successful hit single to date \"Shut Up and Dance\", other notable songs include \"Anna Sun\" and \"One Foot\".\\nWalk the Moon has cited Talking Heads as influences. The band\\'s use of 1980s musical mainstays, such as keyboard and synthesizer, is also notable.\\n\\n\\n== History ==\\n\\n\\n=== 2010–2011: Beginning, Anna Sun and i Want! i Want! ===\\n\\nThe group independently released their debut studio album, I Want! I Want!, in November 2010, receiving airplay for the track \"Anna Sun\" on multiple alternative radio stations. Along with the success of \"Anna Sun\", Alt Nation named them a band you need to know for the summer of 2012. Influential music blog Neon Gold helped to break the band in January 2011, calling \"Anna Sun\", \"the kind of stuff British A&R dreams, and major label bidding wars, are made of.\" In February 2011, Walk the Moon signed to RCA Records.\\nIn 2011, the band members began to paint their faces for live performances and they would bring enough paint to share with audience members. They have claimed it has become a “live tradition”. Bonnaroo’s camera crew documented the painting process in a short video from the 2011 festival. The band played at the Sasquatch Music Festival and Firefly Music Festival. In these years, they were known for their energetic performances and tireless touring schedule.\\nBefore the release of their self-titled album, Walk the Moon joined many other performers at the Music Midtown festival and performed on the Great Southeast Music Hall Stage in Atlanta, Georgia in September 2011. In spring 2011, the band went on a short tour with the west coast band, Grouplove, as well as supporting Panic! at the Disco and Weezer on select dates. The band played on the main stage at the 20th Anniversary of Lollapalooza and also supported Local Natives in an Official Lollaplooza Aftershow at Lincoln Hall.\\nThe band recorded i Want! i Want! with Chris Schmidt and Ben Cochran at Soap Floats Recording Studio in their hometown of Cincinnati, Ohio and then self-released it. The lead single from the album, \"Anna Sun\", became a surprise hit in the summer of 2011 following an endorsement by the Esquire article \"30 Summer Songs Every Man Should Listen To\". The song was written by Petricca and New York songwriter Nick Lerangis as their time at Kenyon College came to an end. \"It\\'s about college, about maintaining that little bit of being a kid,\" Petricca said. \"Don\\'t be afraid to play.\" The song was named after one of their favorite teachers. It was named song of the summer by MTV and Seventeen Mag, and one of the top songs of the year by Amazon. It has been officially remixed by Fool\\'s Gold and received a Trouble Productions remix by Albert Hammond Jr. Anna Sun rose to the number one spot on Alt. Nation on Sirius XM Radio. \"Anna Sun\" was added to the video rotation of American Eagle Outfitters stores in May 2011. It was featured on the hit TV show Vampire Diaries in the first episode of season three. It was also the free single of the week on iTunes for the week of May 15.\\nFilmed in 2011 in Cincinnati\\'s Over-the-Rhine neighborhood, the \"Anna Sun\" music video was released to coincide with the album. The video was shot on-location at the Cincinnati Mockbee building, as well as at a city park. It was directed and produced by Patrick Meier of the Cincinnati company, Contrast Productions, and features original choreography from Kim Popa of PONES Inc., as well as a cast full of the band\\'s friends and locals from Cincinnati. MTV Hive calls the video a \"hilariously choreographed, neon-colored and awesomely shot in one take\" production.\\n\\n\\n=== 2012–2013: Walk the Moon and Tightrope EP ===\\n\\nThe band\\'s self-titled major label debut Walk t\\n\\nAs part of the Apollo program by NASA, 24 astronauts flew nine missions to the Moon between December 1968 and December 1972. During six successful two-man landing missions, twelve men walked on the lunar surface, six of whom drove Lunar Roving Vehicles as part of the last three missions. Three men have been to the Moon twice, one orbited once and took a circumlunar trajectory the second time, while the other two landed once apiece. Apart from these 24 men, no human being has gone beyond low Earth orbit. No woman has been to the Moon, but a number of non-human animals have circled or orbited it, including two tortoises, several turtles, and five mice.\\nApollo missions 8 and 10–17 were the nine crewed missions to the Moon. Apollo 4–6 and AS-201 and AS-202 were uncrewed, while AS-203 is considered a test flight. The Apollo program included three other crewed missions: Apollo 1 (AS-204) did not launch and its crew died in a ground-based capsule fire, while Apollo 7 and Apollo 9 were low Earth orbit missions that only tested spacecraft components and docking maneuvers. Apollo missions 18, 19, and 20 were canceled. Twelve astronauts later flew unused Apollo command modules in the Apollo Applications Program\\'s Skylab and Apollo–Soyuz Test Project. Of the 24 astronauts who flew to the Moon, two went on to command a Skylab mission, one commanded Apollo–Soyuz, one flew as commander for Approach and Landing Tests of the Space Shuttle, and two commanded orbital Space Shuttle missions.\\n\\n\\n== Prime crew members ==\\nNASA\\'s Director of Flight Crew Operations during the Gemini and Apollo programs was Donald K. \"Deke\" Slayton, one of the original Mercury Seven astronauts, who was medically grounded in September 1962 due to a minor cardiac arrhythmia – paroxysmal atrial fibrillation. Slayton was responsible for making all Gemini and Apollo crew assignments. In March 1972, Slayton was restored to flight status, and flew on the 1975 Apollo–Soyuz Test Project mission.\\nThe prime crew members selected for actual missions are here grouped by their NASA astronaut selection groups, and within each group in the order selected for flight. Two versions of the Apollo Command/Service Module (CSM) spacecraft were developed: Block I, intended for preliminary low Earth orbit testing; and Block II, redesigned for the lunar landing. The Block I crew position titles were Command Pilot, Senior Pilot (second seat), and Pilot (third seat). The corresponding Block II titles were: Commander, Command Module Pilot, and Lunar Module Pilot. The second seat pilot was given secondary responsibility for celestial navigation to keep the CSM\\'s guidance computer accurately calibrated with the spacecraft\\'s true position, and the third seat pilot served as a flight engineer, monitoring the health of the spacecraft systems.\\n\\n\\n== Apollo astronauts by their dates of selection by NASA ==\\n\\n\\n=== 1959 ===\\nVirgil I. \"Gus\" Grissom began his career at NASA in 1959. In 1966, he was selected as Command Pilot for the first crewed Apollo mission, a low Earth orbit test. This mission ended a month before its scheduled launch, when a cabin fire on the launch pad killed Grissom, Ed White and Roger Chaffee on January 27, 1967.\\nWalter M. Schirra Jr. also began his NASA career in 1959. He was selected in October 1968 as Command Pilot for Apollo 7, an 11-day, low Earth orbit shakedown test of the three-man Apollo Command/Service Module and the first crewed launch for the Apollo project.\\nAlan B. Shepard Jr. – America\\'s first man in space on Freedom 7 was originally selected to command Gemini 3, but was medically grounded for the duration of Gemini due to Ménière\\'s disease and assisted Slayton in Flight Operations. After corrective surgery, Shepard was restored to flight status and commanded Apollo 14, the third successful Moon landing mission.\\n\\n\\n=== 1962 ===\\n\\nAll of these astronauts flew on Gemini, and except for White, each commanded one Gemini and one Apollo mission:\\n\\nEdward H. White II – Second-seat \\n\\n\"Man on the Moon\" is a song by American alternative rock band R.E.M., released in November 1992 as the second single from their eighth album, Automatic for the People (1992). The lyrics were written by lead singer Michael Stipe, and the music by drummer Bill Berry and guitarist Peter Buck. The song was well received by critics and reached number 30 on the US Billboard Hot 100, number 17 on the US Cash Box Top 100, number 18 on the UK Singles Chart, and number one in Iceland. It remains one of R.E.M.\\'s most popular songs and was included on the compilations In Time: The Best of R.E.M. 1988–2003 and Part Lies, Part Heart, Part Truth, Part Garbage 1982–2011.\\n\"Man on the Moon\" is a tribute to comedian Andy Kaufman, with numerous references to his career including his Elvis impersonation, wrestling, and the film My Breakfast with Blassie. The song\\'s title and chorus refer to Moon landing conspiracy theories, as an oblique allusion to rumors that Kaufman\\'s death in 1984 was faked. The song gave its name to Miloš Forman\\'s Kaufman biopic Man on the Moon (1999), and features prominently in the film\\'s soundtrack.\\n\\n\\n== Composition ==\\n\"Man on the Moon\" is a mid-tempo country-rock song following a verse-chorus structure with an added pre-chorus and an instrumental bridge following the second and third choruses. The song has six lines in the first verse but only four in the second and third verses.An early instrumental demo of the song was known to the band as \"C to D Slide\". Guitarist Peter Buck has explained how the music came together: \"\\'Man on the Moon\\' was something that Bill [Berry] had, this one chord change that he came in with, which was C to D like the verse of the song, and he said: \\'I don\\'t know what to do with that.\\' I used to finish some of Bill\\'s things ... he would come up with the riffs, but I would be the finish guy for that. I sat down and came up with the chorus, the bridges, and so forth. I remember we showed it to Mike and Michael when they came in later; definitely we had the song finished. I think Bill played bass and I played guitar; we kept going around with it. I think we might have played some mandolin on it in the rehearsal studio.\"Michael Stipe explained in an interview with Charlie Rose how the lyric was written independently of the music, which had no prior association with the song\\'s eventual lyrical content regarding Kaufman. Stipe recounted the other R.E.M. members had written and performed the music of the song and recorded it along with the rest of the Automatic for the People album during studio sessions in Seattle. As of the final week of the recording sessions, Stipe was still struggling to write the lyric, and the others continued to plead with him to finish it. Stipe attempted to argue the track should be an instrumental, but his bandmates were insistent. Stipe listened to the track on a walk around Seattle on his Walkman cassette player and was inspired to write about Andy Kaufman. After Stipe went back to the studio to complete the vocal track, the track was mixed that night and sent out the following day to be mastered.\\n\\n\\n== Lyric ==\\nThe song\\'s lyric does not tell a conventional story and instead forms a collection of cultural references, images and ideas. There are repeated mentions of Andy Kaufman, including references to his Elvis impersonation and work with wrestlers Fred Blassie and Jerry Lawler. The song also invokes the conspiracy theories surrounding the Moon landing and Elvis Presley\\'s death as an indirect nod to the persistent rumors that Kaufman faked his own death. Speaking in 2017 to the NME, Mike Mills explained that the perceived ambiguity of Kaufman\\'s legacy, including questions of whether he was a comedian or a performance artist, and whether his work was funny or irritating, was a way to frame other questions about life within the song:\\n\\nHe\\'s the perfect ghost to lead you through this tour of questioning things. Did the moon landing really happen? Is Elvis really dead? He was ki<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>\\n', 'chat_history': [], 'model': 'command-r', 'raw_prompting': True}\n", - "\u001b[32;1m\u001b[1;3mReflection: I have found that the second person to walk on the moon was Edwin Aldrin. Now I will search for his mother's hometown.\n", + "Edward H. White II – Second-seat \u001b[0m\u001b[32;1m\u001b[1;3mReflection: I have found that the second person to walk on the moon was Alan Shepard. Now I will search for Alan Shepard's mother's hometown and write the answer.\n", "Action: ```json\n", "[\n", " {\n", " \"tool_name\": \"wikipedia\",\n", " \"parameters\": {\n", - " \"query\": \"Edwin Aldrin mother's hometown\"\n", + " \"query\": \"Alan Shepard mother's hometown\"\n", " }\n", " }\n", "]\n", - "```\u001b[0m\u001b[36;1m\u001b[1;3mBuzz Aldrin (; born Edwin Eugene Aldrin Jr.; January 20, 1930) is an American former astronaut, engineer and fighter pilot. He made three spacewalks as pilot of the 1966 Gemini 12 mission, and was the Lunar Module Eagle pilot on the 1969 Apollo 11 mission. He was the second person to walk on the Moon after mission commander Neil Armstrong.\n", - "Born in Glen Ridge, New Jersey, Aldrin graduated third in the class of 1951 from the United States Military Academy at West Point with a degree in mechanical engineering. He was commissioned into the United States Air Force and served as a jet fighter pilot during the Korean War. He flew 66 combat missions and shot down two MiG-15 aircraft.\n", - "After earning a Doctor of Science degree in astronautics from the Massachusetts Institute of Technology (MIT), Aldrin was selected as a member of NASA's Astronaut Group 3, making him the first astronaut with a doctoral degree. His doctoral thesis, Line-of-Sight Guidance Techniques for Manned Orbital Rendezvous, earned him the nickname \"Dr. Rendezvous\" from fellow astronauts. His first space flight was in 1966 on Gemini 12, during which he spent over five hours on extravehicular activity. Three years later, Aldrin set foot on the Moon at 03:15:16 on July 21, 1969 (UTC), nineteen minutes after Armstrong first touched the surface, while command module pilot Michael Collins remained in lunar orbit. A Presbyterian elder, Aldrin became the first person to hold a religious ceremony on the Moon when he privately took communion.\n", - "After leaving NASA in 1971, Aldrin became Commandant of the U.S. Air Force Test Pilot School. He retired from the Air Force in 1972 after 21 years of service. His autobiographies Return to Earth (1973) and Magnificent Desolation (2009) recount his struggles with clinical depression and alcoholism in the years after leaving NASA. Aldrin continues to advocate for space exploration, particularly a human mission to Mars. He developed the Aldrin cycler, a special spacecraft trajectory that makes travel to Mars more efficient in terms of time and propellant. He has been accorded numerous honors, including the Presidential Medal of Freedom in 1969.\n", + "```\u001b[0m\u001b[36;1m\u001b[1;3mAlan Eugene Jackson (born October 17, 1958) is an American singer-songwriter. He is known for performing a style widely regarded as \"neotraditional country\", as well as penning many of his own songs. Jackson has recorded 21 studio albums, including two Christmas albums, and two gospel albums, as well as released three greatest-hits albums.\n", + "Jackson is one of the best-selling music artists of all time, having sold over 75 million records worldwide, with 44 million sold in the United States alone. He has had 66 songs appear on the Billboard Hot Country Singles & Tracks chart; of the 66 titles, and six featured singles, 38 have reached the top five and 35 have claimed the number one spot. Out of 15 titles to reach the Billboard Top Country Albums chart, nine have been certified multi-platinum. He is the recipient of two Grammy Awards, 16 CMA Awards, 17 ACM Awards and nominee of multiple other awards. He is a member of the Grand Ole Opry, and was inducted into the Georgia Music Hall of Fame in 2001. He was inducted into the Country Music Hall of Fame in 2017 by Loretta Lynn and into the Nashville Songwriters Hall of Fame in 2018.\n", + "\n", "\n", + "== Early life ==\n", + "Jackson was born to Joseph Eugene \"Daddy Gene\" Jackson (1927–2000) and Ruth Musick \"Mama Ruth\" Jackson (1930–2017) in Newnan, Georgia, and has four older sisters. He and his immediate family lived in a small home built around his grandfather's old toolshed. The family is primarily of English descent. His mother lived in the home until her death on January 7, 2017. He began writing music in 1983.Growing up, Jackson listened primarily to gospel music, until a friend introduced him to Gene Watson, John Anderson, and Hank Williams Jr. Jackson attended the local Elm Street Elementary and Newnan High School, and joined the band Dixie Steel after graduation. When he was 27, Jackson and his wife of six years, Denise, moved from Newnan to Nashville, Tennessee, where he hoped to pursue music full-time. In 1987, Jackson cut a pre-debut demo album titled New Traditional at Doc's Place in Hendersonville, Tennessee, but it is extremely rare and was released only in Japan.\n", "\n", - "== Early life and education ==\n", - "Aldrin was born Edwin Eugene Aldrin Jr. on January 20, 1930, at Mountainside Hospital in Glen Ridge, New Jersey. His parents, Edwin Eugene Aldrin Sr. and Marion Aldrin (née Moon), lived in neighboring Montclair. His father was an Army aviator during World War I and the assistant commandant of the Army's test pilot school at McCook Field, Ohio, from 1919 to 1922, but left the Army in 1928 and became an executive at Standard Oil. Aldrin had two sisters: Madeleine, who was four years older, and Fay Ann, who was a year and a half older. His nickname, which became his legal first name in 1988, arose as a result of Fay's mispronouncing \"brother\" as \"buzzer\", which was then shortened to \"Buzz\". He was a Boy Scout, achieving the rank of Tenderfoot Scout.Aldrin did well in school, maintaining an A average. He played football and was the starting center for Montclair High School's undefeated 1946 state champion team. His father wanted him to go to the United States Naval Academy in Annapolis, Maryland, and enrolled him at nearby Severn School, a preparatory school for Annapolis, and even secured him a Naval Academy appointment from Albert W. Hawkes, one of the United States senators from New Jersey. Aldrin attended Severn School in 1946, but had other ideas about his future career. He suffered from seasickness and considered ships a distraction from flying airplanes. He faced down his father and told him to ask Hawkes to change the nomination to the United States Military Academy at West Point, New York.Aldrin entered West Point in 1947. He did well academically, finishing first in his class his plebe (first) year. Aldrin was also an excellent athlete, competing in pole vault for the academy track and field team. In 1950, he traveled with a group of West Point cadets to Japan and\n", "\n", - "Francisco Sionil José (December 3, 1924 – January 6, 2022) was a Filipino writer who was one of the most widely read in the English language. A National Artist of the Philippines for Literature, which was bestowed upon him in 2001, José's novels and short stories depict the social underpinnings of class struggles and colonialism in Filipino society. His works—written in English—have been translated into 28 languages, including Korean, Indonesian, Czech, Russian, Latvian, Ukrainian and Dutch. He was often considered the leading Filipino candidate for the Nobel Prize in Literature.\n", + "== Career ==\n", + "In Tennessee, Jackson got his first job in The Nashville Network's mailroom. His wife Denise was a flight attendant. While working, she came in contact with Glen Campbell and requested advice for her husband. Campbell handed her his business card of his manager and told her to call, which helped jumpstart his career. Jackson eventually signed with Arista, and in 1989, he became the first artist signed to the newly formed Arista Nashville branch of Arista Records. Arista released Jackson's debut single, \"Blue Blooded Woman\", in late 1989. Although the song failed to reach top 40 on Hot Country Songs, he reached number three by early 1990 with \"Here in the Real World\". This song served as the title track to his debut studio album, Here in the Real World, which also included two more top five hits (\"Wanted\" and \"Chasin' That Neon Rainbow\") and his first number one, \"I'd Love You All Over Again\". Don't Rock the Jukebox was the title of Jackson's second album. Released in 1991, it included four number-one singles: the title track, \"Someday\", \"Dallas\" and \"Love's Got a Hold on You\", and the number three \"Midnight in Montgomery\". Jackson also co-wrote several songs on Randy Travis' 1991 album High Lonesome.A Lot About Livin' (And a Little 'bout Love), his third album, accounted for the number one hits \"She's Got the Rhythm (And I Got the Blues)\" (which Randy Travis co-wrote) and \"Chattahoochee\", plus the top five hits \"Tonight I Climbed the Wall\", \"Mercury Blues\" and \"(Who Says) You Can't Have It All\". \"Chattahoochee\" also won him the 1994 Country Music Association (CMA) awards for Single and Song of the Year. In 1994, Jackson left his management company, Ten Ten Management, which had overseen his career up to that point, and switched to Gary Overton. His fourth album was titled Who I Am, and it contained four number one hit\n", "\n", + "Alan LaVern Bean (March 15, 1932 – May 26, 2018) was an American naval officer and aviator, aeronautical engineer, test pilot, NASA astronaut and painter. He was selected to become an astronaut by NASA in 1963 as part of Astronaut Group 3, and was the fourth person to walk on the Moon.\n", + "Before becoming an astronaut, Bean graduated with a Bachelor of Science degree in Aeronautical Engineering from University of Texas at Austin in 1955 and re-joined the U.S. Navy—he served as an enlisted member for a year after his high school graduation. He received his naval aviator wings in 1956 and served as a fighter pilot. In 1960, he graduated from the U.S. Naval Test Pilot School, flew as a test pilot and was The New Nine selection finalist in 1962.\n", + "He made his first flight into space aboard Apollo 12, the second crewed mission to land on the Moon, at age 37 in November 1969. He made his second and final flight into space on the Skylab 3 mission in 1973, the second crewed mission to the Skylab space station. After retiring from the United States Navy in 1975 and NASA in 1981, he pursued his interest in painting, depicting various space-related scenes and documenting his own experiences in space as well as those of his fellow Apollo program astronauts. He was the last living crew member of Apollo 12.\n", "\n", - "== Early life ==\n", - "José was born in Rosales, Pangasinan, the setting of many of his stories. He spent his childhood in Barrio Cabugawan, Rosales, where he first began to write. José is of Ilocano descent whose family had migrated to Pangasinan prior to his birth. Fleeing poverty, his forefathers traveled from Ilocos towards Cagayan Valley through the Santa Fe Trail. Like many migrant families, they brought their lifetime possessions with them, including uprooted molave posts of their old houses and their alsong, a stone mortar for pounding rice.One of the greatest influences to José was his industrious mother who went out of her way to get him the books he loved to read, while making sure her family did not go hungry despite poverty and landlessness. José started writing in grade school, at the time he started reading. In the fifth grade, one of José's teachers opened the school library to her students, which is how José managed to read the novels of José Rizal, Willa Cather’s My Antonia, Faulkner and Steinbeck. Reading about Basilio and Crispin in Rizal's Noli Me Tangere made the young José cry, because injustice was not an alien thing to him. When José was five years old, his grandfather who was a soldier during the Philippine revolution, had once tearfully showed him the land their family had once tilled but was taken away by rich mestizo landlords who knew how to work the system against illiterates like his grandfather.\n", "\n", + "== Biography ==\n", "\n", - "== Writing career ==\n", - "José attended the University of Santo Tomas after World War II, but dropped out and plunged into writing and journalism in Manila. In subsequent years, he edited various literary and journalistic publications, started a publishing house, and founded the Philippine branch of PEN, an international organization for writers. José received numerous awards for his work. The Pretenders is his most popular novel, which is the story of one man's alienation from his poor background and the decadence of his wife's wealthy family.José Rizal's life and writings profoundly influenced José's work. The five volume Rosales Saga, in particular, employs and integrates themes and characters from Rizal's work. Throughout his career, José's writings espouse social justice and change to better the lives of average Filipino families. He is one of the most critically acclaimed Filipino authors internationally, although much underrated in his own country because of his authentic Filipino English and his anti-elite views.\n", - "\"Authors like myself choose the city as a setting for their fiction because the city itself illustrates the progress or the sophistication that a particular country has achieved. Or, on the other hand, it might also reflect the kind of decay, both social and perhaps moral, that has come upon a particular people.\"\n", - "Sionil José also owned Solidaridad Bookshop, located on Padre Faura Street in Ermita, Manila. The bookshop offers mostly hard-to-find books and Filipiniana reading materials. It is said to be one of the favorite haunts of many local writers.In his regular column, Hindsight, in The Philippine STAR, dated September 12, 2011, he wrote \"Why we are shallow\", blaming the decline of Filipino intellectual and cultural standards on a variety of modern amenities, including media, the education system—particularly the loss of emphasis on classic literature and the study of Greek and Latin—and the abundance and imme\n", "\n", - "Magpakailanman (English: Forevermore) is a weekly drama anthology broadcast by GMA Network. The show is hosted by 24 Oras anchor and GMA Kapuso Foundation founder Mel Tiangco and features inspiring stories and life experiences from both famous and ordinary people. It was aired every Monday until the end of 2004 and was moved to Thursday from 2005 on the network's primetime block.\n", - "The following are the lists of Magpakailanman episodes listed by the year they were aired, in the first incarnation that was aired from December 2, 2002, to December 27, 2007.\n", + "=== Early life and education ===\n", + "Bean was born March 15, 1932, in Wheeler, the seat of Wheeler County in the northeastern Texas Panhandle, to parents Arnold Horace Bean and Frances Caroline Bean (née Murphy), who lived from 1908 to 1983, and 1906 to 1981, respectively. He considered Fort Worth his hometown. He was of Scottish descent. As a boy, he lived in Minden, the seat of Webster Parish in northwestern Louisiana, where his father worked for the U.S. Soil Conservation Service. Bean was a Boy Scout and he earned the rank of First Class. He graduated from R. L. Paschal High School in Fort Worth, Texas, in 1949. Following his high school graduation in 1949, Bean enlisted in the U.S. Naval Reserve.Bean received a Bachelor of Science degree in aeronautical engineering from the University of Texas at Austin in 1955, where he attended on a Naval Reserve Officers Training Corps (NROTC) scholarship. While at the university, he also joined the Delta Kappa Epsilon fraternity.\n", "\n", "\n", - "== Series overview ==\n", + "=== Military service ===\n", + "He was an Electronics Technician Striker at the NAS Dallas, Texas, until September 1950, when he was honorably discharged. In January 1955, Bean was commissioned a U.S. Navy ensign through the NROTC at the University of Texas at Austin, and attended flight training. After completing flight training in June 1956, he was assigned to Attack Squadron 44 (VA-44) at NAS Jacksonville, Florida, from 1956 to 1960, flying the F9F Cougar and A4D Skyhawk. After a four-year tour of duty, he attended the U.S. Naval Test Pilot School (USNTPS) at NAS Patuxent River, Maryland, where his instructor was his future Apollo 12 Commander, Pete Conrad, graduating in November 1960. Bean took art classes at St. Mary's College of Maryland during this tour, and flew as a test pilot on several types of naval aircraft. Following his assignment at USNTPS and aviation safety training with the University of Southern California (USC), he went through additional instruction with his old Attack Squadron 44, and was assigned to Navy Attack Squadron VA-172 at NAS Cecil Field, Florida, flying the A-4 Skyhawks, during which time he was selected as a NASA astronaut.Bean logged more than 7,145 hours of flying time, including 4,890 hours in jet aircraft.\n", "\n", "\n", - "== Episode list ==\n", + "=== NASA career ===\n", + "Bean was selected by NASA as part of Astronaut Group 3 in 1963 (after not being selected for Astronaut Group 2 the previous year). He was selected to be the backup command pilot for Gemini 10, but was unsuccessful in securing an early Apollo flight assignment. He was placed in the Apollo Applications Program in the interim. In that capacity, he was the first astronaut to dive in the Neutral Buoyancy Simu\n", "\n", + "Mari Aldon (born Marija Aldona Pauliutė; 17 November 1925 – 31 October 2004) was a Lithuanian-born American actress.\n", + "\n", + "\n", + "== Early life ==\n", + "Mari Aldon was born in Tauragė, Lithuania. Her father Antanas Paulius was a policeman, mother Antanina (Antosė) Paulienė was a nurse. Father moved to America looking for a job. Soon after, when Mari was three years old, her mother also moved to Toronto, Canada with her daughter. There, she attended Givens Public School and Central High School. She studied ballet, drama, piano, and singing. Her early performances were noticed in Lithuanian newspapers of America. She had a sister.\n", "\n", - "=== First incarnation ===\n", "\n", + "== Career ==\n", + "Before Aldon began working in films, she acted for 11 months in a road company of A Streetcar Named Desire and danced with the Canadian Ballet. She also appeared on radio with Alan Young and on The Harold Peary Show.\n", + "After making her screen debut in a minor role in The Locket (1946) she gradually evolved to playing supporting or lead roles. Her most notable performance was starring opposite Gary Cooper in the 1951 Western Distant Drums. By the mid-1950s she was appearing either in B Pictures like the British thriller Mask of Dust (1954) or in supporting roles in more expensive films such as David Lean's Summertime (1955).After this point she worked largely in television, such as on the TV Western Wagon Train in 1959 as Freda Johnson in \"The Vivian Carter Story\" (S2E23) and in 1960 as Hester Millikan in \"The Jeremy Dow Story\" (S4E14). She guest-starred in a 1961 episode of Ichabod and Me.\n", "\n", - "==== 2002 ====\n", "\n", + "== Personal life ==\n", + "Aldon married Tay Garnett in London, England on 13 August 1953. Their daughter, Tiela Aldon Garnett (later Daniels), was born in Los Angeles, California on 25 October 1955.On 17 January 1958, Aldon became a US citizen. In August 1970, Aldon filed for divorce from Garnett in Los Angeles, she was widowed seven years later. Aldon and Garnett had a ranch, near King Vidor in Paso Robles, California. Close relatives still live in her hometown of Tauragė, Lithuania, with whom she kept in touch.\n", "\n", - "==== 2003 ====\n", "\n", + "== Death ==\n", + "Aldon died on 31 October 2004 in Las Vegas, aged 78, of cancer.\n", "\n", - "==== 2004 ====\n", "\n", + "== Filmography ==\n", "\n", - "==== 2005 ====\n", "\n", + "== References ==\n", "\n", - "==== 2006 ====\n", "\n", + "== Bibliography ==\n", + "Aaker, Everett. George Raft: The Films. McFarland, 2013.\n", "\n", - "==== 2007 ====\n", "\n", + "== External links ==\n", "\n", - "== References ==\u001b[0m{'message': '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Introduction:\\n\\nThis document details the task you must accomplish. Read it carefully and always follow its instructions.\\n\\n## Safety Preamble\\nThe instructions in this section override those in the task description and style guide sections. Don\\'t answer questions that are harmful or immoral.\\n\\n## System Preamble\\n### Basic Rules\\nYou are a powerful language agent trained by Cohere to help people. You are capable of complex reasoning and augmented with a number of tools. Your job is to plan and reason about how you will use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see an instruction informing you what kind of response to generate. You will construct a plan and then perform a number of reasoning and action steps to solve the problem. When you have determined the answer to the user\\'s request, you will cite your sources in your answers, according the instructions.\\n\\n## User Preamble\\n### Task And Context\\nYou use your advanced complex reasoning capabilities to help people by answering their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You may need to use multiple tools in parallel or sequentially to complete your task. You should focus on serving the user\\'s needs as best you can, which will be wide-ranging. The current date is Wednesday, March 27, 2024 11:42:29.\\n\\n### Style Guide\\nUnless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.\\n\\n### Available Tools\\nHere is a list of tools that you have available to you:\\n\\n\\n```python\\ndef wikipedia(query: string) -> List[Dict]\\n \"\"\"Search for information on Wikipedia\\n Args: \\n query (string): query to look up in retriever\\n \"\"\"\\n pass\\n```\\n\\n```python\\ndef search earth(query: string) -> List[Dict]\\n \"\"\"Search for information on search earth\\n Args: \\n query (string): query to look up in retriever\\n \"\"\"\\n pass\\n```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Human: Write all output in capital letters. What was the hometown of the mother of the second person to walk on the moon?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Carefully perform the following instructions, in order, starting each with a new line.\\nFirstly, You may need to use complex and advanced reasoning to complete your task and answer the question. Think about how you can use the provided tools to answer the question and come up with a high level plan you will execute.\\nWrite \\'Plan:\\' followed by an initial high level plan of how you will solve the problem including the tools and steps required.\\nSecondly, Carry out your plan by repeatedly using actions, reasoning over the results, and re-evaluating your plan. Perform Action, Observation, Reflection steps with the following format. Write \\'Action:\\' followed by a json formatted action containing the \"tool_name\" and \"parameters\"\\n Next you will analyze the \\'Observation:\\', this is the result of the action.\\nAfter that you should always think about what to do next. Write \\'Reflection:\\' followed by what you\\'ve figured out so far, any changes you need to make to your plan, and what you will do next including if you know the answer to the question.\\n... (this Action/Observation/Reflection can repeat N times)\\nThirdly, Decide which of the retrieved documents are relevant to the user\\'s last input by writing \\'Relevant Documents:\\' followed by comma-separated list of document numbers. If none are relevant, you should instead write \\'None\\'.\\nFourthly, Decide which of the retrieved documents contain facts that should be cited in a good answer to the user\\'s last input by writing \\'Cited Documents:\\' followed a comma-separated list of document numbers. If you don\\'t want to cite any of them, you should instead write \\'None\\'.\\nFifthly, Write \\'Answer:\\' followed by a response to the user\\'s last input in high quality natural english. Use the retrieved documents to help you. Do not insert any citations or grounding markup.\\nFinally, Write \\'Grounded answer:\\' followed by a response to the user\\'s last input in high quality natural english. Use the symbols and to indicate when a fact comes from a document in the search result, e.g my fact for a fact from document 4.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>\\nPlan: First I will search for who the second person to walk on the moon was, then I will search for that person\\'s mother\\'s hometown and write the answer in capitals.\\nAction: ```json\\n[\\n {\\n \"tool_name\": \"wikipedia\",\\n \"parameters\": {\\n \"query\": \"second man to walk on the moon\"\\n }\\n }\\n]\\n```<|END_OF_TURN_TOKEN|>\\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>\\nDocument 0\\nWalk the Moon (stylized as WALK THE MOON) is an American pop rock band based in Cincinnati, Ohio. Lead singer Nicholas Petricca started the band in 2006, while a student at Kenyon College, deriving the band\\'s name from the song \"Walking on the Moon\" by The Police. Although the band is best known for their most successful hit single to date \"Shut Up and Dance\", other notable songs include \"Anna Sun\" and \"One Foot\".\\nWalk the Moon has cited Talking Heads as influences. The band\\'s use of 1980s musical mainstays, such as keyboard and synthesizer, is also notable.\\n\\n\\n== History ==\\n\\n\\n=== 2010–2011: Beginning, Anna Sun and i Want! i Want! ===\\n\\nThe group independently released their debut studio album, I Want! I Want!, in November 2010, receiving airplay for the track \"Anna Sun\" on multiple alternative radio stations. Along with the success of \"Anna Sun\", Alt Nation named them a band you need to know for the summer of 2012. Influential music blog Neon Gold helped to break the band in January 2011, calling \"Anna Sun\", \"the kind of stuff British A&R dreams, and major label bidding wars, are made of.\" In February 2011, Walk the Moon signed to RCA Records.\\nIn 2011, the band members began to paint their faces for live performances and they would bring enough paint to share with audience members. They have claimed it has become a “live tradition”. Bonnaroo’s camera crew documented the painting process in a short video from the 2011 festival. The band played at the Sasquatch Music Festival and Firefly Music Festival. In these years, they were known for their energetic performances and tireless touring schedule.\\nBefore the release of their self-titled album, Walk the Moon joined many other performers at the Music Midtown festival and performed on the Great Southeast Music Hall Stage in Atlanta, Georgia in September 2011. In spring 2011, the band went on a short tour with the west coast band, Grouplove, as well as supporting Panic! at the Disco and Weezer on select dates. The band played on the main stage at the 20th Anniversary of Lollapalooza and also supported Local Natives in an Official Lollaplooza Aftershow at Lincoln Hall.\\nThe band recorded i Want! i Want! with Chris Schmidt and Ben Cochran at Soap Floats Recording Studio in their hometown of Cincinnati, Ohio and then self-released it. The lead single from the album, \"Anna Sun\", became a surprise hit in the summer of 2011 following an endorsement by the Esquire article \"30 Summer Songs Every Man Should Listen To\". The song was written by Petricca and New York songwriter Nick Lerangis as their time at Kenyon College came to an end. \"It\\'s about college, about maintaining that little bit of being a kid,\" Petricca said. \"Don\\'t be afraid to play.\" The song was named after one of their favorite teachers. It was named song of the summer by MTV and Seventeen Mag, and one of the top songs of the year by Amazon. It has been officially remixed by Fool\\'s Gold and received a Trouble Productions remix by Albert Hammond Jr. Anna Sun rose to the number one spot on Alt. Nation on Sirius XM Radio. \"Anna Sun\" was added to the video rotation of American Eagle Outfitters stores in May 2011. It was featured on the hit TV show Vampire Diaries in the first episode of season three. It was also the free single of the week on iTunes for the week of May 15.\\nFilmed in 2011 in Cincinnati\\'s Over-the-Rhine neighborhood, the \"Anna Sun\" music video was released to coincide with the album. The video was shot on-location at the Cincinnati Mockbee building, as well as at a city park. It was directed and produced by Patrick Meier of the Cincinnati company, Contrast Productions, and features original choreography from Kim Popa of PONES Inc., as well as a cast full of the band\\'s friends and locals from Cincinnati. MTV Hive calls the video a \"hilariously choreographed, neon-colored and awesomely shot in one take\" production.\\n\\n\\n=== 2012–2013: Walk the Moon and Tightrope EP ===\\n\\nThe band\\'s self-titled major label debut Walk t\\n\\nAs part of the Apollo program by NASA, 24 astronauts flew nine missions to the Moon between December 1968 and December 1972. During six successful two-man landing missions, twelve men walked on the lunar surface, six of whom drove Lunar Roving Vehicles as part of the last three missions. Three men have been to the Moon twice, one orbited once and took a circumlunar trajectory the second time, while the other two landed once apiece. Apart from these 24 men, no human being has gone beyond low Earth orbit. No woman has been to the Moon, but a number of non-human animals have circled or orbited it, including two tortoises, several turtles, and five mice.\\nApollo missions 8 and 10–17 were the nine crewed missions to the Moon. Apollo 4–6 and AS-201 and AS-202 were uncrewed, while AS-203 is considered a test flight. The Apollo program included three other crewed missions: Apollo 1 (AS-204) did not launch and its crew died in a ground-based capsule fire, while Apollo 7 and Apollo 9 were low Earth orbit missions that only tested spacecraft components and docking maneuvers. Apollo missions 18, 19, and 20 were canceled. Twelve astronauts later flew unused Apollo command modules in the Apollo Applications Program\\'s Skylab and Apollo–Soyuz Test Project. Of the 24 astronauts who flew to the Moon, two went on to command a Skylab mission, one commanded Apollo–Soyuz, one flew as commander for Approach and Landing Tests of the Space Shuttle, and two commanded orbital Space Shuttle missions.\\n\\n\\n== Prime crew members ==\\nNASA\\'s Director of Flight Crew Operations during the Gemini and Apollo programs was Donald K. \"Deke\" Slayton, one of the original Mercury Seven astronauts, who was medically grounded in September 1962 due to a minor cardiac arrhythmia – paroxysmal atrial fibrillation. Slayton was responsible for making all Gemini and Apollo crew assignments. In March 1972, Slayton was restored to flight status, and flew on the 1975 Apollo–Soyuz Test Project mission.\\nThe prime crew members selected for actual missions are here grouped by their NASA astronaut selection groups, and within each group in the order selected for flight. Two versions of the Apollo Command/Service Module (CSM) spacecraft were developed: Block I, intended for preliminary low Earth orbit testing; and Block II, redesigned for the lunar landing. The Block I crew position titles were Command Pilot, Senior Pilot (second seat), and Pilot (third seat). The corresponding Block II titles were: Commander, Command Module Pilot, and Lunar Module Pilot. The second seat pilot was given secondary responsibility for celestial navigation to keep the CSM\\'s guidance computer accurately calibrated with the spacecraft\\'s true position, and the third seat pilot served as a flight engineer, monitoring the health of the spacecraft systems.\\n\\n\\n== Apollo astronauts by their dates of selection by NASA ==\\n\\n\\n=== 1959 ===\\nVirgil I. \"Gus\" Grissom began his career at NASA in 1959. In 1966, he was selected as Command Pilot for the first crewed Apollo mission, a low Earth orbit test. This mission ended a month before its scheduled launch, when a cabin fire on the launch pad killed Grissom, Ed White and Roger Chaffee on January 27, 1967.\\nWalter M. Schirra Jr. also began his NASA career in 1959. He was selected in October 1968 as Command Pilot for Apollo 7, an 11-day, low Earth orbit shakedown test of the three-man Apollo Command/Service Module and the first crewed launch for the Apollo project.\\nAlan B. Shepard Jr. – America\\'s first man in space on Freedom 7 was originally selected to command Gemini 3, but was medically grounded for the duration of Gemini due to Ménière\\'s disease and assisted Slayton in Flight Operations. After corrective surgery, Shepard was restored to flight status and commanded Apollo 14, the third successful Moon landing mission.\\n\\n\\n=== 1962 ===\\n\\nAll of these astronauts flew on Gemini, and except for White, each commanded one Gemini and one Apollo mission:\\n\\nEdward H. White II – Second-seat \\n\\n\"Man on the Moon\" is a song by American alternative rock band R.E.M., released in November 1992 as the second single from their eighth album, Automatic for the People (1992). The lyrics were written by lead singer Michael Stipe, and the music by drummer Bill Berry and guitarist Peter Buck. The song was well received by critics and reached number 30 on the US Billboard Hot 100, number 17 on the US Cash Box Top 100, number 18 on the UK Singles Chart, and number one in Iceland. It remains one of R.E.M.\\'s most popular songs and was included on the compilations In Time: The Best of R.E.M. 1988–2003 and Part Lies, Part Heart, Part Truth, Part Garbage 1982–2011.\\n\"Man on the Moon\" is a tribute to comedian Andy Kaufman, with numerous references to his career including his Elvis impersonation, wrestling, and the film My Breakfast with Blassie. The song\\'s title and chorus refer to Moon landing conspiracy theories, as an oblique allusion to rumors that Kaufman\\'s death in 1984 was faked. The song gave its name to Miloš Forman\\'s Kaufman biopic Man on the Moon (1999), and features prominently in the film\\'s soundtrack.\\n\\n\\n== Composition ==\\n\"Man on the Moon\" is a mid-tempo country-rock song following a verse-chorus structure with an added pre-chorus and an instrumental bridge following the second and third choruses. The song has six lines in the first verse but only four in the second and third verses.An early instrumental demo of the song was known to the band as \"C to D Slide\". Guitarist Peter Buck has explained how the music came together: \"\\'Man on the Moon\\' was something that Bill [Berry] had, this one chord change that he came in with, which was C to D like the verse of the song, and he said: \\'I don\\'t know what to do with that.\\' I used to finish some of Bill\\'s things ... he would come up with the riffs, but I would be the finish guy for that. I sat down and came up with the chorus, the bridges, and so forth. I remember we showed it to Mike and Michael when they came in later; definitely we had the song finished. I think Bill played bass and I played guitar; we kept going around with it. I think we might have played some mandolin on it in the rehearsal studio.\"Michael Stipe explained in an interview with Charlie Rose how the lyric was written independently of the music, which had no prior association with the song\\'s eventual lyrical content regarding Kaufman. Stipe recounted the other R.E.M. members had written and performed the music of the song and recorded it along with the rest of the Automatic for the People album during studio sessions in Seattle. As of the final week of the recording sessions, Stipe was still struggling to write the lyric, and the others continued to plead with him to finish it. Stipe attempted to argue the track should be an instrumental, but his bandmates were insistent. Stipe listened to the track on a walk around Seattle on his Walkman cassette player and was inspired to write about Andy Kaufman. After Stipe went back to the studio to complete the vocal track, the track was mixed that night and sent out the following day to be mastered.\\n\\n\\n== Lyric ==\\nThe song\\'s lyric does not tell a conventional story and instead forms a collection of cultural references, images and ideas. There are repeated mentions of Andy Kaufman, including references to his Elvis impersonation and work with wrestlers Fred Blassie and Jerry Lawler. The song also invokes the conspiracy theories surrounding the Moon landing and Elvis Presley\\'s death as an indirect nod to the persistent rumors that Kaufman faked his own death. Speaking in 2017 to the NME, Mike Mills explained that the perceived ambiguity of Kaufman\\'s legacy, including questions of whether he was a comedian or a performance artist, and whether his work was funny or irritating, was a way to frame other questions about life within the song:\\n\\nHe\\'s the perfect ghost to lead you through this tour of questioning things. Did the moon landing really happen? Is Elvis really dead? He was ki<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>Reflection: I have found that the second person to walk on the moon was Edwin Aldrin. Now I will search for his mother\\'s hometown.\\nAction: ```json\\n[\\n {\\n \"tool_name\": \"wikipedia\",\\n \"parameters\": {\\n \"query\": \"Edwin Aldrin mother\\'s hometown\"\\n }\\n }\\n]\\n```\\n<|END_OF_TURN_TOKEN|>\\n<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>\\nDocument 1\\nBuzz Aldrin (; born Edwin Eugene Aldrin Jr.; January 20, 1930) is an American former astronaut, engineer and fighter pilot. He made three spacewalks as pilot of the 1966 Gemini 12 mission, and was the Lunar Module Eagle pilot on the 1969 Apollo 11 mission. He was the second person to walk on the Moon after mission commander Neil Armstrong.\\nBorn in Glen Ridge, New Jersey, Aldrin graduated third in the class of 1951 from the United States Military Academy at West Point with a degree in mechanical engineering. He was commissioned into the United States Air Force and served as a jet fighter pilot during the Korean War. He flew 66 combat missions and shot down two MiG-15 aircraft.\\nAfter earning a Doctor of Science degree in astronautics from the Massachusetts Institute of Technology (MIT), Aldrin was selected as a member of NASA\\'s Astronaut Group 3, making him the first astronaut with a doctoral degree. His doctoral thesis, Line-of-Sight Guidance Techniques for Manned Orbital Rendezvous, earned him the nickname \"Dr. Rendezvous\" from fellow astronauts. His first space flight was in 1966 on Gemini 12, during which he spent over five hours on extravehicular activity. Three years later, Aldrin set foot on the Moon at 03:15:16 on July 21, 1969 (UTC), nineteen minutes after Armstrong first touched the surface, while command module pilot Michael Collins remained in lunar orbit. A Presbyterian elder, Aldrin became the first person to hold a religious ceremony on the Moon when he privately took communion.\\nAfter leaving NASA in 1971, Aldrin became Commandant of the U.S. Air Force Test Pilot School. He retired from the Air Force in 1972 after 21 years of service. His autobiographies Return to Earth (1973) and Magnificent Desolation (2009) recount his struggles with clinical depression and alcoholism in the years after leaving NASA. Aldrin continues to advocate for space exploration, particularly a human mission to Mars. He developed the Aldrin cycler, a special spacecraft trajectory that makes travel to Mars more efficient in terms of time and propellant. He has been accorded numerous honors, including the Presidential Medal of Freedom in 1969.\\n\\n\\n== Early life and education ==\\nAldrin was born Edwin Eugene Aldrin Jr. on January 20, 1930, at Mountainside Hospital in Glen Ridge, New Jersey. His parents, Edwin Eugene Aldrin Sr. and Marion Aldrin (née Moon), lived in neighboring Montclair. His father was an Army aviator during World War I and the assistant commandant of the Army\\'s test pilot school at McCook Field, Ohio, from 1919 to 1922, but left the Army in 1928 and became an executive at Standard Oil. Aldrin had two sisters: Madeleine, who was four years older, and Fay Ann, who was a year and a half older. His nickname, which became his legal first name in 1988, arose as a result of Fay\\'s mispronouncing \"brother\" as \"buzzer\", which was then shortened to \"Buzz\". He was a Boy Scout, achieving the rank of Tenderfoot Scout.Aldrin did well in school, maintaining an A average. He played football and was the starting center for Montclair High School\\'s undefeated 1946 state champion team. His father wanted him to go to the United States Naval Academy in Annapolis, Maryland, and enrolled him at nearby Severn School, a preparatory school for Annapolis, and even secured him a Naval Academy appointment from Albert W. Hawkes, one of the United States senators from New Jersey. Aldrin attended Severn School in 1946, but had other ideas about his future career. He suffered from seasickness and considered ships a distraction from flying airplanes. He faced down his father and told him to ask Hawkes to change the nomination to the United States Military Academy at West Point, New York.Aldrin entered West Point in 1947. He did well academically, finishing first in his class his plebe (first) year. Aldrin was also an excellent athlete, competing in pole vault for the academy track and field team. In 1950, he traveled with a group of West Point cadets to Japan and\\n\\nFrancisco Sionil José (December 3, 1924 – January 6, 2022) was a Filipino writer who was one of the most widely read in the English language. A National Artist of the Philippines for Literature, which was bestowed upon him in 2001, José\\'s novels and short stories depict the social underpinnings of class struggles and colonialism in Filipino society. His works—written in English—have been translated into 28 languages, including Korean, Indonesian, Czech, Russian, Latvian, Ukrainian and Dutch. He was often considered the leading Filipino candidate for the Nobel Prize in Literature.\\n\\n\\n== Early life ==\\nJosé was born in Rosales, Pangasinan, the setting of many of his stories. He spent his childhood in Barrio Cabugawan, Rosales, where he first began to write. José is of Ilocano descent whose family had migrated to Pangasinan prior to his birth. Fleeing poverty, his forefathers traveled from Ilocos towards Cagayan Valley through the Santa Fe Trail. Like many migrant families, they brought their lifetime possessions with them, including uprooted molave posts of their old houses and their alsong, a stone mortar for pounding rice.One of the greatest influences to José was his industrious mother who went out of her way to get him the books he loved to read, while making sure her family did not go hungry despite poverty and landlessness. José started writing in grade school, at the time he started reading. In the fifth grade, one of José\\'s teachers opened the school library to her students, which is how José managed to read the novels of José Rizal, Willa Cather’s My Antonia, Faulkner and Steinbeck. Reading about Basilio and Crispin in Rizal\\'s Noli Me Tangere made the young José cry, because injustice was not an alien thing to him. When José was five years old, his grandfather who was a soldier during the Philippine revolution, had once tearfully showed him the land their family had once tilled but was taken away by rich mestizo landlords who knew how to work the system against illiterates like his grandfather.\\n\\n\\n== Writing career ==\\nJosé attended the University of Santo Tomas after World War II, but dropped out and plunged into writing and journalism in Manila. In subsequent years, he edited various literary and journalistic publications, started a publishing house, and founded the Philippine branch of PEN, an international organization for writers. José received numerous awards for his work. The Pretenders is his most popular novel, which is the story of one man\\'s alienation from his poor background and the decadence of his wife\\'s wealthy family.José Rizal\\'s life and writings profoundly influenced José\\'s work. The five volume Rosales Saga, in particular, employs and integrates themes and characters from Rizal\\'s work. Throughout his career, José\\'s writings espouse social justice and change to better the lives of average Filipino families. He is one of the most critically acclaimed Filipino authors internationally, although much underrated in his own country because of his authentic Filipino English and his anti-elite views.\\n\"Authors like myself choose the city as a setting for their fiction because the city itself illustrates the progress or the sophistication that a particular country has achieved. Or, on the other hand, it might also reflect the kind of decay, both social and perhaps moral, that has come upon a particular people.\"\\nSionil José also owned Solidaridad Bookshop, located on Padre Faura Street in Ermita, Manila. The bookshop offers mostly hard-to-find books and Filipiniana reading materials. It is said to be one of the favorite haunts of many local writers.In his regular column, Hindsight, in The Philippine STAR, dated September 12, 2011, he wrote \"Why we are shallow\", blaming the decline of Filipino intellectual and cultural standards on a variety of modern amenities, including media, the education system—particularly the loss of emphasis on classic literature and the study of Greek and Latin—and the abundance and imme\\n\\nMagpakailanman (English: Forevermore) is a weekly drama anthology broadcast by GMA Network. The show is hosted by 24 Oras anchor and GMA Kapuso Foundation founder Mel Tiangco and features inspiring stories and life experiences from both famous and ordinary people. It was aired every Monday until the end of 2004 and was moved to Thursday from 2005 on the network\\'s primetime block.\\nThe following are the lists of Magpakailanman episodes listed by the year they were aired, in the first incarnation that was aired from December 2, 2002, to December 27, 2007.\\n\\n\\n== Series overview ==\\n\\n\\n== Episode list ==\\n\\n\\n=== First incarnation ===\\n\\n\\n==== 2002 ====\\n\\n\\n==== 2003 ====\\n\\n\\n==== 2004 ====\\n\\n\\n==== 2005 ====\\n\\n\\n==== 2006 ====\\n\\n\\n==== 2007 ====\\n\\n\\n== References ==<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>\\n', 'chat_history': [], 'model': 'command-r', 'raw_prompting': True}\n", - "\u001b[32;1m\u001b[1;3mRelevant Documents: 1\n", - "Cited Documents: 1\n", - "Answer: MONTclair, NEW JERSEY, WAS THE HOMETOWN OF THE MOTHER OF THE SECOND MAN TO WALK ON THE MOON.\n", - "Grounded answer: Montclair, New Jersey, was the hometown of the mother of the second man to walk on the moon.\u001b[0m\n", + "Mari Aldon at IMDb\u001b[0m\u001b[32;1m\u001b[1;3mRelevant Documents: 0,2,6\n", + "Cited Documents: 2,6\n", + "Answer: THE MOTHER OF ALAN SHEPARD, THE SECOND MAN TO WALK ON THE MOON, WAS BORN IN FORT WORTH, TEXAS.\n", + "Grounded answer: THE MOTHER OF ALAN SHEPARD, THE SECOND MAN TO WALK ON THE MOON, WAS BORN IN FORT WORTH, TEXAS.\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n" ] @@ -254,10 +261,10 @@ "data": { "text/plain": [ "{'input': 'What was the hometown of the mother of the second person to walk on the moon?',\n", - " 'output': 'MONTclair, NEW JERSEY, WAS THE HOMETOWN OF THE MOTHER OF THE SECOND MAN TO WALK ON THE MOON.'}" + " 'output': 'THE MOTHER OF ALAN SHEPARD, THE SECOND MAN TO WALK ON THE MOON, WAS BORN IN FORT WORTH, TEXAS.'}" ] }, - "execution_count": 4, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -265,10 +272,10 @@ "source": [ "agent = create_cohere_multi_hop_agent(\n", " llm=chat,\n", - " tools=[retriever_tool, retriever_tool2],\n", + " tools=[retriever_tool],\n", " prompt=prompt,\n", ")\n", - "agent_executor = AgentExecutor(agent=agent, tools=[retriever_tool, retriever_tool2], verbose=True)\n", + "agent_executor = AgentExecutor(agent=agent, tools=[retriever_tool], verbose=True)\n", "agent_executor.invoke({\"input\": \"What was the hometown of the mother of the second person to walk on the moon?\"})" ] } From 685375538d5421acbc3ffa63ed212dee30ce5f11 Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:58:26 +0000 Subject: [PATCH 06/27] Lint --- .../cohere/langchain_cohere/multi_hop/agent.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/partners/cohere/langchain_cohere/multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/multi_hop/agent.py index f03b19facc71f..7cfa4b99b43f6 100644 --- a/libs/partners/cohere/langchain_cohere/multi_hop/agent.py +++ b/libs/partners/cohere/langchain_cohere/multi_hop/agent.py @@ -1,7 +1,7 @@ import json import logging import re -from typing import List, Sequence, Union +from typing import Dict, List, Sequence, Tuple, Union from langchain_core.agents import AgentAction, AgentFinish from langchain_core.language_models import BaseLanguageModel @@ -56,7 +56,7 @@ def _type(self) -> str: def parse_jsonified_tool_use_generation( self, tool_use_generation: str, tool_use_prefix: str - ) -> List[dict]: + ) -> List[Dict]: """Parses model-generated jsonified actions. Expects input of the form @@ -85,15 +85,15 @@ def _extract_codeblocks_from_md(text: str) -> List[str]: if len(actions): if any( - not isinstance(action, dict) or "tool_name" not in action + not isinstance(action, Dict) or "tool_name" not in action for action in actions ): raise ValueError(f"Action Parsing Failed: {tool_use_generation}") return actions def parse_answer_with_prefixes( - self, completion: str, prefixes: dict[str, str] - ) -> dict[str, str]: + self, completion: str, prefixes: Dict[str, str] + ) -> Dict[str, str]: """parses string into key-value pairs, according to patterns supplied in prefixes. Also strips. @@ -126,7 +126,7 @@ def parse_answer_with_prefixes( parsed[reverse_prefix_map[prefix]] = value.strip() return parsed - def parse_actions(self, generation: str) -> tuple[str, str, List[dict]]: + def parse_actions(self, generation: str) -> Tuple[str, str, List[Dict]]: """Parse action selections from model output.""" plan = "" actions = generation @@ -253,7 +253,7 @@ def calculator_calc(expression: str) -> List[Dict]: def format_cohere_log_to_str( - intermediate_steps: List[tuple[AgentAction, str]], + intermediate_steps: List[Tuple[AgentAction, str]], observation_prefix: str = "<|END_OF_TURN_TOKEN|>\n<|START_OF_TURN_TOKEN|>" + "<|SYSTEM_TOKEN|>\n", llm_prefix: str = "<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|>" From bb4762dff35cad901cdd7290019ec40d809d6cd8 Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:37:44 +0000 Subject: [PATCH 07/27] Spelling --- libs/partners/cohere/langchain_cohere/multi_hop/agent.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/partners/cohere/langchain_cohere/multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/multi_hop/agent.py index 7cfa4b99b43f6..9a8deeefa2dc4 100644 --- a/libs/partners/cohere/langchain_cohere/multi_hop/agent.py +++ b/libs/partners/cohere/langchain_cohere/multi_hop/agent.py @@ -115,10 +115,10 @@ def parse_answer_with_prefixes( # sort out prefixes re_pat = "(" + "|".join([re.escape(p) for p in prefixes.values()]) + ")" reverse_prefix_map = {v: k for k, v in prefixes.items()} - splitted = re.split(re_pat, completion) - splitted = splitted[1:] + split = re.split(re_pat, completion) + split = split[1:] parsed = {} - for prefix, value in zip(splitted[::2], splitted[1::2]): + for prefix, value in zip(split[::2], split[1::2]): if prefix in reverse_prefix_map: # if the prefix is a match if ( reverse_prefix_map[prefix] not in parsed From 768dd37389c6c3cc0a24851076915cd2f46987ee Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:44:10 +0000 Subject: [PATCH 08/27] Fix test --- libs/partners/cohere/tests/unit_tests/test_imports.py | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/partners/cohere/tests/unit_tests/test_imports.py b/libs/partners/cohere/tests/unit_tests/test_imports.py index ceff62f104e92..543a8ce52615f 100644 --- a/libs/partners/cohere/tests/unit_tests/test_imports.py +++ b/libs/partners/cohere/tests/unit_tests/test_imports.py @@ -6,6 +6,7 @@ "CohereEmbeddings", "CohereRagRetriever", "CohereRerank", + "create_cohere_multi_hop_agent", ] From a549a112ff48449f628fcd4aee57cac2e25902d0 Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:07:25 +0000 Subject: [PATCH 09/27] Add chat history --- .../cohere/langchain_cohere/cohere_agent.py | 4 +- .../langchain_cohere/multi_hop/agent.py | 46 ++++++++++++++----- .../langchain_cohere/multi_hop/prompt.py | 4 +- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/libs/partners/cohere/langchain_cohere/cohere_agent.py b/libs/partners/cohere/langchain_cohere/cohere_agent.py index 5bf8328e8c6f2..c9c3fa9808f08 100644 --- a/libs/partners/cohere/langchain_cohere/cohere_agent.py +++ b/libs/partners/cohere/langchain_cohere/cohere_agent.py @@ -83,7 +83,9 @@ def _convert_to_cohere_tool( description=tool.description, parameter_definitions={ param_name: ToolParameterDefinitionsValue( - description=param_definition.get("description"), + description=param_definition.get("description") + if "description" in param_definition + else "", type=param_definition.get("type"), required="default" not in param_definition, ) diff --git a/libs/partners/cohere/langchain_cohere/multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/multi_hop/agent.py index 9a8deeefa2dc4..67e49dc037b1f 100644 --- a/libs/partners/cohere/langchain_cohere/multi_hop/agent.py +++ b/libs/partners/cohere/langchain_cohere/multi_hop/agent.py @@ -5,7 +5,11 @@ from langchain_core.agents import AgentAction, AgentFinish from langchain_core.language_models import BaseLanguageModel +from langchain_core.messages.ai import AIMessage +from langchain_core.messages.base import BaseMessage +from langchain_core.messages.system import SystemMessage from langchain_core.output_parsers import BaseOutputParser +from langchain_core.prompts.base import BasePromptTemplate from langchain_core.prompts.chat import ChatPromptTemplate from langchain_core.runnables import Runnable, RunnablePassthrough from langchain_core.tools import BaseTool @@ -24,22 +28,21 @@ def create_cohere_multi_hop_agent( tools: Sequence[BaseTool], prompt: ChatPromptTemplate, ) -> Runnable: - multi_hop_prompt = multi_hop_prompt_template.partial( - tools="\n".join([render_tool_description(t) for t in tools]), - ) - llm_with_tools = llm.bind(stop=["\nObservation:"], raw_prompting=True) + def multi_hop_prompt(x: Dict) -> BasePromptTemplate: + return multi_hop_prompt_template.partial( + tools="\n".join([render_tool_description(t) for t in tools]), + input=prompt.invoke(x).to_string(), + steps=format_cohere_log_to_str(x["intermediate_steps"]), + history=render_chat_history(x.get("chat_history", [])), + ) agent = ( RunnablePassthrough.assign( - agent_scratchpad=lambda x: format_cohere_log_to_str( - x["intermediate_steps"], - ), - input=lambda x: prompt.format( - input=x["input"], agent_scratchpad=x["intermediate_steps"] - ), + # Handled in the multi_hop_prompt + agent_scratchpad=lambda _: [], ) | multi_hop_prompt - | llm_with_tools + | llm.bind(stop=["\nObservation:"], raw_prompting=True) | CohereToolsMultiHopAgentOutputParser() ) return agent @@ -177,7 +180,7 @@ def parse(self, text: str) -> Union[List[AgentAction], AgentFinish]: elif any([x in text for x in ["Plan: ", "Reflection: ", "Action: "]]): completion, plan, actions = self.parse_actions(text) return [ - AgentAction(action["tool_name"], action["parameters"]["query"], text) + AgentAction(action["tool_name"], action["parameters"], text) for action in actions ] else: @@ -220,6 +223,25 @@ def get_tool_args(tool: BaseTool) -> str: return "\n ".join(rendered_args) +def render_chat_history(chat_history: List[BaseMessage]) -> str: + """Render chat history.""" + return "".join( + [ + f"<|START_OF_TURN_TOKEN|>{get_role(message)}{message.content}<|END_OF_TURN_TOKEN|>" + for message in chat_history + ] + ) + + +def get_role(message: BaseMessage) -> str: + if isinstance(message, AIMessage): + return "<|CHATBOT_TOKEN|>" + elif isinstance(message, SystemMessage): + return "<|SYSTEM_TOKEN|>" + else: + return "<|USER_TOKEN|>" + + def render_tool_description(tool: BaseTool) -> str: """Render the tool name and description. diff --git a/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py b/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py index 7b45c6756fbb5..6bea1f30d7507 100644 --- a/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py +++ b/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py @@ -69,8 +69,8 @@ def render_structured_preamble( ### Available Tools Here is a list of tools that you have available to you: -{tools}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>{input}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{multi_hop_instruction}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|> -{agent_scratchpad} +{tools}<|END_OF_TURN_TOKEN|>{history}<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{input}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{multi_hop_instruction}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|> +{steps} """ ).partial( multi_hop_instruction=multi_hop_instruction, From 068549b7905b462c8570e6f0b57ce2fbe23bb6fa Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:21:38 +0000 Subject: [PATCH 10/27] Fix prompt --- libs/partners/cohere/langchain_cohere/multi_hop/agent.py | 2 +- libs/partners/cohere/langchain_cohere/multi_hop/prompt.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/partners/cohere/langchain_cohere/multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/multi_hop/agent.py index 67e49dc037b1f..acd0cff3faa0f 100644 --- a/libs/partners/cohere/langchain_cohere/multi_hop/agent.py +++ b/libs/partners/cohere/langchain_cohere/multi_hop/agent.py @@ -31,7 +31,7 @@ def create_cohere_multi_hop_agent( def multi_hop_prompt(x: Dict) -> BasePromptTemplate: return multi_hop_prompt_template.partial( tools="\n".join([render_tool_description(t) for t in tools]), - input=prompt.invoke(x).to_string(), + user_prompt=prompt.invoke(x).to_string(), steps=format_cohere_log_to_str(x["intermediate_steps"]), history=render_chat_history(x.get("chat_history", [])), ) diff --git a/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py b/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py index 6bea1f30d7507..a6ed9c8b7acab 100644 --- a/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py +++ b/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py @@ -69,7 +69,7 @@ def render_structured_preamble( ### Available Tools Here is a list of tools that you have available to you: -{tools}<|END_OF_TURN_TOKEN|>{history}<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{input}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{multi_hop_instruction}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|> +{tools}<|END_OF_TURN_TOKEN|>{history}<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{user_prompt}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{multi_hop_instruction}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|> {steps} """ ).partial( From 4bde450ad3511b633af998847c34f57c322f4a77 Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Thu, 28 Mar 2024 11:54:49 -0700 Subject: [PATCH 11/27] Update libs/partners/cohere/langchain_cohere/multi_hop/agent.py --- libs/partners/cohere/langchain_cohere/multi_hop/agent.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libs/partners/cohere/langchain_cohere/multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/multi_hop/agent.py index acd0cff3faa0f..449e45dede178 100644 --- a/libs/partners/cohere/langchain_cohere/multi_hop/agent.py +++ b/libs/partners/cohere/langchain_cohere/multi_hop/agent.py @@ -53,10 +53,6 @@ class CohereToolsMultiHopAgentOutputParser( ): """Parses a message into agent actions/finish.""" - @property - def _type(self) -> str: - return "cohere-tools-agent-output-parser" - def parse_jsonified_tool_use_generation( self, tool_use_generation: str, tool_use_prefix: str ) -> List[Dict]: From fc983168383c5c5d87ad9d763d643ec98d23be7f Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Thu, 28 Mar 2024 19:08:13 +0000 Subject: [PATCH 12/27] Remove new lines --- libs/partners/cohere/langchain_cohere/multi_hop/prompt.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py b/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py index a6ed9c8b7acab..4d88b28c3ed2d 100644 --- a/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py +++ b/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py @@ -69,9 +69,7 @@ def render_structured_preamble( ### Available Tools Here is a list of tools that you have available to you: -{tools}<|END_OF_TURN_TOKEN|>{history}<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{user_prompt}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{multi_hop_instruction}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|> -{steps} -""" +{tools}<|END_OF_TURN_TOKEN|>{history}<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{user_prompt}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{multi_hop_instruction}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>{steps}""" ).partial( multi_hop_instruction=multi_hop_instruction, structured_preamble=rendered_structured_preamble, From 74b55e3818f436bd9c82678659d3acb949190713 Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Thu, 28 Mar 2024 21:32:27 +0000 Subject: [PATCH 13/27] Update the naming and notebook --- .../cohere/docs/multi_hop_agent.ipynb | 124 ++++++++++-------- .../cohere/langchain_cohere/__init__.py | 4 +- .../__init__.py | 0 .../{multi_hop => react_multi_hop}/agent.py | 8 +- .../{multi_hop => react_multi_hop}/prompt.py | 0 5 files changed, 75 insertions(+), 61 deletions(-) rename libs/partners/cohere/langchain_cohere/{multi_hop => react_multi_hop}/__init__.py (100%) rename libs/partners/cohere/langchain_cohere/{multi_hop => react_multi_hop}/agent.py (98%) rename libs/partners/cohere/langchain_cohere/{multi_hop => react_multi_hop}/prompt.py (100%) diff --git a/libs/partners/cohere/docs/multi_hop_agent.ipynb b/libs/partners/cohere/docs/multi_hop_agent.ipynb index 2181586494fbf..1ee6806496821 100644 --- a/libs/partners/cohere/docs/multi_hop_agent.ipynb +++ b/libs/partners/cohere/docs/multi_hop_agent.ipynb @@ -44,7 +44,7 @@ "source": [ "from langchain.agents import AgentExecutor\n", "from langchain_cohere.chat_models import ChatCohere\n", - "from langchain_cohere.multi_hop.agent import create_cohere_multi_hop_agent\n", + "from langchain_cohere.react_multi_hop.agent import create_cohere_react_agent\n", "from langchain.retrievers import WikipediaRetriever\n", "from langchain.tools.retriever import create_retriever_tool\n", "from langchain_core.prompts import ChatPromptTemplate" @@ -112,7 +112,7 @@ "\n", "\n", "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", - "\u001b[32;1m\u001b[1;3mPlan: First I will search for who the second person to walk on the moon was, then I will search for that person's mother's hometown and write the answer in capitals.\n", + "\u001b[32;1m\u001b[1;3mPlan: First I will search for who the second person to walk on the moon was. Then I will search for that person's mother's hometown and write the answer in capital letters.\n", "Action: ```json\n", "[\n", " {\n", @@ -142,19 +142,6 @@ "\n", "The band's self-titled major label debut Walk t\n", "\n", - "\"Man on the Moon\" is a song by American alternative rock band R.E.M., released in November 1992 as the second single from their eighth album, Automatic for the People (1992). The lyrics were written by lead singer Michael Stipe, and the music by drummer Bill Berry and guitarist Peter Buck. The song was well received by critics and reached number 30 on the US Billboard Hot 100, number 17 on the US Cash Box Top 100, number 18 on the UK Singles Chart, and number one in Iceland. It remains one of R.E.M.'s most popular songs and was included on the compilations In Time: The Best of R.E.M. 1988–2003 and Part Lies, Part Heart, Part Truth, Part Garbage 1982–2011.\n", - "\"Man on the Moon\" is a tribute to comedian Andy Kaufman, with numerous references to his career including his Elvis impersonation, wrestling, and the film My Breakfast with Blassie. The song's title and chorus refer to Moon landing conspiracy theories, as an oblique allusion to rumors that Kaufman's death in 1984 was faked. The song gave its name to Miloš Forman's Kaufman biopic Man on the Moon (1999), and features prominently in the film's soundtrack.\n", - "\n", - "\n", - "== Composition ==\n", - "\"Man on the Moon\" is a mid-tempo country-rock song following a verse-chorus structure with an added pre-chorus and an instrumental bridge following the second and third choruses. The song has six lines in the first verse but only four in the second and third verses.An early instrumental demo of the song was known to the band as \"C to D Slide\". Guitarist Peter Buck has explained how the music came together: \"'Man on the Moon' was something that Bill [Berry] had, this one chord change that he came in with, which was C to D like the verse of the song, and he said: 'I don't know what to do with that.' I used to finish some of Bill's things ... he would come up with the riffs, but I would be the finish guy for that. I sat down and came up with the chorus, the bridges, and so forth. I remember we showed it to Mike and Michael when they came in later; definitely we had the song finished. I think Bill played bass and I played guitar; we kept going around with it. I think we might have played some mandolin on it in the rehearsal studio.\"Michael Stipe explained in an interview with Charlie Rose how the lyric was written independently of the music, which had no prior association with the song's eventual lyrical content regarding Kaufman. Stipe recounted the other R.E.M. members had written and performed the music of the song and recorded it along with the rest of the Automatic for the People album during studio sessions in Seattle. As of the final week of the recording sessions, Stipe was still struggling to write the lyric, and the others continued to plead with him to finish it. Stipe attempted to argue the track should be an instrumental, but his bandmates were insistent. Stipe listened to the track on a walk around Seattle on his Walkman cassette player and was inspired to write about Andy Kaufman. After Stipe went back to the studio to complete the vocal track, the track was mixed that night and sent out the following day to be mastered.\n", - "\n", - "\n", - "== Lyric ==\n", - "The song's lyric does not tell a conventional story and instead forms a collection of cultural references, images and ideas. There are repeated mentions of Andy Kaufman, including references to his Elvis impersonation and work with wrestlers Fred Blassie and Jerry Lawler. The song also invokes the conspiracy theories surrounding the Moon landing and Elvis Presley's death as an indirect nod to the persistent rumors that Kaufman faked his own death. Speaking in 2017 to the NME, Mike Mills explained that the perceived ambiguity of Kaufman's legacy, including questions of whether he was a comedian or a performance artist, and whether his work was funny or irritating, was a way to frame other questions about life within the song:\n", - "\n", - "He's the perfect ghost to lead you through this tour of questioning things. Did the moon landing really happen? Is Elvis really dead? He was ki\n", - "\n", "As part of the Apollo program by NASA, 24 astronauts flew nine missions to the Moon between December 1968 and December 1972. During six successful two-man landing missions, twelve men walked on the lunar surface, six of whom drove Lunar Roving Vehicles as part of the last three missions. Three men have been to the Moon twice, one orbited once and took a circumlunar trajectory the second time, while the other two landed once apiece. Apart from these 24 men, no human being has gone beyond low Earth orbit. No woman has been to the Moon, but a number of non-human animals have circled or orbited it, including two tortoises, several turtles, and five mice.\n", "Apollo missions 8 and 10–17 were the nine crewed missions to the Moon. Apollo 4–6 and AS-201 and AS-202 were uncrewed, while AS-203 is considered a test flight. The Apollo program included three other crewed missions: Apollo 1 (AS-204) did not launch and its crew died in a ground-based capsule fire, while Apollo 7 and Apollo 9 were low Earth orbit missions that only tested spacecraft components and docking maneuvers. Apollo missions 18, 19, and 20 were canceled. Twelve astronauts later flew unused Apollo command modules in the Apollo Applications Program's Skylab and Apollo–Soyuz Test Project. Of the 24 astronauts who flew to the Moon, two went on to command a Skylab mission, one commanded Apollo–Soyuz, one flew as commander for Approach and Landing Tests of the Space Shuttle, and two commanded orbital Space Shuttle missions.\n", "\n", @@ -177,82 +164,109 @@ "\n", "All of these astronauts flew on Gemini, and except for White, each commanded one Gemini and one Apollo mission:\n", "\n", - "Edward H. White II – Second-seat \u001b[0m\u001b[32;1m\u001b[1;3mReflection: I have found that the second person to walk on the moon was Alan Shepard. Now I will search for Alan Shepard's mother's hometown and write the answer.\n", + "Edward H. White II – Second-seat \n", + "\n", + "\"Man on the Moon\" is a song by American alternative rock band R.E.M., released in November 1992 as the second single from their eighth album, Automatic for the People (1992). The lyrics were written by lead singer Michael Stipe, and the music by drummer Bill Berry and guitarist Peter Buck. The song was well received by critics and reached number 30 on the US Billboard Hot 100, number 17 on the US Cash Box Top 100, number 18 on the UK Singles Chart, and number one in Iceland. It remains one of R.E.M.'s most popular songs and was included on the compilations In Time: The Best of R.E.M. 1988–2003 and Part Lies, Part Heart, Part Truth, Part Garbage 1982–2011.\n", + "\"Man on the Moon\" is a tribute to comedian Andy Kaufman, with numerous references to his career including his Elvis impersonation, wrestling, and the film My Breakfast with Blassie. The song's title and chorus refer to Moon landing conspiracy theories, as an oblique allusion to rumors that Kaufman's death in 1984 was faked. The song gave its name to Miloš Forman's Kaufman biopic Man on the Moon (1999), and features prominently in the film's soundtrack.\n", + "\n", + "\n", + "== Composition ==\n", + "\"Man on the Moon\" is a mid-tempo country-rock song following a verse-chorus structure with an added pre-chorus and an instrumental bridge following the second and third choruses. The song has six lines in the first verse but only four in the second and third verses.An early instrumental demo of the song was known to the band as \"C to D Slide\". Guitarist Peter Buck has explained how the music came together: \"'Man on the Moon' was something that Bill [Berry] had, this one chord change that he came in with, which was C to D like the verse of the song, and he said: 'I don't know what to do with that.' I used to finish some of Bill's things ... he would come up with the riffs, but I would be the finish guy for that. I sat down and came up with the chorus, the bridges, and so forth. I remember we showed it to Mike and Michael when they came in later; definitely we had the song finished. I think Bill played bass and I played guitar; we kept going around with it. I think we might have played some mandolin on it in the rehearsal studio.\"Michael Stipe explained in an interview with Charlie Rose how the lyric was written independently of the music, which had no prior association with the song's eventual lyrical content regarding Kaufman. Stipe recounted the other R.E.M. members had written and performed the music of the song and recorded it along with the rest of the Automatic for the People album during studio sessions in Seattle. As of the final week of the recording sessions, Stipe was still struggling to write the lyric, and the others continued to plead with him to finish it. Stipe attempted to argue the track should be an instrumental, but his bandmates were insistent. Stipe listened to the track on a walk around Seattle on his Walkman cassette player and was inspired to write about Andy Kaufman. After Stipe went back to the studio to complete the vocal track, the track was mixed that night and sent out the following day to be mastered.\n", + "\n", + "\n", + "== Lyric ==\n", + "The song's lyric does not tell a conventional story and instead forms a collection of cultural references, images and ideas. There are repeated mentions of Andy Kaufman, including references to his Elvis impersonation and work with wrestlers Fred Blassie and Jerry Lawler. The song also invokes the conspiracy theories surrounding the Moon landing and Elvis Presley's death as an indirect nod to the persistent rumors that Kaufman faked his own death. Speaking in 2017 to the NME, Mike Mills explained that the perceived ambiguity of Kaufman's legacy, including questions of whether he was a comedian or a performance artist, and whether his work was funny or irritating, was a way to frame other questions about life within the song:\n", + "\n", + "He's the perfect ghost to lead you through this tour of questioning things. Did the moon landing really happen? Is Elvis really dead? He was ki\u001b[0m\u001b[32;1m\u001b[1;3mReflection: I have found that the second person to walk on the moon was Buzz Aldrin. Now I will search for the hometown of his mother and write the answer in capital letters.\n", "Action: ```json\n", "[\n", " {\n", " \"tool_name\": \"wikipedia\",\n", " \"parameters\": {\n", - " \"query\": \"Alan Shepard mother's hometown\"\n", + " \"query\": \"Buzz Aldrin mother's hometown\"\n", " }\n", " }\n", "]\n", - "```\u001b[0m\u001b[36;1m\u001b[1;3mAlan Eugene Jackson (born October 17, 1958) is an American singer-songwriter. He is known for performing a style widely regarded as \"neotraditional country\", as well as penning many of his own songs. Jackson has recorded 21 studio albums, including two Christmas albums, and two gospel albums, as well as released three greatest-hits albums.\n", - "Jackson is one of the best-selling music artists of all time, having sold over 75 million records worldwide, with 44 million sold in the United States alone. He has had 66 songs appear on the Billboard Hot Country Singles & Tracks chart; of the 66 titles, and six featured singles, 38 have reached the top five and 35 have claimed the number one spot. Out of 15 titles to reach the Billboard Top Country Albums chart, nine have been certified multi-platinum. He is the recipient of two Grammy Awards, 16 CMA Awards, 17 ACM Awards and nominee of multiple other awards. He is a member of the Grand Ole Opry, and was inducted into the Georgia Music Hall of Fame in 2001. He was inducted into the Country Music Hall of Fame in 2017 by Loretta Lynn and into the Nashville Songwriters Hall of Fame in 2018.\n", - "\n", + "```\u001b[0m\u001b[36;1m\u001b[1;3mBuzz Aldrin (; born Edwin Eugene Aldrin Jr.; January 20, 1930) is an American former astronaut, engineer and fighter pilot. He made three spacewalks as pilot of the 1966 Gemini 12 mission, and was the Lunar Module Eagle pilot on the 1969 Apollo 11 mission. He was the second person to walk on the Moon after mission commander Neil Armstrong.\n", + "Born in Glen Ridge, New Jersey, Aldrin graduated third in the class of 1951 from the United States Military Academy at West Point with a degree in mechanical engineering. He was commissioned into the United States Air Force and served as a jet fighter pilot during the Korean War. He flew 66 combat missions and shot down two MiG-15 aircraft.\n", + "After earning a Doctor of Science degree in astronautics from the Massachusetts Institute of Technology (MIT), Aldrin was selected as a member of NASA's Astronaut Group 3, making him the first astronaut with a doctoral degree. His doctoral thesis, Line-of-Sight Guidance Techniques for Manned Orbital Rendezvous, earned him the nickname \"Dr. Rendezvous\" from fellow astronauts. His first space flight was in 1966 on Gemini 12, during which he spent over five hours on extravehicular activity. Three years later, Aldrin set foot on the Moon at 03:15:16 on July 21, 1969 (UTC), nineteen minutes after Armstrong first touched the surface, while command module pilot Michael Collins remained in lunar orbit. A Presbyterian elder, Aldrin became the first person to hold a religious ceremony on the Moon when he privately took communion.\n", + "After leaving NASA in 1971, Aldrin became Commandant of the U.S. Air Force Test Pilot School. He retired from the Air Force in 1972 after 21 years of service. His autobiographies Return to Earth (1973) and Magnificent Desolation (2009) recount his struggles with clinical depression and alcoholism in the years after leaving NASA. Aldrin continues to advocate for space exploration, particularly a human mission to Mars. He developed the Aldrin cycler, a special spacecraft trajectory that makes travel to Mars more efficient in terms of time and propellant. He has been accorded numerous honors, including the Presidential Medal of Freedom in 1969.\n", "\n", - "== Early life ==\n", - "Jackson was born to Joseph Eugene \"Daddy Gene\" Jackson (1927–2000) and Ruth Musick \"Mama Ruth\" Jackson (1930–2017) in Newnan, Georgia, and has four older sisters. He and his immediate family lived in a small home built around his grandfather's old toolshed. The family is primarily of English descent. His mother lived in the home until her death on January 7, 2017. He began writing music in 1983.Growing up, Jackson listened primarily to gospel music, until a friend introduced him to Gene Watson, John Anderson, and Hank Williams Jr. Jackson attended the local Elm Street Elementary and Newnan High School, and joined the band Dixie Steel after graduation. When he was 27, Jackson and his wife of six years, Denise, moved from Newnan to Nashville, Tennessee, where he hoped to pursue music full-time. In 1987, Jackson cut a pre-debut demo album titled New Traditional at Doc's Place in Hendersonville, Tennessee, but it is extremely rare and was released only in Japan.\n", "\n", + "== Early life and education ==\n", + "Aldrin was born Edwin Eugene Aldrin Jr. on January 20, 1930, at Mountainside Hospital in Glen Ridge, New Jersey. His parents, Edwin Eugene Aldrin Sr. and Marion Aldrin (née Moon), lived in neighboring Montclair. His father was an Army aviator during World War I and the assistant commandant of the Army's test pilot school at McCook Field, Ohio, from 1919 to 1922, but left the Army in 1928 and became an executive at Standard Oil. Aldrin had two sisters: Madeleine, who was four years older, and Fay Ann, who was a year and a half older. His nickname, which became his legal first name in 1988, arose as a result of Fay's mispronouncing \"brother\" as \"buzzer\", which was then shortened to \"Buzz\". He was a Boy Scout, achieving the rank of Tenderfoot Scout.Aldrin did well in school, maintaining an A average. He played football and was the starting center for Montclair High School's undefeated 1946 state champion team. His father wanted him to go to the United States Naval Academy in Annapolis, Maryland, and enrolled him at nearby Severn School, a preparatory school for Annapolis, and even secured him a Naval Academy appointment from Albert W. Hawkes, one of the United States senators from New Jersey. Aldrin attended Severn School in 1946, but had other ideas about his future career. He suffered from seasickness and considered ships a distraction from flying airplanes. He faced down his father and told him to ask Hawkes to change the nomination to the United States Military Academy at West Point, New York.Aldrin entered West Point in 1947. He did well academically, finishing first in his class his plebe (first) year. Aldrin was also an excellent athlete, competing in pole vault for the academy track and field team. In 1950, he traveled with a group of West Point cadets to Japan and\n", "\n", - "== Career ==\n", - "In Tennessee, Jackson got his first job in The Nashville Network's mailroom. His wife Denise was a flight attendant. While working, she came in contact with Glen Campbell and requested advice for her husband. Campbell handed her his business card of his manager and told her to call, which helped jumpstart his career. Jackson eventually signed with Arista, and in 1989, he became the first artist signed to the newly formed Arista Nashville branch of Arista Records. Arista released Jackson's debut single, \"Blue Blooded Woman\", in late 1989. Although the song failed to reach top 40 on Hot Country Songs, he reached number three by early 1990 with \"Here in the Real World\". This song served as the title track to his debut studio album, Here in the Real World, which also included two more top five hits (\"Wanted\" and \"Chasin' That Neon Rainbow\") and his first number one, \"I'd Love You All Over Again\". Don't Rock the Jukebox was the title of Jackson's second album. Released in 1991, it included four number-one singles: the title track, \"Someday\", \"Dallas\" and \"Love's Got a Hold on You\", and the number three \"Midnight in Montgomery\". Jackson also co-wrote several songs on Randy Travis' 1991 album High Lonesome.A Lot About Livin' (And a Little 'bout Love), his third album, accounted for the number one hits \"She's Got the Rhythm (And I Got the Blues)\" (which Randy Travis co-wrote) and \"Chattahoochee\", plus the top five hits \"Tonight I Climbed the Wall\", \"Mercury Blues\" and \"(Who Says) You Can't Have It All\". \"Chattahoochee\" also won him the 1994 Country Music Association (CMA) awards for Single and Song of the Year. In 1994, Jackson left his management company, Ten Ten Management, which had overseen his career up to that point, and switched to Gary Overton. His fourth album was titled Who I Am, and it contained four number one hit\n", + "Neil Alden Armstrong (August 5, 1930 – August 25, 2012) was an American astronaut and aeronautical engineer who in 1969 became the first person to walk on the Moon. He was also a naval aviator, test pilot, and university professor.\n", + "Armstrong was born and raised in Wapakoneta, Ohio. He entered Purdue University, studying aeronautical engineering, with the U.S. Navy paying his tuition under the Holloway Plan. He became a midshipman in 1949 and a naval aviator the following year. He saw action in the Korean War, flying the Grumman F9F Panther from the aircraft carrier USS Essex. After the war, he completed his bachelor's degree at Purdue and became a test pilot at the National Advisory Committee for Aeronautics (NACA) High-Speed Flight Station at Edwards Air Force Base in California. He was the project pilot on Century Series fighters and flew the North American X-15 seven times. He was also a participant in the U.S. Air Force's Man in Space Soonest and X-20 Dyna-Soar human spaceflight programs.\n", + "Armstrong joined the NASA Astronaut Corps in the second group, which was selected in 1962. He made his first spaceflight as command pilot of Gemini 8 in March 1966, becoming NASA's first civilian astronaut to fly in space. During this mission with pilot David Scott, he performed the first docking of two spacecraft; the mission was aborted after Armstrong used some of his re-entry control fuel to stabilize a dangerous roll caused by a stuck thruster. During training for Armstrong's second and last spaceflight as commander of Apollo 11, he had to eject from the Lunar Landing Research Vehicle moments before a crash.\n", + "On July 20, 1969, Armstrong and Apollo 11 Lunar Module (LM) pilot Buzz Aldrin became the first people to land on the Moon, and the next day they spent two and a half hours outside the Lunar Module Eagle spacecraft while Michael Collins remained in lunar orbit in the Apollo Command Module Columbia. When Armstrong first stepped onto the lunar surface, he famously said: \"That's one small step for [a] man, one giant leap for mankind.\" It was broadcast live to an estimated 530 million viewers worldwide. Apollo 11 was a major U.S. victory in the Space Race, by fulfilling a national goal proposed in 1961 by President John F. Kennedy \"of landing a man on the Moon and returning him safely to the Earth\" before the end of the decade. Along with Collins and Aldrin, Armstrong was awarded the Presidential Medal of Freedom by President Richard Nixon and received the 1969 Collier Trophy. President Jimmy Carter presented him with the Congressional Space Medal of Honor in 1978, he was inducted into the National Aviation Hall of Fame in 1979, and with his former crewmates received the Congressional Gold Medal in 2009.\n", + "After he resigned from NASA in 1971, Armstrong taught in the Department of Aerospace Engineering at the University of Cincinnati until 1979. He served on the Apollo 13 accident investigation and on the Rogers Commission, which investigated the Space Shuttle Challenger disaster. In 2012, Armstrong died due to complications resulting from coronary bypass surgery, at the age of 82.\n", "\n", - "Alan LaVern Bean (March 15, 1932 – May 26, 2018) was an American naval officer and aviator, aeronautical engineer, test pilot, NASA astronaut and painter. He was selected to become an astronaut by NASA in 1963 as part of Astronaut Group 3, and was the fourth person to walk on the Moon.\n", - "Before becoming an astronaut, Bean graduated with a Bachelor of Science degree in Aeronautical Engineering from University of Texas at Austin in 1955 and re-joined the U.S. Navy—he served as an enlisted member for a year after his high school graduation. He received his naval aviator wings in 1956 and served as a fighter pilot. In 1960, he graduated from the U.S. Naval Test Pilot School, flew as a test pilot and was The New Nine selection finalist in 1962.\n", - "He made his first flight into space aboard Apollo 12, the second crewed mission to land on the Moon, at age 37 in November 1969. He made his second and final flight into space on the Skylab 3 mission in 1973, the second crewed mission to the Skylab space station. After retiring from the United States Navy in 1975 and NASA in 1981, he pursued his interest in painting, depicting various space-related scenes and documenting his own experiences in space as well as those of his fellow Apollo program astronauts. He was the last living crew member of Apollo 12.\n", "\n", + "== Early life ==\n", + "Armstrong was born near Wapakoneta, Ohio, on August 5, 1930, the son of Viola Louise (née Engel) and Stephen Koenig Armstrong. He was of German, English, Scots-Irish, and Scottish descent. He is a descendant of Clan Armstrong. He had a younger sister, June, and a younger brother, Dean. His father was an auditor for the Ohio state government, and the family moved around the state repeatedly, living in 16 towns over the next 14 years. Armstrong's love for flying grew during this time, having started at the age of two when his father took him to the Cleveland Air Races. When he was five or six, he experienced his first airplane flight in Warren, Ohio, when he and his father took a ride in a Ford Trimotor (also known as the \"Tin Goose\").The family's last move was in 1944 and took them back to Wapakoneta, where Armstrong attended Blume High Scho\n", "\n", - "== Biography ==\n", + "David Kaufman (born July 23, 1961) is an American actor. He is best known for his voice roles of Dexter Douglas in Freakazoid!, Jimmy Olsen in various DC projects beginning with Superman: The Animated Series, the titular protagonist in Danny Phantom, Aldrin in The Buzz on Maggie, Marty McFly in Back to the Future, and Stuart Little in the animated series of the same name. He often is a voice double for Michael J. Fox.\n", "\n", "\n", - "=== Early life and education ===\n", - "Bean was born March 15, 1932, in Wheeler, the seat of Wheeler County in the northeastern Texas Panhandle, to parents Arnold Horace Bean and Frances Caroline Bean (née Murphy), who lived from 1908 to 1983, and 1906 to 1981, respectively. He considered Fort Worth his hometown. He was of Scottish descent. As a boy, he lived in Minden, the seat of Webster Parish in northwestern Louisiana, where his father worked for the U.S. Soil Conservation Service. Bean was a Boy Scout and he earned the rank of First Class. He graduated from R. L. Paschal High School in Fort Worth, Texas, in 1949. Following his high school graduation in 1949, Bean enlisted in the U.S. Naval Reserve.Bean received a Bachelor of Science degree in aeronautical engineering from the University of Texas at Austin in 1955, where he attended on a Naval Reserve Officers Training Corps (NROTC) scholarship. While at the university, he also joined the Delta Kappa Epsilon fraternity.\n", + "== Early life ==\n", + "Kaufman was born and raised in St. Louis, Missouri. His father is Jewish, while his mother is Catholic. Kaufman began acting at a young age in his hometown when his kindergarten teacher handed him the plum lead role of Santa Claus in the class Christmas play.\n", + "At the age of 18, Kaufman moved from St. Louis to attend UCLA; he was a student in the Department of Theater Arts.\n", "\n", "\n", - "=== Military service ===\n", - "He was an Electronics Technician Striker at the NAS Dallas, Texas, until September 1950, when he was honorably discharged. In January 1955, Bean was commissioned a U.S. Navy ensign through the NROTC at the University of Texas at Austin, and attended flight training. After completing flight training in June 1956, he was assigned to Attack Squadron 44 (VA-44) at NAS Jacksonville, Florida, from 1956 to 1960, flying the F9F Cougar and A4D Skyhawk. After a four-year tour of duty, he attended the U.S. Naval Test Pilot School (USNTPS) at NAS Patuxent River, Maryland, where his instructor was his future Apollo 12 Commander, Pete Conrad, graduating in November 1960. Bean took art classes at St. Mary's College of Maryland during this tour, and flew as a test pilot on several types of naval aircraft. Following his assignment at USNTPS and aviation safety training with the University of Southern California (USC), he went through additional instruction with his old Attack Squadron 44, and was assigned to Navy Attack Squadron VA-172 at NAS Cecil Field, Florida, flying the A-4 Skyhawks, during which time he was selected as a NASA astronaut.Bean logged more than 7,145 hours of flying time, including 4,890 hours in jet aircraft.\n", + "== Career ==\n", + "Since his college years, Kaufman has studied and worked extensively as a professional actor in films and television.\n", + "He has worked with the Daly family of actors on several projects: He worked with Tim Daly on Superman: The Animated Series and its subsequent spin-offs, playing Jimmy Olsen. He also appeared with Daly in the series Wings in 1995 with his wife Lisa; the two portrayed a couple whose wedding Daly's character Joe and his fiancée Helen crash. He worked with Tim's sister, Tyne Daly on Kids Like These and joined Tim again in Justice League: Doom, reprising his role of Jimmy Olsen.\n", + "Kaufman has also worked as a commercial actor. One of his most prominent roles was as a dancing stockboy in a 1989 commercial for Hi-C Ecto Cooler.\n", "\n", "\n", - "=== NASA career ===\n", - "Bean was selected by NASA as part of Astronaut Group 3 in 1963 (after not being selected for Astronaut Group 2 the previous year). He was selected to be the backup command pilot for Gemini 10, but was unsuccessful in securing an early Apollo flight assignment. He was placed in the Apollo Applications Program in the interim. In that capacity, he was the first astronaut to dive in the Neutral Buoyancy Simu\n", + "== Personal life ==\n", + "On June 30, 1990, Kaufman married actress Lisa Picotte; together, they have two children who are also actors, including Grace Kaufman and Henry Kaufman. He came out as bisexual on Celebrate Bisexuality Day in 2021.\n", "\n", - "Mari Aldon (born Marija Aldona Pauliutė; 17 November 1925 – 31 October 2004) was a Lithuanian-born American actress.\n", "\n", + "== Filmography ==\n", "\n", - "== Early life ==\n", - "Mari Aldon was born in Tauragė, Lithuania. Her father Antanas Paulius was a policeman, mother Antanina (Antosė) Paulienė was a nurse. Father moved to America looking for a job. Soon after, when Mari was three years old, her mother also moved to Toronto, Canada with her daughter. There, she attended Givens Public School and Central High School. She studied ballet, drama, piano, and singing. Her early performances were noticed in Lithuanian newspapers of America. She had a sister.\n", "\n", + "=== Television series ===\n", "\n", - "== Career ==\n", - "Before Aldon began working in films, she acted for 11 months in a road company of A Streetcar Named Desire and danced with the Canadian Ballet. She also appeared on radio with Alan Young and on The Harold Peary Show.\n", - "After making her screen debut in a minor role in The Locket (1946) she gradually evolved to playing supporting or lead roles. Her most notable performance was starring opposite Gary Cooper in the 1951 Western Distant Drums. By the mid-1950s she was appearing either in B Pictures like the British thriller Mask of Dust (1954) or in supporting roles in more expensive films such as David Lean's Summertime (1955).After this point she worked largely in television, such as on the TV Western Wagon Train in 1959 as Freda Johnson in \"The Vivian Carter Story\" (S2E23) and in 1960 as Hester Millikan in \"The Jeremy Dow Story\" (S4E14). She guest-starred in a 1961 episode of Ichabod and Me.\n", "\n", + "=== Films ===\n", "\n", - "== Personal life ==\n", - "Aldon married Tay Garnett in London, England on 13 August 1953. Their daughter, Tiela Aldon Garnett (later Daniels), was born in Los Angeles, California on 25 October 1955.On 17 January 1958, Aldon became a US citizen. In August 1970, Aldon filed for divorce from Garnett in Los Angeles, she was widowed seven years later. Aldon and Garnett had a ranch, near King Vidor in Paso Robles, California. Close relatives still live in her hometown of Tauragė, Lithuania, with whom she kept in touch.\n", "\n", + "=== Video games ===\n", "\n", - "== Death ==\n", - "Aldon died on 31 October 2004 in Las Vegas, aged 78, of cancer.\n", "\n", + "=== Commercials ===\n", + "AT&T (starring with Ray Walston)\n", + "Pepsi (starring with Cindy Crawford)\n", + "Blockbuster (starring with Magic Johnson)\n", + "Kid Cuisine (voice of K. C. Penguin)as well as spots for Honda, Hi-C Ecto-Cooler, Maxwell House, Dentyne, Chili's, Midas, Wendy's, Twiglets and British Petroleum, among others.\n", "\n", - "== Filmography ==\n", "\n", + "=== Stage work ===\n", + "Kaufman has earned several Los Angeles area critics' awards and nominations.\n", + "He has been a member of the West Coast Ensemble in Los Angeles for over ten years, performing such varied roles as:\n", "\n", - "== References ==\n", + "Skeets Miller in Floyd Collins\n", + "Prosecutor Gilmer in To Kill a Mockingbird\n", + "George Lewis in Kaufman and Hart's Once in a Lifetime\n", + "Orestes in Electra\n", + "Tyler in Sondheim and Furth's Merrily We Roll Along\n", + "Ronnie Shaughnessy in The House of Blue Leaves\n", + "Callimaco in Machiavelli's The Mandrake\n", + "Eugene Jerome in Neil Simon's Biloxi Blues\n", + "Paul Palmer in James Duff's A Quarrel of Sparrows at The Court Theatre in Los Angeles\n", + "Stewie in the premiere of Richard Greenberg's Night and Her Stars at South Coast Repertory.\n", "\n", "\n", - "== Bibliography ==\n", - "Aaker, Everett. George Raft: The Films. McFarland, 2013.\n", + "== References ==\n", "\n", "\n", "== External links ==\n", - "\n", - "Mari Aldon at IMDb\u001b[0m\u001b[32;1m\u001b[1;3mRelevant Documents: 0,2,6\n", - "Cited Documents: 2,6\n", - "Answer: THE MOTHER OF ALAN SHEPARD, THE SECOND MAN TO WALK ON THE MOON, WAS BORN IN FORT WORTH, TEXAS.\n", - "Grounded answer: THE MOTHER OF ALAN SHEPARD, THE SECOND MAN TO WALK ON THE MOON, WAS BORN IN FORT WORTH, TEXAS.\u001b[0m\n", + "David Kaufman at IMDb\u001b[0m\u001b[32;1m\u001b[1;3mRelevant Documents: 1\n", + "Cited Documents: 1\n", + "Answer: MONTclair, NEW JERSEY.\n", + "Grounded answer: Montclair, New Jersey.\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n" ] @@ -261,7 +275,7 @@ "data": { "text/plain": [ "{'input': 'What was the hometown of the mother of the second person to walk on the moon?',\n", - " 'output': 'THE MOTHER OF ALAN SHEPARD, THE SECOND MAN TO WALK ON THE MOON, WAS BORN IN FORT WORTH, TEXAS.'}" + " 'output': 'MONTclair, NEW JERSEY.'}" ] }, "execution_count": 8, @@ -270,7 +284,7 @@ } ], "source": [ - "agent = create_cohere_multi_hop_agent(\n", + "agent = create_cohere_react_agent(\n", " llm=chat,\n", " tools=[retriever_tool],\n", " prompt=prompt,\n", diff --git a/libs/partners/cohere/langchain_cohere/__init__.py b/libs/partners/cohere/langchain_cohere/__init__.py index 60142c0e6ceca..cbf887c938e38 100644 --- a/libs/partners/cohere/langchain_cohere/__init__.py +++ b/libs/partners/cohere/langchain_cohere/__init__.py @@ -1,7 +1,7 @@ from langchain_cohere.chat_models import ChatCohere from langchain_cohere.cohere_agent import create_cohere_tools_agent from langchain_cohere.embeddings import CohereEmbeddings -from langchain_cohere.multi_hop.agent import create_cohere_multi_hop_agent +from langchain_cohere.react_multi_hop.agent import create_cohere_react_agent from langchain_cohere.rag_retrievers import CohereRagRetriever from langchain_cohere.rerank import CohereRerank @@ -12,5 +12,5 @@ "CohereRagRetriever", "CohereRerank", "create_cohere_tools_agent", - "create_cohere_multi_hop_agent", + "create_cohere_react_agent", ] diff --git a/libs/partners/cohere/langchain_cohere/multi_hop/__init__.py b/libs/partners/cohere/langchain_cohere/react_multi_hop/__init__.py similarity index 100% rename from libs/partners/cohere/langchain_cohere/multi_hop/__init__.py rename to libs/partners/cohere/langchain_cohere/react_multi_hop/__init__.py diff --git a/libs/partners/cohere/langchain_cohere/multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py similarity index 98% rename from libs/partners/cohere/langchain_cohere/multi_hop/agent.py rename to libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py index 449e45dede178..ca0c458eb59ba 100644 --- a/libs/partners/cohere/langchain_cohere/multi_hop/agent.py +++ b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py @@ -14,7 +14,7 @@ from langchain_core.runnables import Runnable, RunnablePassthrough from langchain_core.tools import BaseTool -from langchain_cohere.multi_hop.prompt import multi_hop_prompt_template +from langchain_cohere.react_multi_hop.prompt import multi_hop_prompt_template """ Cohere multi-hop tool allows you to use multiple tools in parallel or @@ -23,7 +23,7 @@ """ -def create_cohere_multi_hop_agent( +def create_cohere_react_agent( llm: BaseLanguageModel, tools: Sequence[BaseTool], prompt: ChatPromptTemplate, @@ -43,12 +43,12 @@ def multi_hop_prompt(x: Dict) -> BasePromptTemplate: ) | multi_hop_prompt | llm.bind(stop=["\nObservation:"], raw_prompting=True) - | CohereToolsMultiHopAgentOutputParser() + | CohereToolsReactAgentOutputParser() ) return agent -class CohereToolsMultiHopAgentOutputParser( +class CohereToolsReactAgentOutputParser( BaseOutputParser[Union[List[AgentAction], AgentFinish]] ): """Parses a message into agent actions/finish.""" diff --git a/libs/partners/cohere/langchain_cohere/multi_hop/prompt.py b/libs/partners/cohere/langchain_cohere/react_multi_hop/prompt.py similarity index 100% rename from libs/partners/cohere/langchain_cohere/multi_hop/prompt.py rename to libs/partners/cohere/langchain_cohere/react_multi_hop/prompt.py From fed0badb30147e0587f0cb4618a0fba7f99f75e7 Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Fri, 29 Mar 2024 08:39:49 +0000 Subject: [PATCH 14/27] Test --- libs/partners/cohere/langchain_cohere/__init__.py | 2 +- libs/partners/cohere/tests/unit_tests/test_imports.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/partners/cohere/langchain_cohere/__init__.py b/libs/partners/cohere/langchain_cohere/__init__.py index cbf887c938e38..17dc3c35defa0 100644 --- a/libs/partners/cohere/langchain_cohere/__init__.py +++ b/libs/partners/cohere/langchain_cohere/__init__.py @@ -1,8 +1,8 @@ from langchain_cohere.chat_models import ChatCohere from langchain_cohere.cohere_agent import create_cohere_tools_agent from langchain_cohere.embeddings import CohereEmbeddings -from langchain_cohere.react_multi_hop.agent import create_cohere_react_agent from langchain_cohere.rag_retrievers import CohereRagRetriever +from langchain_cohere.react_multi_hop.agent import create_cohere_react_agent from langchain_cohere.rerank import CohereRerank __all__ = [ diff --git a/libs/partners/cohere/tests/unit_tests/test_imports.py b/libs/partners/cohere/tests/unit_tests/test_imports.py index 71fe07e8d7b59..b34708aa5d863 100644 --- a/libs/partners/cohere/tests/unit_tests/test_imports.py +++ b/libs/partners/cohere/tests/unit_tests/test_imports.py @@ -7,7 +7,7 @@ "CohereRagRetriever", "CohereRerank", "create_cohere_tools_agent", - "create_cohere_multi_hop_agent", + "create_cohere_react_agent", ] From e00a3f13db3cd81b2886b399a66eea356fc9562d Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Fri, 29 Mar 2024 13:37:54 +0000 Subject: [PATCH 15/27] Add premable override --- .../langchain_cohere/react_multi_hop/agent.py | 8 +++++- .../react_multi_hop/prompt.py | 25 +++++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py index ca0c458eb59ba..bf930c8ee659e 100644 --- a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py +++ b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py @@ -14,7 +14,10 @@ from langchain_core.runnables import Runnable, RunnablePassthrough from langchain_core.tools import BaseTool -from langchain_cohere.react_multi_hop.prompt import multi_hop_prompt_template +from langchain_cohere.react_multi_hop.prompt import ( + multi_hop_prompt_template, + render_structured_preamble, +) """ Cohere multi-hop tool allows you to use multiple tools in parallel or @@ -30,6 +33,9 @@ def create_cohere_react_agent( ) -> Runnable: def multi_hop_prompt(x: Dict) -> BasePromptTemplate: return multi_hop_prompt_template.partial( + structured_preamble=render_structured_preamble( + user_preamble=x.get("preamble", None) + ), tools="\n".join([render_tool_description(t) for t in tools]), user_prompt=prompt.invoke(x).to_string(), steps=format_cohere_log_to_str(x["intermediate_steps"]), diff --git a/libs/partners/cohere/langchain_cohere/react_multi_hop/prompt.py b/libs/partners/cohere/langchain_cohere/react_multi_hop/prompt.py index 4d88b28c3ed2d..f95b825679d91 100644 --- a/libs/partners/cohere/langchain_cohere/react_multi_hop/prompt.py +++ b/libs/partners/cohere/langchain_cohere/react_multi_hop/prompt.py @@ -13,6 +13,12 @@ default_system_prefix = """<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>""" +overridable_preamble = """### Task And Context +{TASK_CONTEXT} + +### Style Guide +{STYLE_GUIDE}""" + structured_preamble_template = """{SYSTEM_PREFIX}# Introduction: This document details the task you must accomplish. Read it carefully and always follow its instructions. @@ -25,31 +31,29 @@ {BASIC_RULES} ## User Preamble -### Task And Context -{TASK_CONTEXT} - -### Style Guide -{STYLE_GUIDE}""" +{USER_PREAMBLE}""" def render_structured_preamble( + user_preamble: str, system_prefix: str = default_system_prefix, basic_rules: str = default_basic_rules, task_context: str = default_task_context, - style_guide: str = default_style_guide, safety_rules: str = default_safety_rules, ) -> str: + if user_preamble is None: + user_preamble = overridable_preamble.format( + STYLE_GUIDE=default_style_guide, + TASK_CONTEXT=task_context, + ) return structured_preamble_template.format( SYSTEM_PREFIX=system_prefix, BASIC_RULES=basic_rules, - TASK_CONTEXT=task_context, - STYLE_GUIDE=style_guide, + USER_PREAMBLE=user_preamble, SAFETY_PREAMBLE=safety_rules, ) -rendered_structured_preamble = render_structured_preamble() - multi_hop_instruction = """Carefully perform the following instructions, in order, starting each with a new line. Firstly, You may need to use complex and advanced reasoning to complete your task and answer the question. Think about how you can use the provided tools to answer the question and come up with a high level plan you will execute. Write 'Plan:' followed by an initial high level plan of how you will solve the problem including the tools and steps required. @@ -72,5 +76,4 @@ def render_structured_preamble( {tools}<|END_OF_TURN_TOKEN|>{history}<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{user_prompt}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{multi_hop_instruction}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>{steps}""" ).partial( multi_hop_instruction=multi_hop_instruction, - structured_preamble=rendered_structured_preamble, ) From a9e6a4acb16d5c1f5979f3ec0da1ffc2c8732dde Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:21:20 +0000 Subject: [PATCH 16/27] Fix text repsonse --- .../cohere/docs/(Maxime)_data_analyst.ipynb | 330 ++++++++++++++++++ .../langchain_cohere/react_multi_hop/agent.py | 4 +- 2 files changed, 333 insertions(+), 1 deletion(-) create mode 100644 libs/partners/cohere/docs/(Maxime)_data_analyst.ipynb diff --git a/libs/partners/cohere/docs/(Maxime)_data_analyst.ipynb b/libs/partners/cohere/docs/(Maxime)_data_analyst.ipynb new file mode 100644 index 0000000000000..1c342d037f364 --- /dev/null +++ b/libs/partners/cohere/docs/(Maxime)_data_analyst.ipynb @@ -0,0 +1,330 @@ +{ + "cells": [ + { + "cell_type": "raw", + "metadata": { + "id": "EUYMLmXAF3W1" + }, + "source": [ + "---\n", + "sidebar_position: 0\n", + "---" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "YxYFKeHcF3W2" + }, + "source": [ + "# Cohere Tools\n", + "\n", + "The following notebook goes over how to use the Cohere tools agent:" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "mBOjO9wjF3W3" + }, + "source": [ + "Prerequisites for this notebook:" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "W8yvOB2MQp07" + }, + "source": [ + "# Environment" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "ujQVUvA9QlD4", + "outputId": "cd76d4cc-d04e-4620-a0d5-2e75b837bd5e" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/177.6 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r", + "\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[90m╺\u001b[0m \u001b[32m174.1/177.6 kB\u001b[0m \u001b[31m5.2 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m177.6/177.6 kB\u001b[0m \u001b[31m4.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25h" + ] + } + ], + "source": [ + "! pip install --quiet langchain langchain_experimental langchain_cohere" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "zXL6LhxyQnD7", + "outputId": "3cb9a20e-30bb-4c21-a0ec-e6dd937401b8" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", + " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", + " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m394.9/394.9 kB\u001b[0m \u001b[31m7.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.6/62.6 kB\u001b[0m \u001b[31m8.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m705.5/705.5 kB\u001b[0m \u001b[31m15.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m85.6/85.6 kB\u001b[0m \u001b[31m12.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m163.8/163.8 kB\u001b[0m \u001b[31m11.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m61.6/61.6 kB\u001b[0m \u001b[31m8.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.2/2.2 MB\u001b[0m \u001b[31m22.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m142.1/142.1 kB\u001b[0m \u001b[31m16.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m121.1/121.1 kB\u001b[0m \u001b[31m13.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25h Building wheel for langchain-cohere (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", + "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", + "torch 2.2.1+cu121 requires nvidia-cublas-cu12==12.1.3.1; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", + "torch 2.2.1+cu121 requires nvidia-cuda-cupti-cu12==12.1.105; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", + "torch 2.2.1+cu121 requires nvidia-cuda-nvrtc-cu12==12.1.105; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", + "torch 2.2.1+cu121 requires nvidia-cuda-runtime-cu12==12.1.105; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", + "torch 2.2.1+cu121 requires nvidia-cudnn-cu12==8.9.2.26; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", + "torch 2.2.1+cu121 requires nvidia-cufft-cu12==11.0.2.54; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", + "torch 2.2.1+cu121 requires nvidia-curand-cu12==10.3.2.106; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", + "torch 2.2.1+cu121 requires nvidia-cusolver-cu12==11.4.5.107; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", + "torch 2.2.1+cu121 requires nvidia-cusparse-cu12==12.1.0.106; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", + "torch 2.2.1+cu121 requires nvidia-nccl-cu12==2.19.3; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", + "torch 2.2.1+cu121 requires nvidia-nvtx-cu12==12.1.105; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", + "jupyter-server 1.24.0 requires anyio<4,>=3.1.0, but you have anyio 4.3.0 which is incompatible.\u001b[0m\u001b[31m\n", + "\u001b[0m" + ] + } + ], + "source": [ + "! pip install --force-reinstall --quiet 'git+https://github.com/BeatrixCohere/langchain.git@beatrix/MultiHopAgent#subdirectory=libs/partners/cohere&egg=langchain-cohere'" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "K9rrOrKWJaBd" + }, + "outputs": [], + "source": [ + "### LLMs\n", + "import os\n", + "COHERE_API_KEY = \"a344FMSW0GsEpjLdqov1QK1jIJ4g2yg1BQ7RAzl9\" # \n", + "# TAVILY_API_KEY = \"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\" # " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hPybpQ5whLkv" + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "k3mrKxSsTfXO" + }, + "source": [ + "# Define tools" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4kGUB4IRF3W5" + }, + "source": [ + "### Web search tool" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "id": "hYsJgVY0F3W5" + }, + "outputs": [], + "source": [ + "from langchain_community.tools.tavily_search import TavilySearchResults\n", + "\n", + "os.environ['TAVILY_API_KEY'] = \"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\"\n", + "web_search_tool = TavilySearchResults(max_results=3)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "rsd-REnMhOq-" + }, + "source": [ + "### Python interpreter tool" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "id": "Zblt8Wm6aV0l" + }, + "outputs": [], + "source": [ + "from langchain.agents import Tool\n", + "from langchain_experimental.utilities import PythonREPL\n", + "\n", + "python_repl = PythonREPL()\n", + "\n", + "repl_tool = Tool(\n", + " name=\"python_repl\",\n", + " description=\"Executes python code and returns the result. The code runs in a static sandbox without interactive mode, so print output or save output to a file.\",\n", + " func=python_repl.run,\n", + ")\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "OjWgvH5MsUZs" + }, + "source": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "sZ0OWLtPsNik" + }, + "source": [ + "### A tool based on a function" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "id": "1rizjYZ1sQwz" + }, + "outputs": [], + "source": [ + "# demo how to easily transform a python function into a tool ?\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "2ENQAfYXRG9Q" + }, + "source": [ + "# Create ReAct Agent" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "id": "hx-Ew1i5F3W4" + }, + "outputs": [], + "source": [ + "from langchain.agents import AgentExecutor\n", + "from langchain_cohere.chat_models import ChatCohere\n", + "from langchain_cohere.react_multi_hop.agent import create_cohere_react_agent\n", + "from langchain_core.prompts import ChatPromptTemplate" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "id": "BPo3ZIHkF3W4" + }, + "outputs": [], + "source": [ + "# Create the prompt\n", + "prompt = ChatPromptTemplate.from_template(\n", + " \"{input}\"\n", + ")\n", + "\n", + "# Create the Cohere chat model\n", + "chat = ChatCohere(cohere_api_key=COHERE_API_KEY, model=\"command-r\")\n", + "\n", + "# Create the ReAct agent\n", + "agent = create_cohere_react_agent(\n", + " llm=chat,\n", + " tools=[web_search_tool, repl_tool],\n", + " prompt=prompt,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "id": "Jl0JNX2TF3W5", + "outputId": "5e4243ad-f591-4287-d42f-e921b2674fff" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", + "\u001b[32;1m\u001b[1;3mCalling: {'tool_name': 'tavily_search_results_json', 'parameters': {'query': 'three most valuable companies number of employees'}} with plan I will search for the three most valuable companies and their number of full-time employees, then write and execute Python code to plot the data.\u001b[0m\u001b[36;1m\u001b[1;3m[{'url': 'https://www.visualcapitalist.com/profit-per-employee-top-u-s-companies-ranking/', 'content': \"That said, the top 10 within this cohort boasted an average profit per employee of $1.13 million, while the bottom 10 companies sit at an average of $348,300. Of course, companies not making the ranking would have even more modest numbers. For example, it's estimated that Starbucks makes around $80,000 per employee, and Coca-Cola makes around ...\"}, {'url': 'https://www.statista.com/statistics/264671/top-50-companies-based-on-number-of-employees/', 'content': 'Largest companies in the world based on revenues, by number of employees 2022\\nAmazon\\nLeading 500 Fortune companies based on number of employees in 2022\\nAdditional Information\\nShow sources information\\nShow publisher information\\nUse Ask Statista Research Service\\nJanuary 2023\\nWorldwide\\nDecember 2022\\nOther statistics on the topic\\nEconomy\\nBiggest companies in the world by market value 2023\\nEconomy\\nTop companies in the world by revenue 2022\\nB2C E-Commerce\\nNumber of Amazon.com employees 2007-2022\\nFinancial Instruments & Investments\\nWeekly development Dow Jones Industrial Average Index 2020-2023\\nTo download this statistic in XLS format you need a Statista Account\\nTo download this statistic in PNG format you need a Statista Account\\nTo download this statistic in PDF format you need a Statista Account\\nTo download this statistic in PPT format you need a Statista Account\\nAs a Premium user you get access to the detailed source references and background information about this statistic.\\n Industry Overview\\nDigital & Trend reports\\nOverview and forecasts on trending topics\\nIndustry & Market reports\\nIndustry and market insights and forecasts\\nCompanies & Products reports\\nKey figures and rankings about companies and products\\nConsumer & Brand reports\\nConsumer and brand insights and preferences in various industries\\nPolitics & Society reports\\nDetailed information about political and social topics\\nCountry & Region reports\\nAll key figures about countries and regions\\nMarket forecast and expert KPIs for 1000+ markets in 190+ countries & territories\\nInsights on consumer attitudes and behavior worldwide\\nBusiness information on 100m+ public and private companies\\nExplore Company Insights\\nDetailed information for 39,000+ online stores and marketplaces\\nDirectly accessible data for 170 industries from 150+ countries\\nand over 1\\xa0Mio. facts.\\n Statistics on\\n\"\\nCompanies worldwide\\n\"\\nOther statistics that may interest you Companies worldwide\\nOverview\\nLargest companies\\nStartups\\nTechnology & sustainability\\nDiversity\\nCovid crisis & recovery\\nFurther related statistics\\nFurther Content: You might find this interesting as well\\nStatistics\\nTopics Transforming data into design:\\nStatista Content & Design\\nStrategy and business building for the data-driven economy:\\nIndustry-specific and extensively researched technical data (partially from exclusive partnerships). Customized Research & Analysis projects:\\nGet quick analyses with our professional research service\\nThe best of the best: the portal for top lists & rankings:\\n'}, {'url': 'https://companiesmarketcap.com/largest-companies-by-number-of-employees/', 'content': \"Woolworths Group. WOW.AX. 200,364. $21.57. 1.91%. 🇦🇺 Australia. This is the list of the world's largest public companies by market number of full-time and part-tim employees. Next 100 .\"}]\u001b[0m\u001b[32;1m\u001b[1;3mCalling: {'tool_name': 'tavily_search_results_json', 'parameters': {'query': 'amazon number of employees'}} with plan The three most valuable companies with the highest number of employees are Amazon, Woolworths Group and Apple. I will now search for the number of employees at each of these companies to gather data for the plot.\u001b[0m\u001b[36;1m\u001b[1;3m[{'url': 'https://www.macrotrends.net/stocks/charts/AMZN/amazon/number-of-employees', 'content': 'Interactive chart of Amazon (AMZN) annual worldwide employee count from 2010 to 2023. Amazon total number of employees in 2023 was 1,525,000, a 1.04% decline from 2022. Amazon total number of employees in 2022 was 1,541,000, a 4.17% decline from 2021. Amazon total number of employees in 2021 was 1,608,000, a 23.88% increase from 2020.'}, {'url': 'https://www.statista.com/statistics/234488/number-of-amazon-employees/', 'content': 'Industry Overview\\nDigital & Trend reports\\nOverview and forecasts on trending topics\\nIndustry & Market reports\\nIndustry and market insights and forecasts\\nCompanies & Products reports\\nKey figures and rankings about companies and products\\nConsumer & Brand reports\\nConsumer and brand insights and preferences in various industries\\nPolitics & Society reports\\nDetailed information about political and social topics\\nCountry & Region reports\\nAll key figures about countries and regions\\nMarket forecast and expert KPIs for 1000+ markets in 190+ countries & territories\\nInsights on consumer attitudes and behavior worldwide\\nBusiness information on 100m+ public and private companies\\nExplore Company Insights\\nDetailed information for 39,000+ online stores and marketplaces\\nDirectly accessible data for 170 industries from 150+ countries\\nand over 1\\xa0Mio. facts.\\n Other statistics on the topicAmazon\\nGeneral Merchandise\\nAmazon physical store sales worldwide Q4 2019-Q4 2022\\nKey Figures of E-Commerce\\nAmazon\\'s chain retail sales value 2022, by business model\\nB2C E-Commerce\\nValue of Fulfilled-by-Amazon (FBA) fees 2020-2023, by weight\\nE-Commerce\\nExpected growth of brand\\'s revenue generated on Amazon 2022\\nTo download this statistic in XLS format you need a Statista Account\\nTo download this statistic in PNG format you need a Statista Account\\nTo download this statistic in PDF format you need a Statista Account\\nTo download this statistic in PPT format you need a Statista Account\\nAs a Premium user you get access to the detailed source references and background information about this statistic.\\n Number of Amazon.com employees 2007-2023\\nE-commerce crunch\\nDiversifying business\\nNumber of Amazon.com employees from 2007 to 2023\\nAdditional Information\\nShow sources information\\nShow publisher information\\nUse Ask Statista Research Service\\nFebruary 2024\\nWorldwide\\n2007 to 2023\\nYear ending December 31\\nFull-time and part-time; excludes contractors & temporary personnel.\\n Statistics on\\n\"\\nAmazon\\n\"\\nOther statistics that may interest you Amazon\\nOverview\\nBenchmarks and competitors\\nMarketplace vs. direct sales\\nRetail segments\\nOnline traffic\\nFurther related statistics\\nFurther Content: You might find this interesting as well\\nStatistics\\nTopics Transforming data into design:\\nStatista Content & Design\\nStrategy and business building for the data-driven economy:\\nIndustry-specific and extensively researched technical data (partially from exclusive partnerships).'}, {'url': 'https://www.aboutamazon.com/news/workplace/our-workforce-data', 'content': '11 Amazon interview tips from recruiters and hiring managers\\nAmazon named among the world’s most admired companies for the eighth year in a row by ‘Fortune’ magazine\\nEverything you should know about Amazon’s hourly wage and benefits offerings for fulfillment employees\\nAn Amazon recruiting manager offers his 3\\nbest tips for a successful job interview\\nI’m Amazon’s VP of Workplace Safety. A review of the compensation awarded in 2022 at Amazon, including base, cash bonuses, and stock, shows that women globally and in the U.S. earned 99.6 cents and 99.5 cents, respectively, for every dollar that men earned performing the same jobs, and minorities in the U.S. earned 99.5 cents for every dollar that white employees earned performing these same jobs. 8 unique benefits and perks available to Amazon employees\\nMeet 4 Amazon employees who help make the holidays happen for customers\\nAmazon News\\nSign up for the latest news, facts, analysis, and original stories about Amazon, delivered to you weekly. This Self-ID process allows Amazon to gather more inclusive global data on race, gender, and other identities to help give us a more detailed picture of our workforce.\\n Our workforce data\\nWe have made year-over-year progress, and we will continue to strive for better representation across our company.\\n'}]\u001b[0m\u001b[32;1m\u001b[1;3mCalling: {'tool_name': 'tavily_search_results_json', 'parameters': {'query': 'Woolworths Group number of employees'}} with plan The three most valuable companies with the highest number of employees are Amazon, Woolworths Group and Apple. I will now search for the number of employees at each of these companies to gather data for the plot.\u001b[0m\u001b[36;1m\u001b[1;3m[{'url': 'https://www.woolworthsgroup.com.au/content/dam/wwg/investors/reports/2023/f23-full-year/Woolworths Group 2023 Annual Report.pdf', 'content': \"Our pathway to net positive Woolworths Group reaffirms our support for the Uluru 46 Our material risks 60 SECTION 3 Directors' Report Governance 66 Board of Directors 68 ... 1 Total number of members that have joined the program since inception. 2 Includes Woolworths Supermarkets, Metro Food Stores, Countdown Supermarkets and BIG W. ...\"}, {'url': 'https://www.statista.com/statistics/1429437/number-of-employees-woolworths-group-limited/', 'content': 'The number of employees of the company Woolworths Group Limited headquartered in Australia decreased to 198 thousand persons since the previous year. This means a decline of 12.1 thousand persons ...'}, {'url': 'https://en.wikipedia.org/wiki/Woolworths_Group_(Australia)', 'content': 'Woolworths Group Limited is an Australian multinational retail and finance company, ... Sydney, it is the largest company in Australia by revenue and number of employees, and the second-largest in New Zealand. Founded in Sydney in 1924 as variety retailer Woolworths Limited, ...'}]\u001b[0m\u001b[32;1m\u001b[1;3mCalling: {'tool_name': 'tavily_search_results_json', 'parameters': {'query': 'apple number of employees'}} with plan The three most valuable companies with the highest number of employees are Amazon, Woolworths Group and Apple. I will now search for the number of employees at each of these companies to gather data for the plot.\u001b[0m\u001b[36;1m\u001b[1;3m[{'url': 'https://www.macrotrends.net/stocks/charts/AAPL/apple/number-of-employees', 'content': 'Employee Count. Interactive chart of Apple (AAPL) annual worldwide employee count from 2010 to 2023. Apple total number of employees in 2023 was 161,000, a 1.83% decline from 2022. Apple total number of employees in 2022 was 164,000, a 6.49% increase from 2021. Apple total number of employees in 2021 was 154,000, a 4.76% increase from 2020.'}, {'url': 'https://stockanalysis.com/stocks/aapl/employees/', 'content': 'Apple Employees. Apple had 161,000 employees on September 30, 2023. The number of employees decreased by 3,000 or -1.83% compared to the previous year. Employees ... Sources: Annual number of employees according to filings submitted to the U.S. Securities and Exchange Commission (SEC). Data is also manually gathered from company press releases ...'}, {'url': 'https://www.statista.com/statistics/273439/number-of-employees-of-apple-since-2005/', 'content': 'Digital & Trend reports\\nOverview and forecasts on trending topics\\nIndustry & Market reports\\nIndustry and market insights and forecasts\\nCompanies & Products reports\\nKey figures and rankings about companies and products\\nConsumer & Brand reports\\nConsumer and brand insights and preferences in various industries\\nPolitics & Society reports\\nDetailed information about political and social topics\\nCountry & Region reports\\nAll key figures about countries and regions\\nMarket forecast and expert KPIs for 1000+ markets in 190+ countries & territories\\nInsights on consumer attitudes and behavior worldwide\\nBusiness information on 100m+ public and private companies\\nExplore Company Insights\\nDetailed information for 39,000+ online stores and marketplaces\\nDirectly accessible data for 170 industries from 150+ countries\\nand over 1\\xa0Mio. facts.\\n Other statistics on the topicApple\\nConsumer Electronics\\nApple\\'s revenue worldwide 2004-2023\\nConsumer Electronics\\nApple\\'s revenue broken down by geographical region 2012-2023, by quarter\\nTelecommunications\\nQuarterly market share of smartphone vendors in the U.S. 2016-2023\\nConsumer Electronics\\nApple: expenditure on research and development 2007-2023\\nTo download this statistic in XLS format you need a Statista Account\\nTo download this statistic in PNG format you need a Statista Account\\nTo download this statistic in PDF format you need a Statista Account\\nTo download this statistic in PPT format you need a Statista Account\\nAs a Premium user you get access to the detailed source references and background information about this statistic.\\n Statistics on\\n\"\\nApple in the U.S.\\n\"\\nOther statistics that may interest you Apple in the U.S.\\nOverview: Apple\\nOverview: Apple in the U.S.\\nSegment: iPhone\\nSegment: iPad\\nSegment: Mac\\nSegment: Wearables & Smart home\\nFurther related statistics\\nFurther Content: You might find this interesting as well\\nStatistics\\nTopics Number of employees of Apple 2005-2023\\nApple Corporation – additional information\\nApple products\\nApple\\'s number of employees in the fiscal years 2005 to 2023\\n(in 1,000s)\\nAdditional Information\\nShow sources information\\nShow publisher information\\nUse Ask Statista Research Service\\nNovember 2023\\nWorldwide\\n2005 to 2023\\n Transforming data into design:\\nStatista Content & Design\\nStrategy and business building for the data-driven economy:\\nIndustry-specific and extensively researched technical data (partially from exclusive partnerships).'}]\u001b[0m" + ] + } + ], + "source": [ + "agent_executor = AgentExecutor(agent=agent, tools=[web_search_tool, repl_tool], verbose=True)\n", + "# agent_executor = AgentExecutor(agent=agent, tools=[web_search_tool], verbose=True)\n", + "agent_executor.invoke({\"input\": \"Create a plot of the number of full time employees at the three most valuable\"})" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.7" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py index bf930c8ee659e..4329bb9e809c1 100644 --- a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py +++ b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py @@ -182,7 +182,9 @@ def parse(self, text: str) -> Union[List[AgentAction], AgentFinish]: elif any([x in text for x in ["Plan: ", "Reflection: ", "Action: "]]): completion, plan, actions = self.parse_actions(text) return [ - AgentAction(action["tool_name"], action["parameters"], text) + AgentAction( + action["tool_name"], action["parameters"], f"Calling: {action} with plan {plan}" + ) for action in actions ] else: From e3cf615d977574476650745ff85d4ac49c8933af Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:21:50 +0000 Subject: [PATCH 17/27] Format --- .../partners/cohere/langchain_cohere/react_multi_hop/agent.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py index 4329bb9e809c1..35ffa6d7a7ca4 100644 --- a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py +++ b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py @@ -183,7 +183,9 @@ def parse(self, text: str) -> Union[List[AgentAction], AgentFinish]: completion, plan, actions = self.parse_actions(text) return [ AgentAction( - action["tool_name"], action["parameters"], f"Calling: {action} with plan {plan}" + action["tool_name"], + action["parameters"], + f"Calling: {action} with plan {plan}", ) for action in actions ] From a24ffc336351a1c90d2277dd33135b2351c5e64a Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:23:03 +0000 Subject: [PATCH 18/27] Delete --- .../cohere/docs/(Maxime)_data_analyst.ipynb | 330 ------------------ 1 file changed, 330 deletions(-) delete mode 100644 libs/partners/cohere/docs/(Maxime)_data_analyst.ipynb diff --git a/libs/partners/cohere/docs/(Maxime)_data_analyst.ipynb b/libs/partners/cohere/docs/(Maxime)_data_analyst.ipynb deleted file mode 100644 index 1c342d037f364..0000000000000 --- a/libs/partners/cohere/docs/(Maxime)_data_analyst.ipynb +++ /dev/null @@ -1,330 +0,0 @@ -{ - "cells": [ - { - "cell_type": "raw", - "metadata": { - "id": "EUYMLmXAF3W1" - }, - "source": [ - "---\n", - "sidebar_position: 0\n", - "---" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "YxYFKeHcF3W2" - }, - "source": [ - "# Cohere Tools\n", - "\n", - "The following notebook goes over how to use the Cohere tools agent:" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "mBOjO9wjF3W3" - }, - "source": [ - "Prerequisites for this notebook:" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "W8yvOB2MQp07" - }, - "source": [ - "# Environment" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "ujQVUvA9QlD4", - "outputId": "cd76d4cc-d04e-4620-a0d5-2e75b837bd5e" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/177.6 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r", - "\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[90m╺\u001b[0m \u001b[32m174.1/177.6 kB\u001b[0m \u001b[31m5.2 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m177.6/177.6 kB\u001b[0m \u001b[31m4.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25h" - ] - } - ], - "source": [ - "! pip install --quiet langchain langchain_experimental langchain_cohere" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "zXL6LhxyQnD7", - "outputId": "3cb9a20e-30bb-4c21-a0ec-e6dd937401b8" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", - " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", - " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m394.9/394.9 kB\u001b[0m \u001b[31m7.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.6/62.6 kB\u001b[0m \u001b[31m8.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m705.5/705.5 kB\u001b[0m \u001b[31m15.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m85.6/85.6 kB\u001b[0m \u001b[31m12.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m163.8/163.8 kB\u001b[0m \u001b[31m11.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m61.6/61.6 kB\u001b[0m \u001b[31m8.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.2/2.2 MB\u001b[0m \u001b[31m22.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m142.1/142.1 kB\u001b[0m \u001b[31m16.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m121.1/121.1 kB\u001b[0m \u001b[31m13.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25h Building wheel for langchain-cohere (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", - "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", - "torch 2.2.1+cu121 requires nvidia-cublas-cu12==12.1.3.1; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", - "torch 2.2.1+cu121 requires nvidia-cuda-cupti-cu12==12.1.105; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", - "torch 2.2.1+cu121 requires nvidia-cuda-nvrtc-cu12==12.1.105; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", - "torch 2.2.1+cu121 requires nvidia-cuda-runtime-cu12==12.1.105; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", - "torch 2.2.1+cu121 requires nvidia-cudnn-cu12==8.9.2.26; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", - "torch 2.2.1+cu121 requires nvidia-cufft-cu12==11.0.2.54; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", - "torch 2.2.1+cu121 requires nvidia-curand-cu12==10.3.2.106; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", - "torch 2.2.1+cu121 requires nvidia-cusolver-cu12==11.4.5.107; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", - "torch 2.2.1+cu121 requires nvidia-cusparse-cu12==12.1.0.106; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", - "torch 2.2.1+cu121 requires nvidia-nccl-cu12==2.19.3; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", - "torch 2.2.1+cu121 requires nvidia-nvtx-cu12==12.1.105; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", - "jupyter-server 1.24.0 requires anyio<4,>=3.1.0, but you have anyio 4.3.0 which is incompatible.\u001b[0m\u001b[31m\n", - "\u001b[0m" - ] - } - ], - "source": [ - "! pip install --force-reinstall --quiet 'git+https://github.com/BeatrixCohere/langchain.git@beatrix/MultiHopAgent#subdirectory=libs/partners/cohere&egg=langchain-cohere'" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": { - "id": "K9rrOrKWJaBd" - }, - "outputs": [], - "source": [ - "### LLMs\n", - "import os\n", - "COHERE_API_KEY = \"a344FMSW0GsEpjLdqov1QK1jIJ4g2yg1BQ7RAzl9\" # \n", - "# TAVILY_API_KEY = \"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\" # " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "hPybpQ5whLkv" - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "k3mrKxSsTfXO" - }, - "source": [ - "# Define tools" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "4kGUB4IRF3W5" - }, - "source": [ - "### Web search tool" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": { - "id": "hYsJgVY0F3W5" - }, - "outputs": [], - "source": [ - "from langchain_community.tools.tavily_search import TavilySearchResults\n", - "\n", - "os.environ['TAVILY_API_KEY'] = \"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\"\n", - "web_search_tool = TavilySearchResults(max_results=3)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "rsd-REnMhOq-" - }, - "source": [ - "### Python interpreter tool" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": { - "id": "Zblt8Wm6aV0l" - }, - "outputs": [], - "source": [ - "from langchain.agents import Tool\n", - "from langchain_experimental.utilities import PythonREPL\n", - "\n", - "python_repl = PythonREPL()\n", - "\n", - "repl_tool = Tool(\n", - " name=\"python_repl\",\n", - " description=\"Executes python code and returns the result. The code runs in a static sandbox without interactive mode, so print output or save output to a file.\",\n", - " func=python_repl.run,\n", - ")\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "OjWgvH5MsUZs" - }, - "source": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "sZ0OWLtPsNik" - }, - "source": [ - "### A tool based on a function" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": { - "id": "1rizjYZ1sQwz" - }, - "outputs": [], - "source": [ - "# demo how to easily transform a python function into a tool ?\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "2ENQAfYXRG9Q" - }, - "source": [ - "# Create ReAct Agent" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": { - "id": "hx-Ew1i5F3W4" - }, - "outputs": [], - "source": [ - "from langchain.agents import AgentExecutor\n", - "from langchain_cohere.chat_models import ChatCohere\n", - "from langchain_cohere.react_multi_hop.agent import create_cohere_react_agent\n", - "from langchain_core.prompts import ChatPromptTemplate" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": { - "id": "BPo3ZIHkF3W4" - }, - "outputs": [], - "source": [ - "# Create the prompt\n", - "prompt = ChatPromptTemplate.from_template(\n", - " \"{input}\"\n", - ")\n", - "\n", - "# Create the Cohere chat model\n", - "chat = ChatCohere(cohere_api_key=COHERE_API_KEY, model=\"command-r\")\n", - "\n", - "# Create the ReAct agent\n", - "agent = create_cohere_react_agent(\n", - " llm=chat,\n", - " tools=[web_search_tool, repl_tool],\n", - " prompt=prompt,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 1000 - }, - "id": "Jl0JNX2TF3W5", - "outputId": "5e4243ad-f591-4287-d42f-e921b2674fff" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n", - "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", - "\u001b[32;1m\u001b[1;3mCalling: {'tool_name': 'tavily_search_results_json', 'parameters': {'query': 'three most valuable companies number of employees'}} with plan I will search for the three most valuable companies and their number of full-time employees, then write and execute Python code to plot the data.\u001b[0m\u001b[36;1m\u001b[1;3m[{'url': 'https://www.visualcapitalist.com/profit-per-employee-top-u-s-companies-ranking/', 'content': \"That said, the top 10 within this cohort boasted an average profit per employee of $1.13 million, while the bottom 10 companies sit at an average of $348,300. Of course, companies not making the ranking would have even more modest numbers. For example, it's estimated that Starbucks makes around $80,000 per employee, and Coca-Cola makes around ...\"}, {'url': 'https://www.statista.com/statistics/264671/top-50-companies-based-on-number-of-employees/', 'content': 'Largest companies in the world based on revenues, by number of employees 2022\\nAmazon\\nLeading 500 Fortune companies based on number of employees in 2022\\nAdditional Information\\nShow sources information\\nShow publisher information\\nUse Ask Statista Research Service\\nJanuary 2023\\nWorldwide\\nDecember 2022\\nOther statistics on the topic\\nEconomy\\nBiggest companies in the world by market value 2023\\nEconomy\\nTop companies in the world by revenue 2022\\nB2C E-Commerce\\nNumber of Amazon.com employees 2007-2022\\nFinancial Instruments & Investments\\nWeekly development Dow Jones Industrial Average Index 2020-2023\\nTo download this statistic in XLS format you need a Statista Account\\nTo download this statistic in PNG format you need a Statista Account\\nTo download this statistic in PDF format you need a Statista Account\\nTo download this statistic in PPT format you need a Statista Account\\nAs a Premium user you get access to the detailed source references and background information about this statistic.\\n Industry Overview\\nDigital & Trend reports\\nOverview and forecasts on trending topics\\nIndustry & Market reports\\nIndustry and market insights and forecasts\\nCompanies & Products reports\\nKey figures and rankings about companies and products\\nConsumer & Brand reports\\nConsumer and brand insights and preferences in various industries\\nPolitics & Society reports\\nDetailed information about political and social topics\\nCountry & Region reports\\nAll key figures about countries and regions\\nMarket forecast and expert KPIs for 1000+ markets in 190+ countries & territories\\nInsights on consumer attitudes and behavior worldwide\\nBusiness information on 100m+ public and private companies\\nExplore Company Insights\\nDetailed information for 39,000+ online stores and marketplaces\\nDirectly accessible data for 170 industries from 150+ countries\\nand over 1\\xa0Mio. facts.\\n Statistics on\\n\"\\nCompanies worldwide\\n\"\\nOther statistics that may interest you Companies worldwide\\nOverview\\nLargest companies\\nStartups\\nTechnology & sustainability\\nDiversity\\nCovid crisis & recovery\\nFurther related statistics\\nFurther Content: You might find this interesting as well\\nStatistics\\nTopics Transforming data into design:\\nStatista Content & Design\\nStrategy and business building for the data-driven economy:\\nIndustry-specific and extensively researched technical data (partially from exclusive partnerships). Customized Research & Analysis projects:\\nGet quick analyses with our professional research service\\nThe best of the best: the portal for top lists & rankings:\\n'}, {'url': 'https://companiesmarketcap.com/largest-companies-by-number-of-employees/', 'content': \"Woolworths Group. WOW.AX. 200,364. $21.57. 1.91%. 🇦🇺 Australia. This is the list of the world's largest public companies by market number of full-time and part-tim employees. Next 100 .\"}]\u001b[0m\u001b[32;1m\u001b[1;3mCalling: {'tool_name': 'tavily_search_results_json', 'parameters': {'query': 'amazon number of employees'}} with plan The three most valuable companies with the highest number of employees are Amazon, Woolworths Group and Apple. I will now search for the number of employees at each of these companies to gather data for the plot.\u001b[0m\u001b[36;1m\u001b[1;3m[{'url': 'https://www.macrotrends.net/stocks/charts/AMZN/amazon/number-of-employees', 'content': 'Interactive chart of Amazon (AMZN) annual worldwide employee count from 2010 to 2023. Amazon total number of employees in 2023 was 1,525,000, a 1.04% decline from 2022. Amazon total number of employees in 2022 was 1,541,000, a 4.17% decline from 2021. Amazon total number of employees in 2021 was 1,608,000, a 23.88% increase from 2020.'}, {'url': 'https://www.statista.com/statistics/234488/number-of-amazon-employees/', 'content': 'Industry Overview\\nDigital & Trend reports\\nOverview and forecasts on trending topics\\nIndustry & Market reports\\nIndustry and market insights and forecasts\\nCompanies & Products reports\\nKey figures and rankings about companies and products\\nConsumer & Brand reports\\nConsumer and brand insights and preferences in various industries\\nPolitics & Society reports\\nDetailed information about political and social topics\\nCountry & Region reports\\nAll key figures about countries and regions\\nMarket forecast and expert KPIs for 1000+ markets in 190+ countries & territories\\nInsights on consumer attitudes and behavior worldwide\\nBusiness information on 100m+ public and private companies\\nExplore Company Insights\\nDetailed information for 39,000+ online stores and marketplaces\\nDirectly accessible data for 170 industries from 150+ countries\\nand over 1\\xa0Mio. facts.\\n Other statistics on the topicAmazon\\nGeneral Merchandise\\nAmazon physical store sales worldwide Q4 2019-Q4 2022\\nKey Figures of E-Commerce\\nAmazon\\'s chain retail sales value 2022, by business model\\nB2C E-Commerce\\nValue of Fulfilled-by-Amazon (FBA) fees 2020-2023, by weight\\nE-Commerce\\nExpected growth of brand\\'s revenue generated on Amazon 2022\\nTo download this statistic in XLS format you need a Statista Account\\nTo download this statistic in PNG format you need a Statista Account\\nTo download this statistic in PDF format you need a Statista Account\\nTo download this statistic in PPT format you need a Statista Account\\nAs a Premium user you get access to the detailed source references and background information about this statistic.\\n Number of Amazon.com employees 2007-2023\\nE-commerce crunch\\nDiversifying business\\nNumber of Amazon.com employees from 2007 to 2023\\nAdditional Information\\nShow sources information\\nShow publisher information\\nUse Ask Statista Research Service\\nFebruary 2024\\nWorldwide\\n2007 to 2023\\nYear ending December 31\\nFull-time and part-time; excludes contractors & temporary personnel.\\n Statistics on\\n\"\\nAmazon\\n\"\\nOther statistics that may interest you Amazon\\nOverview\\nBenchmarks and competitors\\nMarketplace vs. direct sales\\nRetail segments\\nOnline traffic\\nFurther related statistics\\nFurther Content: You might find this interesting as well\\nStatistics\\nTopics Transforming data into design:\\nStatista Content & Design\\nStrategy and business building for the data-driven economy:\\nIndustry-specific and extensively researched technical data (partially from exclusive partnerships).'}, {'url': 'https://www.aboutamazon.com/news/workplace/our-workforce-data', 'content': '11 Amazon interview tips from recruiters and hiring managers\\nAmazon named among the world’s most admired companies for the eighth year in a row by ‘Fortune’ magazine\\nEverything you should know about Amazon’s hourly wage and benefits offerings for fulfillment employees\\nAn Amazon recruiting manager offers his 3\\nbest tips for a successful job interview\\nI’m Amazon’s VP of Workplace Safety. A review of the compensation awarded in 2022 at Amazon, including base, cash bonuses, and stock, shows that women globally and in the U.S. earned 99.6 cents and 99.5 cents, respectively, for every dollar that men earned performing the same jobs, and minorities in the U.S. earned 99.5 cents for every dollar that white employees earned performing these same jobs. 8 unique benefits and perks available to Amazon employees\\nMeet 4 Amazon employees who help make the holidays happen for customers\\nAmazon News\\nSign up for the latest news, facts, analysis, and original stories about Amazon, delivered to you weekly. This Self-ID process allows Amazon to gather more inclusive global data on race, gender, and other identities to help give us a more detailed picture of our workforce.\\n Our workforce data\\nWe have made year-over-year progress, and we will continue to strive for better representation across our company.\\n'}]\u001b[0m\u001b[32;1m\u001b[1;3mCalling: {'tool_name': 'tavily_search_results_json', 'parameters': {'query': 'Woolworths Group number of employees'}} with plan The three most valuable companies with the highest number of employees are Amazon, Woolworths Group and Apple. I will now search for the number of employees at each of these companies to gather data for the plot.\u001b[0m\u001b[36;1m\u001b[1;3m[{'url': 'https://www.woolworthsgroup.com.au/content/dam/wwg/investors/reports/2023/f23-full-year/Woolworths Group 2023 Annual Report.pdf', 'content': \"Our pathway to net positive Woolworths Group reaffirms our support for the Uluru 46 Our material risks 60 SECTION 3 Directors' Report Governance 66 Board of Directors 68 ... 1 Total number of members that have joined the program since inception. 2 Includes Woolworths Supermarkets, Metro Food Stores, Countdown Supermarkets and BIG W. ...\"}, {'url': 'https://www.statista.com/statistics/1429437/number-of-employees-woolworths-group-limited/', 'content': 'The number of employees of the company Woolworths Group Limited headquartered in Australia decreased to 198 thousand persons since the previous year. This means a decline of 12.1 thousand persons ...'}, {'url': 'https://en.wikipedia.org/wiki/Woolworths_Group_(Australia)', 'content': 'Woolworths Group Limited is an Australian multinational retail and finance company, ... Sydney, it is the largest company in Australia by revenue and number of employees, and the second-largest in New Zealand. Founded in Sydney in 1924 as variety retailer Woolworths Limited, ...'}]\u001b[0m\u001b[32;1m\u001b[1;3mCalling: {'tool_name': 'tavily_search_results_json', 'parameters': {'query': 'apple number of employees'}} with plan The three most valuable companies with the highest number of employees are Amazon, Woolworths Group and Apple. I will now search for the number of employees at each of these companies to gather data for the plot.\u001b[0m\u001b[36;1m\u001b[1;3m[{'url': 'https://www.macrotrends.net/stocks/charts/AAPL/apple/number-of-employees', 'content': 'Employee Count. Interactive chart of Apple (AAPL) annual worldwide employee count from 2010 to 2023. Apple total number of employees in 2023 was 161,000, a 1.83% decline from 2022. Apple total number of employees in 2022 was 164,000, a 6.49% increase from 2021. Apple total number of employees in 2021 was 154,000, a 4.76% increase from 2020.'}, {'url': 'https://stockanalysis.com/stocks/aapl/employees/', 'content': 'Apple Employees. Apple had 161,000 employees on September 30, 2023. The number of employees decreased by 3,000 or -1.83% compared to the previous year. Employees ... Sources: Annual number of employees according to filings submitted to the U.S. Securities and Exchange Commission (SEC). Data is also manually gathered from company press releases ...'}, {'url': 'https://www.statista.com/statistics/273439/number-of-employees-of-apple-since-2005/', 'content': 'Digital & Trend reports\\nOverview and forecasts on trending topics\\nIndustry & Market reports\\nIndustry and market insights and forecasts\\nCompanies & Products reports\\nKey figures and rankings about companies and products\\nConsumer & Brand reports\\nConsumer and brand insights and preferences in various industries\\nPolitics & Society reports\\nDetailed information about political and social topics\\nCountry & Region reports\\nAll key figures about countries and regions\\nMarket forecast and expert KPIs for 1000+ markets in 190+ countries & territories\\nInsights on consumer attitudes and behavior worldwide\\nBusiness information on 100m+ public and private companies\\nExplore Company Insights\\nDetailed information for 39,000+ online stores and marketplaces\\nDirectly accessible data for 170 industries from 150+ countries\\nand over 1\\xa0Mio. facts.\\n Other statistics on the topicApple\\nConsumer Electronics\\nApple\\'s revenue worldwide 2004-2023\\nConsumer Electronics\\nApple\\'s revenue broken down by geographical region 2012-2023, by quarter\\nTelecommunications\\nQuarterly market share of smartphone vendors in the U.S. 2016-2023\\nConsumer Electronics\\nApple: expenditure on research and development 2007-2023\\nTo download this statistic in XLS format you need a Statista Account\\nTo download this statistic in PNG format you need a Statista Account\\nTo download this statistic in PDF format you need a Statista Account\\nTo download this statistic in PPT format you need a Statista Account\\nAs a Premium user you get access to the detailed source references and background information about this statistic.\\n Statistics on\\n\"\\nApple in the U.S.\\n\"\\nOther statistics that may interest you Apple in the U.S.\\nOverview: Apple\\nOverview: Apple in the U.S.\\nSegment: iPhone\\nSegment: iPad\\nSegment: Mac\\nSegment: Wearables & Smart home\\nFurther related statistics\\nFurther Content: You might find this interesting as well\\nStatistics\\nTopics Number of employees of Apple 2005-2023\\nApple Corporation – additional information\\nApple products\\nApple\\'s number of employees in the fiscal years 2005 to 2023\\n(in 1,000s)\\nAdditional Information\\nShow sources information\\nShow publisher information\\nUse Ask Statista Research Service\\nNovember 2023\\nWorldwide\\n2005 to 2023\\n Transforming data into design:\\nStatista Content & Design\\nStrategy and business building for the data-driven economy:\\nIndustry-specific and extensively researched technical data (partially from exclusive partnerships).'}]\u001b[0m" - ] - } - ], - "source": [ - "agent_executor = AgentExecutor(agent=agent, tools=[web_search_tool, repl_tool], verbose=True)\n", - "# agent_executor = AgentExecutor(agent=agent, tools=[web_search_tool], verbose=True)\n", - "agent_executor.invoke({\"input\": \"Create a plot of the number of full time employees at the three most valuable\"})" - ] - } - ], - "metadata": { - "colab": { - "provenance": [] - }, - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.7" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} From 59c8c39319536255394e73d99181887a40f6b5b5 Mon Sep 17 00:00:00 2001 From: BeatrixCohere <128378696+BeatrixCohere@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:48:35 +0000 Subject: [PATCH 19/27] Fix formatting --- .../partners/cohere/langchain_cohere/react_multi_hop/agent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py index 35ffa6d7a7ca4..4ea2d05f6755f 100644 --- a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py +++ b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py @@ -185,9 +185,9 @@ def parse(self, text: str) -> Union[List[AgentAction], AgentFinish]: AgentAction( action["tool_name"], action["parameters"], - f"Calling: {action} with plan {plan}", + f"\n{action}\n" if i > 0 else f"\n{plan}\n{action}\n", ) - for action in actions + for i, action in enumerate(actions) ] else: raise ValueError( From e46b382cac1c5798538b36367e10bd24c5f755b1 Mon Sep 17 00:00:00 2001 From: Harry M <127103098+harry-cohere@users.noreply.github.com> Date: Fri, 29 Mar 2024 17:09:48 +0000 Subject: [PATCH 20/27] Increase default timeout --- libs/partners/cohere/langchain_cohere/llms.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/partners/cohere/langchain_cohere/llms.py b/libs/partners/cohere/langchain_cohere/llms.py index 4cf30e42a3b01..2f8463464a629 100644 --- a/libs/partners/cohere/langchain_cohere/llms.py +++ b/libs/partners/cohere/langchain_cohere/llms.py @@ -69,6 +69,8 @@ class BaseCohere(Serializable): user_agent: str = "langchain" """Identifier for the application making the request.""" + timeout_seconds: Optional[float] = 300 + @root_validator() def validate_environment(cls, values: Dict) -> Dict: """Validate that api key and python package exists in environment.""" @@ -76,12 +78,15 @@ def validate_environment(cls, values: Dict) -> Dict: get_from_dict_or_env(values, "cohere_api_key", "COHERE_API_KEY") ) client_name = values["user_agent"] + timeout_seconds = values.get("timeout_seconds") values["client"] = cohere.Client( api_key=values["cohere_api_key"].get_secret_value(), + timeout=timeout_seconds, client_name=client_name, ) values["async_client"] = cohere.AsyncClient( api_key=values["cohere_api_key"].get_secret_value(), + timeout=timeout_seconds, client_name=client_name, ) return values From c31c15717403836cd786b389b2d37d77fdf84744 Mon Sep 17 00:00:00 2001 From: Harry M <127103098+harry-cohere@users.noreply.github.com> Date: Fri, 29 Mar 2024 17:28:06 +0000 Subject: [PATCH 21/27] Fix stop sequences --- .../cohere/langchain_cohere/chat_models.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libs/partners/cohere/langchain_cohere/chat_models.py b/libs/partners/cohere/langchain_cohere/chat_models.py index 8babfc3e16bc9..19cc20dd1e1ee 100644 --- a/libs/partners/cohere/langchain_cohere/chat_models.py +++ b/libs/partners/cohere/langchain_cohere/chat_models.py @@ -66,6 +66,7 @@ def get_cohere_chat_request( *, documents: Optional[List[Dict[str, str]]] = None, connectors: Optional[List[Dict[str, str]]] = None, + stop_sequences: Optional[List[str]] = None, **kwargs: Any, ) -> Dict[str, Any]: """Get the request for the Cohere chat API. @@ -115,6 +116,7 @@ def get_cohere_chat_request( "documents": formatted_docs, "connectors": connectors, "prompt_truncation": prompt_truncation, + "stop_sequences": stop_sequences, **kwargs, } @@ -180,7 +182,9 @@ def _stream( run_manager: Optional[CallbackManagerForLLMRun] = None, **kwargs: Any, ) -> Iterator[ChatGenerationChunk]: - request = get_cohere_chat_request(messages, **self._default_params, **kwargs) + request = get_cohere_chat_request( + messages, stop_sequences=stop, **self._default_params, **kwargs + ) if hasattr(self.client, "chat_stream"): # detect and support sdk v5 stream = self.client.chat_stream(**request) @@ -210,7 +214,9 @@ async def _astream( run_manager: Optional[AsyncCallbackManagerForLLMRun] = None, **kwargs: Any, ) -> AsyncIterator[ChatGenerationChunk]: - request = get_cohere_chat_request(messages, **self._default_params, **kwargs) + request = get_cohere_chat_request( + messages, stop_sequences=stop, **self._default_params, **kwargs + ) if hasattr(self.async_client, "chat_stream"): # detect and support sdk v5 stream = self.async_client.chat_stream(**request) @@ -266,7 +272,9 @@ def _generate( ) return generate_from_stream(stream_iter) - request = get_cohere_chat_request(messages, **self._default_params, **kwargs) + request = get_cohere_chat_request( + messages, stop_sequences=stop, **self._default_params, **kwargs + ) response = self.client.chat(**request) generation_info = self._get_generation_info(response) @@ -290,7 +298,9 @@ async def _agenerate( ) return await agenerate_from_stream(stream_iter) - request = get_cohere_chat_request(messages, **self._default_params, **kwargs) + request = get_cohere_chat_request( + messages, stop_sequences=stop, **self._default_params, **kwargs + ) response = self.client.chat(**request) generation_info = self._get_generation_info(response) From b3b9d3f3dd7e11c8d96944b5a70bc4648e629ce8 Mon Sep 17 00:00:00 2001 From: Harry M <127103098+harry-cohere@users.noreply.github.com> Date: Fri, 29 Mar 2024 18:26:50 +0000 Subject: [PATCH 22/27] convert parameter types --- .../cohere/langchain_cohere/cohere_agent.py | 19 +++++++++++++++---- .../langchain_cohere/react_multi_hop/agent.py | 6 ++++-- .../tests/unit_tests/test_cohere_agent.py | 6 +++--- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/libs/partners/cohere/langchain_cohere/cohere_agent.py b/libs/partners/cohere/langchain_cohere/cohere_agent.py index c9c3fa9808f08..8481c0768e8ab 100644 --- a/libs/partners/cohere/langchain_cohere/cohere_agent.py +++ b/libs/partners/cohere/langchain_cohere/cohere_agent.py @@ -11,7 +11,12 @@ from langchain_core.runnables import Runnable, RunnablePassthrough from langchain_core.runnables.base import RunnableLambda from langchain_core.tools import BaseTool -from langchain_core.utils.function_calling import convert_to_openai_function +from langchain_core.utils.function_calling import ( + PYTHON_TO_JSON_TYPES, + convert_to_openai_function, +) + +JSON_TO_PYTHON_TYPES = {v: k for k, v in PYTHON_TO_JSON_TYPES.items()} def create_cohere_tools_agent( @@ -86,7 +91,9 @@ def _convert_to_cohere_tool( description=param_definition.get("description") if "description" in param_definition else "", - type=param_definition.get("type"), + type=JSON_TO_PYTHON_TYPES.get( + param_definition.get("type"), param_definition.get("type") + ), required="default" not in param_definition, ) for param_name, param_definition in tool.args.items() @@ -103,7 +110,9 @@ def _convert_to_cohere_tool( parameter_definitions={ param_name: ToolParameterDefinitionsValue( description=param_definition.get("description"), - type=param_definition.get("type"), + type=JSON_TO_PYTHON_TYPES.get( + param_definition.get("type"), param_definition.get("type") + ), required="default" not in param_definition, ) for param_name, param_definition in tool.get("properties", {}).items() @@ -123,7 +132,9 @@ def _convert_to_cohere_tool( parameter_definitions={ param_name: ToolParameterDefinitionsValue( description=param_definition.get("description"), - type=param_definition.get("type"), + type=JSON_TO_PYTHON_TYPES.get( + param_definition.get("type"), param_definition.get("type") + ), required=param_name in parameters.get("required", []), ) for param_name, param_definition in properties.items() diff --git a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py index 4ea2d05f6755f..187babb1edda1 100644 --- a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py +++ b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py @@ -14,6 +14,7 @@ from langchain_core.runnables import Runnable, RunnablePassthrough from langchain_core.tools import BaseTool +from langchain_cohere.cohere_agent import JSON_TO_PYTHON_TYPES from langchain_cohere.react_multi_hop.prompt import ( multi_hop_prompt_template, render_structured_preamble, @@ -197,10 +198,11 @@ def parse(self, text: str) -> Union[List[AgentAction], AgentFinish]: def get_type(type_: str, is_optional: bool) -> str: + python_type = JSON_TO_PYTHON_TYPES.get(type_, type_) if is_optional: - return f"Optional[{type_}]" + return f"Optional[{python_type}]" else: - return type_ + return python_type def get_tool_signature(tool: BaseTool) -> str: diff --git a/libs/partners/cohere/tests/unit_tests/test_cohere_agent.py b/libs/partners/cohere/tests/unit_tests/test_cohere_agent.py index 9dc082a55e671..e3bc37a8dae82 100644 --- a/libs/partners/cohere/tests/unit_tests/test_cohere_agent.py +++ b/libs/partners/cohere/tests/unit_tests/test_cohere_agent.py @@ -12,17 +12,17 @@ "arg_1": { "description": "Arg1 description", "required": True, - "type": "string", + "type": "str", }, "optional_arg_2": { "description": "Arg2 description", "required": False, - "type": "string", + "type": "str", }, "arg_3": { "description": "Arg3 description", "required": True, - "type": "integer", + "type": "int", }, }, } From ec58586af2b9b11d17d6780f5729e2a8eea063dc Mon Sep 17 00:00:00 2001 From: Harry M <127103098+harry-cohere@users.noreply.github.com> Date: Fri, 29 Mar 2024 18:30:17 +0000 Subject: [PATCH 23/27] add resilience to action parsing --- libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py index 187babb1edda1..c2063b569c87c 100644 --- a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py +++ b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py @@ -72,7 +72,7 @@ def parse_jsonified_tool_use_generation( """ def _extract_codeblocks_from_md(text: str) -> List[str]: - return re.findall(r"```([^`]*)```", text) + return re.findall(r"`{3}([^`]*)`{0,3}", text) raw_generation = re.sub(f"^{tool_use_prefix} ", "", tool_use_generation) code_block_sections = _extract_codeblocks_from_md(raw_generation) From 403f78a803f6f3278818edc6d112b8aef363821c Mon Sep 17 00:00:00 2001 From: Harry M <127103098+harry-cohere@users.noreply.github.com> Date: Fri, 29 Mar 2024 19:13:02 +0000 Subject: [PATCH 24/27] prompt rendering changes --- .../langchain_cohere/react_multi_hop/agent.py | 6 ++++-- .../langchain_cohere/react_multi_hop/prompt.py | 18 +++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py index c2063b569c87c..7568966d4cf78 100644 --- a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py +++ b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py @@ -214,7 +214,7 @@ def get_tool_signature(tool: BaseTool) -> str: ) args.append(f"{parameter_name}: {type_}") signature = ", ".join(args) - return f"def {tool.name}({signature}) -> List[Dict]" + return f"def {tool.name}({signature}) -> List[Dict]:" def get_tool_args(tool: BaseTool) -> str: @@ -228,7 +228,8 @@ def get_tool_args(tool: BaseTool) -> str: ) description = parameter_definition.get("description") rendered_args.append(f"{parameter_name} ({type_}): {description}") - return "\n ".join(rendered_args) + indent = " " * 12 + return "\n\n" + f"\n{indent}".join(rendered_args) def render_chat_history(chat_history: List[BaseMessage]) -> str: @@ -258,6 +259,7 @@ def render_tool_description(tool: BaseTool) -> str: def calculator_calc(expression: str) -> List[Dict]: \"\"\"This is a powerful multi-purpose calculator. It is capable of a wide array of math calculation and a range of features. + Args: expression (str): The expression for the calculator to evaluate. diff --git a/libs/partners/cohere/langchain_cohere/react_multi_hop/prompt.py b/libs/partners/cohere/langchain_cohere/react_multi_hop/prompt.py index f95b825679d91..d1d63b5679234 100644 --- a/libs/partners/cohere/langchain_cohere/react_multi_hop/prompt.py +++ b/libs/partners/cohere/langchain_cohere/react_multi_hop/prompt.py @@ -13,24 +13,20 @@ default_system_prefix = """<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>""" -overridable_preamble = """### Task And Context +overridable_preamble = """## Task And Context {TASK_CONTEXT} -### Style Guide +## Style Guide {STYLE_GUIDE}""" -structured_preamble_template = """{SYSTEM_PREFIX}# Introduction: - -This document details the task you must accomplish. Read it carefully and always follow its instructions. - -## Safety Preamble +structured_preamble_template = """{SYSTEM_PREFIX}# Safety Preamble {SAFETY_PREAMBLE} -## System Preamble -### Basic Rules +# System Preamble +## Basic Rules {BASIC_RULES} -## User Preamble +# User Preamble {USER_PREAMBLE}""" @@ -70,7 +66,7 @@ def render_structured_preamble( multi_hop_prompt_template = PromptTemplate.from_template( """{structured_preamble} -### Available Tools +## Available Tools Here is a list of tools that you have available to you: {tools}<|END_OF_TURN_TOKEN|>{history}<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{user_prompt}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{multi_hop_instruction}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>{steps}""" From 8f8d8f0bf2f89d73d72550eece2880fc55c4019d Mon Sep 17 00:00:00 2001 From: Harry M <127103098+harry-cohere@users.noreply.github.com> Date: Fri, 29 Mar 2024 19:17:42 +0000 Subject: [PATCH 25/27] prompt rendering changes --- libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py index 7568966d4cf78..cdc0338b17c94 100644 --- a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py +++ b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py @@ -304,7 +304,7 @@ def format_cohere_log_to_str( last_log = action.log if step_i > 0: thoughts += "\n" - observation_str = f"Document {result_idx}\n{observation}" + observation_str = f"Document: {result_idx}\n{observation}" result_idx += 1 thoughts += f"{observation_prefix}{observation_str}{llm_prefix}" From a6f445d08bd3ec8fa7347966840d2ce70c10eade Mon Sep 17 00:00:00 2001 From: Harry M <127103098+harry-cohere@users.noreply.github.com> Date: Fri, 29 Mar 2024 19:34:06 +0000 Subject: [PATCH 26/27] fix types --- .../langchain_cohere/react_multi_hop/prompt.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libs/partners/cohere/langchain_cohere/react_multi_hop/prompt.py b/libs/partners/cohere/langchain_cohere/react_multi_hop/prompt.py index d1d63b5679234..cdec9533f8a9b 100644 --- a/libs/partners/cohere/langchain_cohere/react_multi_hop/prompt.py +++ b/libs/partners/cohere/langchain_cohere/react_multi_hop/prompt.py @@ -1,5 +1,7 @@ # flake8: noqa from datetime import datetime +from typing import Optional + from langchain_core.prompts import PromptTemplate default_basic_rules = "You are a powerful language agent trained by Cohere to help people. You are capable of complex reasoning and augmented with a number of tools. Your job is to plan and reason about how you will use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see an instruction informing you what kind of response to generate. You will construct a plan and then perform a number of reasoning and action steps to solve the problem. When you have determined the answer to the user's request, you will cite your sources in your answers, according the instructions." @@ -31,11 +33,11 @@ def render_structured_preamble( - user_preamble: str, - system_prefix: str = default_system_prefix, - basic_rules: str = default_basic_rules, - task_context: str = default_task_context, - safety_rules: str = default_safety_rules, + user_preamble: Optional[str] = None, + system_prefix: Optional[str] = default_system_prefix, + basic_rules: Optional[str] = default_basic_rules, + task_context: Optional[str] = default_task_context, + safety_rules: Optional[str] = default_safety_rules, ) -> str: if user_preamble is None: user_preamble = overridable_preamble.format( From 610d9c4cbd48d1bfe38804e7d1a9fcf1ae3d8be8 Mon Sep 17 00:00:00 2001 From: Harry M <127103098+harry-cohere@users.noreply.github.com> Date: Fri, 29 Mar 2024 20:22:31 +0000 Subject: [PATCH 27/27] don't nest prompt function --- .../langchain_cohere/react_multi_hop/agent.py | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py index cdc0338b17c94..66a6d2982b263 100644 --- a/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py +++ b/libs/partners/cohere/langchain_cohere/react_multi_hop/agent.py @@ -1,7 +1,7 @@ import json import logging import re -from typing import Dict, List, Sequence, Tuple, Union +from typing import Callable, Dict, List, Sequence, Tuple, Union from langchain_core.agents import AgentAction, AgentFinish from langchain_core.language_models import BaseLanguageModel @@ -32,23 +32,12 @@ def create_cohere_react_agent( tools: Sequence[BaseTool], prompt: ChatPromptTemplate, ) -> Runnable: - def multi_hop_prompt(x: Dict) -> BasePromptTemplate: - return multi_hop_prompt_template.partial( - structured_preamble=render_structured_preamble( - user_preamble=x.get("preamble", None) - ), - tools="\n".join([render_tool_description(t) for t in tools]), - user_prompt=prompt.invoke(x).to_string(), - steps=format_cohere_log_to_str(x["intermediate_steps"]), - history=render_chat_history(x.get("chat_history", [])), - ) - agent = ( RunnablePassthrough.assign( # Handled in the multi_hop_prompt agent_scratchpad=lambda _: [], ) - | multi_hop_prompt + | _multi_hop_prompt(tools=tools, prompt=prompt) | llm.bind(stop=["\nObservation:"], raw_prompting=True) | CohereToolsReactAgentOutputParser() ) @@ -309,3 +298,20 @@ def format_cohere_log_to_str( thoughts += f"{observation_prefix}{observation_str}{llm_prefix}" return thoughts + + +def _multi_hop_prompt( + tools: Sequence[BaseTool], prompt: ChatPromptTemplate +) -> Callable: + def inner(x: Dict) -> BasePromptTemplate: + return multi_hop_prompt_template.partial( + structured_preamble=render_structured_preamble( + user_preamble=x.get("preamble", None) + ), + tools="\n".join([render_tool_description(t) for t in tools]), + user_prompt=prompt.invoke(x).to_string(), + steps=format_cohere_log_to_str(x["intermediate_steps"]), + history=render_chat_history(x.get("chat_history", [])), + ) + + return inner