mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-31 20:29:46 +02:00
* Create Deploy docs. * Add LangGraph CLI docs. * Update API concepts page. * Create quick start page. * first draft (#695) * first draft * fmt * fmt * Revert "fmt" This reverts commite599030ab5. * Revert "fmt" This reverts commitec8fca977e. * var change * import lint * changed locations * second draft * fmt * Revert "fmt" This reverts commit68a1c5c872. * double texting lint * concepts (#704) * concepts * python sdk * docs structure * fmt * fmt * Small touch ups, rename Hosted LangGraph API to LangGraph Cloud. (#724) * Fix small typos. * Fix broken links in quick start page. * Add LangGraph Cloud reference docs. --------- Co-authored-by: Isaac Francisco <78627776+isahers1@users.noreply.github.com>
173 lines
5.5 KiB
Plaintext
173 lines
5.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Reject\n",
|
|
"\n",
|
|
"There are several strategies for handling concurrent runs in your graph. This notebook covers how to use the `reject` option - please see the other how-to guides in the \"Double Texting\" directory to learn about the other methods.\n",
|
|
"\n",
|
|
"First, let's import our required packages and instantiate our client, assistant, and thread."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import httpx\n",
|
|
"from langchain_core.messages import convert_to_messages\n",
|
|
"from langgraph_sdk import get_client"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"client = get_client()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"assistant = await client.assistants.create(\"agent\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"thread = await client.threads.create()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"run = await client.runs.create(\n",
|
|
" thread[\"thread_id\"],\n",
|
|
" assistant[\"assistant_id\"],\n",
|
|
" input={\"messages\": [{\"role\": \"human\", \"content\": \"whats the weather in sf?\"}]},\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Failed to start concurrent run Client error '409 Conflict' for url 'http://localhost:8123/threads/f9e7088b-8028-4e5c-88d2-9cc9a2870e50/runs'\n",
|
|
"For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"try:\n",
|
|
" await client.runs.create(\n",
|
|
" thread[\"thread_id\"],\n",
|
|
" assistant[\"assistant_id\"],\n",
|
|
" input={\"messages\": [{\"role\": \"human\", \"content\": \"whats the weather in nyc?\"}]},\n",
|
|
" multitask_strategy=\"reject\",\n",
|
|
" )\n",
|
|
"except httpx.HTTPStatusError as e:\n",
|
|
" print(\"Failed to start concurrent run\", e)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"We can verify that the original thread finished executing:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# wait until the original run completes\n",
|
|
"await client.runs.join(thread[\"thread_id\"], run[\"run_id\"])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"state = await client.threads.get_state(thread[\"thread_id\"])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"================================\u001b[1m Human Message \u001b[0m=================================\n",
|
|
"\n",
|
|
"whats the weather in sf?\n",
|
|
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
|
"\n",
|
|
"[{'id': 'toolu_01CyewEifV2Kmi7EFKHbMDr1', 'input': {'query': 'weather in san francisco'}, 'name': 'tavily_search_results_json', 'type': 'tool_use'}]\n",
|
|
"Tool Calls:\n",
|
|
" tavily_search_results_json (toolu_01CyewEifV2Kmi7EFKHbMDr1)\n",
|
|
" Call ID: toolu_01CyewEifV2Kmi7EFKHbMDr1\n",
|
|
" Args:\n",
|
|
" query: weather in san francisco\n",
|
|
"=================================\u001b[1m Tool Message \u001b[0m=================================\n",
|
|
"Name: tavily_search_results_json\n",
|
|
"\n",
|
|
"[{\"url\": \"https://www.accuweather.com/en/us/san-francisco/94103/june-weather/347629\", \"content\": \"Get the monthly weather forecast for San Francisco, CA, including daily high/low, historical averages, to help you plan ahead.\"}]\n",
|
|
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
|
"\n",
|
|
"According to the search results from Tavily, the current weather in San Francisco is:\n",
|
|
"\n",
|
|
"The average high temperature in San Francisco in June is around 65°F (18°C), with average lows around 54°F (12°C). June tends to be one of the cooler and foggier months in San Francisco due to the marine layer of fog that often blankets the city during the summer months.\n",
|
|
"\n",
|
|
"Some key points about the typical June weather in San Francisco:\n",
|
|
"\n",
|
|
"- Mild temperatures with highs in the 60s F and lows in the 50s F\n",
|
|
"- Foggy mornings that often burn off to sunny afternoons\n",
|
|
"- Little to no rainfall, as June falls in the dry season\n",
|
|
"- Breezy conditions, with winds off the Pacific Ocean\n",
|
|
"- Layers are recommended for changing weather conditions\n",
|
|
"\n",
|
|
"So in summary, you can expect mild, foggy mornings giving way to sunny but cool afternoons in San Francisco this time of year. The marine layer keeps temperatures moderate compared to other parts of California in June.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"for m in convert_to_messages(state[\"values\"][\"messages\"]):\n",
|
|
" m.pretty_print()"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"language_info": {
|
|
"name": "python"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|