Skip to content

Commit

Permalink
Fix bad tuple in plan and execute docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Aug 25, 2024
1 parent 70fa16a commit d966aad
Showing 1 changed file with 119 additions and 151 deletions.
270 changes: 119 additions & 151 deletions examples/plan-and-execute/plan-and-execute.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 3,
"id": "10e49ce6",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -139,7 +139,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"id": "18a13860",
"metadata": {},
"outputs": [],
Expand All @@ -163,7 +163,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 5,
"id": "bfa0509d",
"metadata": {},
"outputs": [],
Expand All @@ -179,92 +179,86 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 6,
"id": "93d6c87e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" messages: [\n",
" 'user',\n",
" 'who is the winner of the us open',\n",
" AIMessage {\n",
" \"id\": \"chatcmpl-9yp7dHIgCdRgsJ1Ie58wdLpT5llsR\",\n",
" \"content\": \"\",\n",
" \"additional_kwargs\": {\n",
" \"tool_calls\": [\n",
" {\n",
" \"id\": \"call_OgRCeSGYwBxBDnjUjmYmtGH6\",\n",
" \"type\": \"function\",\n",
" \"function\": \"[Object]\"\n",
" }\n",
" ]\n",
" },\n",
" \"response_metadata\": {\n",
" \"tokenUsage\": {\n",
" \"completionTokens\": 24,\n",
" \"promptTokens\": 85,\n",
" \"totalTokens\": 109\n",
" },\n",
" \"finish_reason\": \"tool_calls\",\n",
" \"system_fingerprint\": \"fp_3aa7262c27\"\n",
" },\n",
" \"tool_calls\": [\n",
" {\n",
" \"name\": \"tavily_search_results_json\",\n",
" \"args\": {\n",
" \"input\": \"winner of US Open 2023\"\n",
" },\n",
" \"type\": \"tool_call\",\n",
" \"id\": \"call_OgRCeSGYwBxBDnjUjmYmtGH6\"\n",
" }\n",
" ],\n",
" \"invalid_tool_calls\": [],\n",
" \"usage_metadata\": {\n",
" \"input_tokens\": 85,\n",
" \"output_tokens\": 24,\n",
" \"total_tokens\": 109\n",
" }\n",
" },\n",
" ToolMessage {\n",
" \"content\": \"[{\\\"title\\\":\\\"How Wyndham Clark won the 2023 U.S. Open over Rory McIlroy, Scottie ...\\\",\\\"url\\\":\\\"https://www.nytimes.com/athletic/live-blogs/us-open-leaderboard-live-scores-results-tee-times/mhPUFgLsyFfM/\\\",\\\"content\\\":\\\"Wyndham Clark is your 2023 U.S. Open champion. Wyndham Clark has won his first major championship, besting some of the best players in the world on Sunday at Los Angeles Country Club to claim the ...\\\",\\\"score\\\":0.9980277,\\\"raw_content\\\":null},{\\\"title\\\":\\\"2023 U.S. Open leaderboard: Wyndham Clark breaks through edging Rory ...\\\",\\\"url\\\":\\\"https://www.cbssports.com/golf/news/2023-u-s-open-leaderboard-wyndham-clark-breaks-through-edging-rory-mcilroy-for-first-major-championship/live/\\\",\\\"content\\\":\\\"College Pick'em\\\\nA Daily SportsLine Betting Podcast\\\\nNFL Playoff Time!\\\\n2023 U.S. Open leaderboard: Wyndham Clark breaks through edging Rory McIlroy for first major championship\\\\nClark beat one of the game's best clinching his second PGA Tour victory, both in the last six weeks\\\\nWith Rickie Fowler, Rory McIlroy and Scottie Scheffler atop the 2023 U.S. Open leaderboard, it appeared as if Los Angeles Country Club was set to crown a shining star as its national champion. After making birdie on No. 1 to momentarily pull even with the leaders, McIlroy was unable to take advantage of the short par-4 6th before leaving one on the table on the par-5 8th when his birdie putt from less than four feet failed to even touch the hole.\\\\n The shot on 14 was kind of the shot of the week for me -- to make a birdie there and grind it on the way in. The Champion Golfer of the Year now goes to defend the Claret Jug at Hoylake where he will relish the opportunity to put his creativity and imagination on display again.\\\\n Instead, the City of Angels saw a breakout performance from perhaps one of the game's rising stars as 29-year-old Wyndham Clark (-10) outlasted the veteran McIlroy (-9) to capture his first major championship and clinch his second professional victory.\\\\n\\\",\\\"score\\\":0.9956685,\\\"raw_content\\\":null},{\\\"title\\\":\\\"U.S. Open 2023 Golf Leaderboard - PGA TOUR\\\",\\\"url\\\":\\\"https://www.pgatour.com/tournaments/2023/u.s-open/R2023026\\\",\\\"content\\\":\\\"PGA TOUR Live Leaderboard 2023 U.S. Open, Los Angeles - Golf Scores and Results. ... Jun 15 - 18, 2023. 67°F. Leaderboard Highlights Tee Times Field FedExCup Course Stats Odds Past Results Overview.\\\",\\\"score\\\":0.97631055,\\\"raw_content\\\":null}]\",\n",
" \"name\": \"tavily_search_results_json\",\n",
" \"additional_kwargs\": {},\n",
" \"response_metadata\": {},\n",
" \"tool_call_id\": \"call_OgRCeSGYwBxBDnjUjmYmtGH6\"\n",
" },\n",
" AIMessage {\n",
" \"id\": \"chatcmpl-9yp7u9o6FOKpPpLSSmVd2W1yxnHUf\",\n",
" \"content\": \"Wyndham Clark is the winner of the 2023 U.S. Open, securing his first major championship by outlasting Rory McIlroy at the Los Angeles Country Club.\",\n",
" \"additional_kwargs\": {},\n",
" \"response_metadata\": {\n",
" \"tokenUsage\": {\n",
" \"completionTokens\": 36,\n",
" \"promptTokens\": 724,\n",
" \"totalTokens\": 760\n",
" },\n",
" \"finish_reason\": \"stop\",\n",
" \"system_fingerprint\": \"fp_df84d6bd70\"\n",
" },\n",
" \"tool_calls\": [],\n",
" \"invalid_tool_calls\": [],\n",
" \"usage_metadata\": {\n",
" \"input_tokens\": 724,\n",
" \"output_tokens\": 36,\n",
" \"total_tokens\": 760\n",
" }\n",
" }\n",
" ]\n",
"}\n"
]
"data": {
"text/plain": [
"{\n",
" messages: [\n",
" HumanMessage {\n",
" \"content\": \"who is the winner of the us open\",\n",
" \"additional_kwargs\": {},\n",
" \"response_metadata\": {}\n",
" },\n",
" AIMessage {\n",
" \"content\": \"\",\n",
" \"additional_kwargs\": {\n",
" \"tool_calls\": [\n",
" {\n",
" \"id\": \"call_c2N7Z1RX31qKJaSlpOJ0K7Wm\",\n",
" \"type\": \"function\",\n",
" \"function\": \"[Object]\"\n",
" }\n",
" ]\n",
" },\n",
" \"response_metadata\": {\n",
" \"tokenUsage\": {\n",
" \"completionTokens\": 25,\n",
" \"promptTokens\": 80,\n",
" \"totalTokens\": 105\n",
" },\n",
" \"finish_reason\": \"tool_calls\"\n",
" },\n",
" \"tool_calls\": [\n",
" {\n",
" \"name\": \"tavily_search_results_json\",\n",
" \"args\": {\n",
" \"input\": \"winner of the US Open 2023\"\n",
" },\n",
" \"type\": \"tool_call\",\n",
" \"id\": \"call_c2N7Z1RX31qKJaSlpOJ0K7Wm\"\n",
" }\n",
" ],\n",
" \"invalid_tool_calls\": []\n",
" },\n",
" ToolMessage {\n",
" \"content\": \"[{\\\"title\\\":\\\"How Wyndham Clark won the 2023 U.S. Open over Rory McIlroy, Scottie ...\\\",\\\"url\\\":\\\"https://www.nytimes.com/athletic/live-blogs/us-open-leaderboard-live-scores-results-tee-times/mhPUFgLsyFfM/\\\",\\\"content\\\":\\\"Wyndham Clark is your 2023 U.S. Open champion. Wyndham Clark has won his first major championship, besting some of the best players in the world on Sunday at Los Angeles Country Club to claim the ...\\\",\\\"score\\\":0.9981324,\\\"raw_content\\\":null},{\\\"title\\\":\\\"Championship Point | Coco Gauff Wins Women's Singles Title | 2023 US Open\\\",\\\"url\\\":\\\"https://www.youtube.com/watch?v=rZ0XQWWFIAo\\\",\\\"content\\\":\\\"The moment Coco Gauff beat Aryna Sabalenka in the final of the 2023 US Open.Don't miss a moment of the US Open! Subscribe now: https://bit.ly/2Pdr81iThe 2023...\\\",\\\"score\\\":0.997459,\\\"raw_content\\\":null},{\\\"title\\\":\\\"2023 U.S. Open leaderboard: Wyndham Clark breaks through edging Rory ...\\\",\\\"url\\\":\\\"https://www.cbssports.com/golf/news/2023-u-s-open-leaderboard-wyndham-clark-breaks-through-edging-rory-mcilroy-for-first-major-championship/live/\\\",\\\"content\\\":\\\"College Pick'em\\\\nA Daily SportsLine Betting Podcast\\\\nNFL Playoff Time!\\\\n2023 U.S. Open leaderboard: Wyndham Clark breaks through edging Rory McIlroy for first major championship\\\\nClark beat one of the game's best clinching his second PGA Tour victory, both in the last six weeks\\\\nWith Rickie Fowler, Rory McIlroy and Scottie Scheffler atop the 2023 U.S. Open leaderboard, it appeared as if Los Angeles Country Club was set to crown a shining star as its national champion. After making birdie on No. 1 to momentarily pull even with the leaders, McIlroy was unable to take advantage of the short par-4 6th before leaving one on the table on the par-5 8th when his birdie putt from less than four feet failed to even touch the hole.\\\\n The shot on 14 was kind of the shot of the week for me -- to make a birdie there and grind it on the way in. The Champion Golfer of the Year now goes to defend the Claret Jug at Hoylake where he will relish the opportunity to put his creativity and imagination on display again.\\\\n Instead, the City of Angels saw a breakout performance from perhaps one of the game's rising stars as 29-year-old Wyndham Clark (-10) outlasted the veteran McIlroy (-9) to capture his first major championship and clinch his second professional victory.\\\\n\\\",\\\"score\\\":0.99586606,\\\"raw_content\\\":null}]\",\n",
" \"name\": \"tavily_search_results_json\",\n",
" \"additional_kwargs\": {},\n",
" \"response_metadata\": {},\n",
" \"tool_call_id\": \"call_c2N7Z1RX31qKJaSlpOJ0K7Wm\"\n",
" },\n",
" AIMessage {\n",
" \"content\": \"The winners of the 2023 US Open are:\\n\\n- **Men's Singles**: Wyndham Clark, who won his first major championship.\\n- **Women's Singles**: Coco Gauff, who defeated Aryna Sabalenka in the final.\",\n",
" \"additional_kwargs\": {},\n",
" \"response_metadata\": {\n",
" \"tokenUsage\": {\n",
" \"completionTokens\": 50,\n",
" \"promptTokens\": 717,\n",
" \"totalTokens\": 767\n",
" },\n",
" \"finish_reason\": \"stop\"\n",
" },\n",
" \"tool_calls\": [],\n",
" \"invalid_tool_calls\": []\n",
" }\n",
" ]\n",
"}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import { HumanMessage } from \"@langchain/core/messages\";\n",
"\n",
"await agentExecutor.invoke({\n",
" messages: [\"user\", \"who is the winner of the us open\"],\n",
" messages: [new HumanMessage(\"who is the winner of the us open\")],\n",
"});\n"
]
},
Expand All @@ -281,7 +275,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 7,
"id": "44b5b660",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -310,7 +304,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 8,
"id": "7ba67c92",
"metadata": {},
"outputs": [],
Expand All @@ -334,21 +328,25 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 9,
"id": "53fec065",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" steps: [\n",
" 'Identify the current Australia Open winner.',\n",
" 'Find out the hometown of the identified winner.'\n",
" ]\n",
"}\n"
]
"data": {
"text/plain": [
"{\n",
" steps: [\n",
" \u001b[32m\"Identify the current Australia Open winner.\"\u001b[39m,\n",
" \u001b[32m\"Research the hometown of the identified Australia Open winner.\"\u001b[39m,\n",
" \u001b[32m\"Report the hometown of the Australia Open winner.\"\u001b[39m\n",
" ]\n",
"}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
Expand All @@ -370,7 +368,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 10,
"id": "2fb888fa",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -434,7 +432,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"id": "ef97a3ea",
"metadata": {},
"outputs": [],
Expand All @@ -448,7 +446,7 @@
"): Promise<Partial<typeof PlanExecuteState.State>> {\n",
" const task = state.plan[0];\n",
" const input = {\n",
" messages: [\"user\", task],\n",
" messages: [new HumanMessage(task)],\n",
" };\n",
" const { messages } = await agentExecutor.invoke(input, config);\n",
"\n",
Expand Down Expand Up @@ -508,7 +506,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"id": "b4bb886e",
"metadata": {},
"outputs": [
Expand All @@ -519,64 +517,37 @@
"{\n",
" planner: {\n",
" plan: [\n",
" 'Determine the winner of the 2024 Australian Open.',\n",
" 'Find out the hometown of the determined winner.',\n",
" 'Present the hometown as the final answer.'\n",
" ]\n",
" }\n",
"}\n",
"{\n",
" agent: {\n",
" plan: [\n",
" 'Find out the hometown of the determined winner.',\n",
" 'Present the hometown as the final answer.'\n",
" ],\n",
" pastSteps: [ [Array] ]\n",
" }\n",
"}\n",
"{\n",
" replan: {\n",
" plan: [\n",
" 'Find out the hometown of Jannik Sinner.',\n",
" 'Find out the hometown of Aryna Sabalenka.',\n",
" 'Present the hometowns as the final answer.'\n",
" \"Identify the winner of the 2024 Australian Open.\",\n",
" \"Research the hometown of the identified winner.\"\n",
" ]\n",
" }\n",
"}\n",
"{\n",
" agent: {\n",
" plan: [\n",
" 'Find out the hometown of Aryna Sabalenka.',\n",
" 'Present the hometowns as the final answer.'\n",
" ],\n",
" pastSteps: [ [Array] ]\n",
" }\n",
"}\n",
"{\n",
" replan: {\n",
" plan: [\n",
" 'Find out the hometown of Aryna Sabalenka.',\n",
" 'Present the hometown of Aryna Sabalenka as the final answer.'\n",
" plan: [ \"Research the hometown of the identified winner.\" ],\n",
" pastSteps: [\n",
" [\n",
" \"Identify the winner of the 2024 Australian Open.\",\n",
" \"The winner of the 2024 Australian Open men's singles title is Jannik Sinner of Italy. He achieved a \"... 175 more characters\n",
" ]\n",
" ]\n",
" }\n",
"}\n",
"{ replan: { plan: [ \"Research the hometown of Jannik Sinner.\" ] } }\n",
"{\n",
" agent: {\n",
" plan: [ 'Present the hometown of Aryna Sabalenka as the final answer.' ],\n",
" pastSteps: [ [Array] ]\n",
" }\n",
"}\n",
"{\n",
" replan: {\n",
" plan: [\n",
" 'Return that the hometowns of the 2024 Australian Open winners are Sexten, Italy for Jannik Sinner and Minsk, Belarus for Aryna Sabalenka.'\n",
" plan: [],\n",
" pastSteps: [\n",
" [\n",
" \"Research the hometown of Jannik Sinner.\",\n",
" \"Jannik Sinner's hometown is Sexten (also known as Sesto) in northern Italy. Located in the Dolomites\"... 126 more characters\n",
" ]\n",
" ]\n",
" }\n",
"}\n",
"{ agent: { plan: [], pastSteps: [ [Array] ] } }\n",
"{\n",
" replan: {\n",
" response: 'The hometowns of the 2024 Australian Open winners are Sexten, Italy for Jannik Sinner and Minsk, Belarus for Aryna Sabalenka.'\n",
" response: \"The objective has been achieved. The hometown of the 2024 Australian Open winner, Jannik Sinner, is \"... 47 more characters\n",
" }\n",
"}\n"
]
Expand All @@ -598,7 +569,7 @@
"id": "2da7f2be",
"metadata": {},
"source": [
"> #### See the LangSmith trace [here](https://smith.langchain.com/public/2f43e8bb-56b8-46da-b059-c0f4c6e43cbb/r).\n"
"> #### See the LangSmith trace [here](https://smith.langchain.com/public/5bb4f582-d111-417d-ba91-29bcced272bb/r).\n"
]
}
],
Expand All @@ -612,20 +583,17 @@
}
},
"kernelspec": {
"display_name": "TypeScript",
"display_name": "Deno",
"language": "typescript",
"name": "tslab"
"name": "deno"
},
"language_info": {
"codemirror_mode": {
"mode": "typescript",
"name": "javascript",
"typescript": true
},
"file_extension": ".ts",
"mimetype": "text/typescript",
"mimetype": "text/x.typescript",
"name": "typescript",
"version": "3.7.2"
"nb_converter": "script",
"pygments_lexer": "typescript",
"version": "5.3.3"
}
},
"nbformat": 4,
Expand Down

0 comments on commit d966aad

Please sign in to comment.