mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-07 18:27:52 +02:00
Update plan-and-execute
This commit is contained in:
@@ -13,6 +13,9 @@
|
||||
"After accomplishing a particular task, you can then revisit the plan and modify as appropriate.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"The general computational graph looks like the following:\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
@@ -20,7 +23,10 @@
|
||||
"The advantages of this \"plan-and-execute\" style agent are:\n",
|
||||
"\n",
|
||||
"1. Explicit long term planning (which even really strong LLMs can struggle with)\n",
|
||||
"2. Ability to use smaller/weaker models for the execution step, only using larger/better models for the planning step"
|
||||
"2. Ability to use smaller/weaker models for the execution step, only using larger/better models for the planning step\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"The following walkthrough demonstrates how to do so in LangGraph. The resulting agent will leave a trace like the following example: ([link](https://smith.langchain.com/public/d46e24d3-dda6-44d5-9550-b618fca4e0d4/r))."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -63,7 +69,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 3,
|
||||
"id": "ce438281-08d5-4804-afe7-e4089f7b016b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -85,25 +91,14 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 4,
|
||||
"id": "01f460d1-f26f-47d1-ae76-de74d5d851de",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\n",
|
||||
"os.environ[\"LANGCHAIN_API_KEY\"] = getpass.getpass(\"LangSmith API Key:\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 37,
|
||||
"id": "e475c7f9-4c46-4f21-8ba6-2e4d67b09cae",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"os.environ[\"LANGCHAIN_PROJECT\"] = \"brex\""
|
||||
"os.environ[\"LANGCHAIN_API_KEY\"] = getpass.getpass(\"LangSmith API Key:\")\n",
|
||||
"os.environ[\"LANGCHAIN_PROJECT\"] = \"Plan-and-execute\""
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -118,7 +113,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 38,
|
||||
"execution_count": 5,
|
||||
"id": "25b9ec62-0675-4715-811c-9b32c635b22f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -141,7 +136,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 39,
|
||||
"execution_count": 6,
|
||||
"id": "72d233ca-1dbf-4b43-b680-b3bf39e3691f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -160,7 +155,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 40,
|
||||
"execution_count": 7,
|
||||
"id": "a3ea9bd3-87d9-4a78-aec6-8ab4bf34479b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -170,7 +165,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 41,
|
||||
"execution_count": 8,
|
||||
"id": "998aebde-c204-494f-930c-14747ed34861",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -180,7 +175,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 42,
|
||||
"execution_count": 9,
|
||||
"id": "746e697a-dec4-4342-a814-9b3456828169",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -189,12 +184,12 @@
|
||||
"text/plain": [
|
||||
"{'input': 'who is the winnner of the us open',\n",
|
||||
" 'chat_history': [],\n",
|
||||
" 'agent_outcome': AgentFinish(return_values={'output': 'The winners of the US Open in 2023 are:\\n\\n- For tennis, Coco Gauff won her first Grand Slam title at the US Open 2023 with a comeback victory against Aryna Sabalenka. [Source](https://sports.yahoo.com/us-open-2023-coco-gauff-wins-1st-grand-slam-title-with-wild-comeback-vs-aryna-sabalenka-222431287.html)\\n\\n- In golf, Wyndham Clark won the 2023 US Open, marking his first major championship victory. The tournament took place at the Los Angeles Country Club. [Source](https://www.nbclosangeles.com/news/sports/golf/wyndham-clark-wins-2023-us-open-for-first-major-championship/3172672/)'}, log='The winners of the US Open in 2023 are:\\n\\n- For tennis, Coco Gauff won her first Grand Slam title at the US Open 2023 with a comeback victory against Aryna Sabalenka. [Source](https://sports.yahoo.com/us-open-2023-coco-gauff-wins-1st-grand-slam-title-with-wild-comeback-vs-aryna-sabalenka-222431287.html)\\n\\n- In golf, Wyndham Clark won the 2023 US Open, marking his first major championship victory. The tournament took place at the Los Angeles Country Club. [Source](https://www.nbclosangeles.com/news/sports/golf/wyndham-clark-wins-2023-us-open-for-first-major-championship/3172672/)'),\n",
|
||||
" 'agent_outcome': AgentFinish(return_values={'output': 'The winners of the US Open in 2023 are as follows:\\n\\n- **Golf:** Wyndham Clark won the 2023 US Open in golf, holding his nerve against Rory McIlroy.\\n \\n- **Tennis:** The 2023 US Open tennis tournament details include information about the event and its prize money, but the winner has not been specified in the provided information. As of the last update, Carlos Alcaraz won the 2022 US Open tennis title.'}, log='The winners of the US Open in 2023 are as follows:\\n\\n- **Golf:** Wyndham Clark won the 2023 US Open in golf, holding his nerve against Rory McIlroy.\\n \\n- **Tennis:** The 2023 US Open tennis tournament details include information about the event and its prize money, but the winner has not been specified in the provided information. As of the last update, Carlos Alcaraz won the 2022 US Open tennis title.'),\n",
|
||||
" 'intermediate_steps': [(AgentActionMessageLog(tool='tavily_search_results_json', tool_input={'query': 'US Open winner 2023'}, log=\"\\nInvoking: `tavily_search_results_json` with `{'query': 'US Open winner 2023'}`\\n\\n\\n\", message_log=[AIMessage(content='', additional_kwargs={'function_call': {'arguments': '{\"query\":\"US Open winner 2023\"}', 'name': 'tavily_search_results_json'}})]),\n",
|
||||
" '[{\\'url\\': \\'https://sports.yahoo.com/us-open-2023-coco-gauff-wins-1st-grand-slam-title-with-wild-comeback-vs-aryna-sabalenka-222431287.html\\', \\'content\\': \\'— US Open Tennis (@usopen) September 9, 2023 — US Open Tennis (@usopen) September 9, 2023 US Open 2023: Coco Gauff wins 1st Grand Slam title with wild comeback vs. Aryna Sabalenka What a backhand winner from Coco Gauff! pic.twitter.com/JhDcFpsJ4E — US Open Tennis (@usopen) September 9, 2023— US Open Tennis (@usopen) September 9, 2023 Gauff got the momentum change the crowd was looking for early in the second set, breaking Sabalenka to go up 3-1 and holding serve from there to take ...\\'}, {\\'url\\': \\'https://www.nbclosangeles.com/news/sports/golf/wyndham-clark-wins-2023-us-open-for-first-major-championship/3172672/\\', \\'content\\': \"Wyndham Clark wins 2023 US Open for first major championship 2023 US Open features a record purse. Here\\'s how much the winning golfer will make Clark on Sunday claimed the 2023 US Open title at the Los Angeles Country Club, making it his first major championship US Open champion in 2011 and a four-time total major winner -- who recorded a nine-under.Clark on Sunday claimed the 2023 US Open title at the Los Angeles Country Club, making it his first major championship triumph. The 29-year-old finished the tournament going 10-under, just edging ...\"}, {\\'url\\': \\'https://www.sportingnews.com/us/golf/news/us-open-2023-live-scores-results-leaderboard/jbmxrpro5jc37drgq8e2lehn\\', \\'content\\': \\'MORE: Watch the 2023 U.S. Open live with Fubo (free trial) U.S. Open leaderboard 2023 Edition Who won the U.S. Open in 2023? Complete scores, results, highlights from Los Angeles Country Club The golf world headed to the City of Angels — Los Angeles — for the 2023 U.S. Open. MORE:\\\\xa0How much prize money does the U.S. Open winner make?Nick Brinkerhoff 06-19-2023 • 23 min read (Getty Images) The golf world headed to the City of Angels — Los Angeles — for the 2023 U.S. Open. And the tournament got its Hollywood ending....\\'}]')]}"
|
||||
" '[{\\'url\\': \\'https://en.wikipedia.org/wiki/2023_U.S._Open_(golf)\\', \\'content\\': \\'Contents 2023 U.S. Open (golf) was selected to host the 123rd U.S. Open in June 2023. The USGA had made overtures to the club for at least 26 years. Final round[edit] Sunday, June 18, 2023 Third round[edit] Saturday, June 17, 2023Rory McIlroy falls short as Wyndham Clark holds nerve to win 2023 US Open. The Guardian. Archived from the original on June 19, 2023. Retrieved June 20, 2023.\\'}, {\\'url\\': \\'https://en.wikipedia.org/wiki/2023_US_Open_(tennis)\\', \\'content\\': \"The 2023 US Open is the 143rd consecutive edition of the tournament and will take place at the USTA Billie Jean King The total overall prize money for the 2023 US Open totals $65 million, 8% more than the 2022 edition.[4] Contents 2023 US Open (tennis) Wheelchair boys\\' singles Dahnon Ward Wheelchair girls\\' singles Ksénia Chasteau contract with ESPN, in which the broadcaster holds exclusive rights to the entire tournament and the US Open Series.Carlos Alcaraz defeats Casper Ruud for 2022 US Open title, world No. 1 ranking. US Open. Archived from the original on September 12, 2022. Retrieved September\\\\xa0...\"}]')]}"
|
||||
]
|
||||
},
|
||||
"execution_count": 42,
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -223,7 +218,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 43,
|
||||
"execution_count": 10,
|
||||
"id": "8eeeaeea-8f10-4fbe-8e24-4e1a2381a009",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -252,7 +247,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 44,
|
||||
"execution_count": 11,
|
||||
"id": "4a88626d-6dfd-4488-87f0-a9a0dd6da44c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -270,7 +265,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 45,
|
||||
"execution_count": 12,
|
||||
"id": "ec7b1867-1ea3-4df3-9a98-992a1c32ec49",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -292,7 +287,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 46,
|
||||
"execution_count": 13,
|
||||
"id": "67ce37b7-e089-479b-bcb8-c3f5d9874613",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -302,7 +297,7 @@
|
||||
"Plan(steps=['Identify the current year.', 'Search for the Australia Open winner of the current year.', 'Find the hometown of the identified winner.'])"
|
||||
]
|
||||
},
|
||||
"execution_count": 46,
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -325,7 +320,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 47,
|
||||
"execution_count": 14,
|
||||
"id": "ec2d12cc-016a-44d1-aa08-4c5ce1e8fe2a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -376,7 +371,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 48,
|
||||
"execution_count": 15,
|
||||
"id": "6c8e0dad-bcea-4c9a-8922-0d820892e2d0",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -411,7 +406,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 49,
|
||||
"execution_count": 16,
|
||||
"id": "e954cea0-5ccc-46c2-a27b-f5b7185b597d",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -456,7 +451,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 50,
|
||||
"execution_count": 17,
|
||||
"id": "b8ac1f67-e87a-427c-b4f7-44351295b788",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -464,13 +459,15 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"{'plan': ['Identify the winner of the 2024 Australia Open.', \"Research the winner's biography to find their place of birth or hometown.\", 'Confirm the hometown of the 2024 Australia Open winner.']}\n",
|
||||
"{'past_steps': ('Identify the winner of the 2024 Australia Open.', \"The winners of the 2024 Australian Open were Jannik Sinner in the men's singles category and Aryna Sabalenka in the women's singles category.\")}\n",
|
||||
"{'plan': [\"Research Jannik Sinner's biography to find his place of birth or hometown.\", \"Research Aryna Sabalenka's biography to find her place of birth or hometown.\", 'Confirm the hometown of Jannik Sinner.', 'Confirm the hometown of Aryna Sabalenka.']}\n",
|
||||
"{'past_steps': (\"Research Jannik Sinner's biography to find his place of birth or hometown.\", 'Jannik Sinner was born in Innichen, Italy. This town is also known as San Candido, which is mentioned as his hometown.')}\n",
|
||||
"{'plan': [\"Research Aryna Sabalenka's biography to find her place of birth or hometown.\", 'Confirm the hometown of Aryna Sabalenka.']}\n",
|
||||
"{'past_steps': (\"Research Aryna Sabalenka's biography to find her place of birth or hometown.\", 'Aryna Sabalenka was born in Minsk, the capital of Belarus.')}\n",
|
||||
"{'response': 'The hometown of the 2024 Australia Open winners are Innichen (San Candido), Italy for Jannik Sinner and Minsk, Belarus for Aryna Sabalenka. No further steps are needed.'}\n"
|
||||
"{'plan': ['Wait until the 2024 Australian Open concludes.', 'Identify the winner of the 2024 Australian Open.', \"Research the winner's biography to find their hometown.\", 'The hometown of the 2024 Australian Open winner is the result found in the previous step.']}\n",
|
||||
"{'past_steps': ('Wait until the 2024 Australian Open concludes.', \"I can't wait for real-time events. However, I can help you find out the schedule, expected dates, or any other information regarding the 2024 Australian Open. How can I assist you further?\")}\n",
|
||||
"{'plan': ['Identify the winner of the 2024 Australian Open.', \"Research the winner's biography to find their hometown.\", 'The hometown of the 2024 Australian Open winner is the result found in the previous step.']}\n",
|
||||
"{'past_steps': ('Identify the winner of the 2024 Australian Open.', \"The winners of the 2024 Australian Open were Jannik Sinner in the men's singles and Aryna Sabalenka in the women's singles. Jannik Sinner defeated Daniil Medvedev in the final, while specific details about Aryna Sabalenka's match are not provided in the information retrieved.\")}\n",
|
||||
"{'plan': [\"Research Jannik Sinner's biography to find his hometown.\", \"Research Aryna Sabalenka's biography to find her hometown.\", 'The hometowns of the 2024 Australian Open winners are the results found in the previous steps.']}\n",
|
||||
"{'past_steps': (\"Research Jannik Sinner's biography to find his hometown.\", 'Jannik Sinner was born in San Candido (Innichen), Italy, on August 16, 2001. This is considered his hometown.')}\n",
|
||||
"{'plan': [\"Research Aryna Sabalenka's biography to find her hometown.\", 'The hometowns of the 2024 Australian Open winners are the results found in the previous steps.']}\n",
|
||||
"{'past_steps': (\"Research Aryna Sabalenka's biography to find her hometown.\", 'Aryna Sabalenka was born in Minsk, the capital of Belarus.')}\n",
|
||||
"{'response': 'The hometowns of the 2024 Australian Open winners are San Candido (Innichen), Italy for Jannik Sinner, and Minsk, Belarus for Aryna Sabalenka. No further steps are needed as the final answer has been reached.'}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user