docs: update cloud how-tos (#747)

This commit is contained in:
Vadym Barda
2024-06-21 14:04:25 -04:00
committed by GitHub
parent f8e7221cae
commit c99b63b9d8
9 changed files with 387 additions and 1759 deletions
+171 -408
View File
@@ -13,7 +13,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "b8e6408a-b37e-428f-9567-077fa55d58e8",
"metadata": {},
"outputs": [],
@@ -26,22 +26,22 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 2,
"id": "4947e9bc-111f-4991-8c41-1041da9bf0ba",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca',\n",
" 'graph_id': 'agent',\n",
" 'config': {},\n",
" 'created_at': '2024-05-18T00:19:39.688822+00:00',\n",
" 'updated_at': '2024-05-18T00:19:39.688822+00:00',\n",
" 'metadata': {'created_by': 'system'}}]"
"{'assistant_id': 'e90fee30-be91-43aa-a33c-d54bd219072e',\n",
" 'graph_id': 'agent',\n",
" 'created_at': '2024-06-18T18:06:55.102231+00:00',\n",
" 'updated_at': '2024-06-18T18:06:55.102231+00:00',\n",
" 'config': {'configurable': {'model_name': 'anthropic'}},\n",
" 'metadata': {}}"
]
},
"execution_count": 7,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
@@ -49,53 +49,36 @@
"source": [
"# List available assistants\n",
"assistants = await client.assistants.search()\n",
"assistants"
"assistants[0]"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 3,
"id": "230c0464-a6e5-420f-9e38-ca514e5634ce",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca',\n",
" 'graph_id': 'agent',\n",
" 'config': {},\n",
" 'created_at': '2024-05-18T00:19:39.688822+00:00',\n",
" 'updated_at': '2024-05-18T00:19:39.688822+00:00',\n",
" 'metadata': {'created_by': 'system'}}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"# Get the first assistant, we will use this one\n",
"assistant = assistants[0]\n",
"assistant"
"# NOTE: we can use `assistant_id` UUID from the above response, or just pass graph ID instead when creating runs. we'll use graph ID here\n",
"assistant_id = \"agent\""
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 4,
"id": "56aa5159-5583-4134-9210-709b969bda6f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'thread_id': '6ada015b-b47a-4c4f-a5cd-580893cb6d0c',\n",
" 'created_at': '2024-05-18T00:50:26.367620+00:00',\n",
" 'updated_at': '2024-05-18T00:50:26.367620+00:00',\n",
"{'thread_id': '5fc20631-47b7-48cd-8aa2-9f2eace9778d',\n",
" 'created_at': '2024-06-21T14:58:02.079462+00:00',\n",
" 'updated_at': '2024-06-21T14:58:02.079462+00:00',\n",
" 'metadata': {}}"
]
},
"execution_count": 10,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
@@ -108,7 +91,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 5,
"id": "147c3f98-f889-4f05-a090-6b31f2a0b291",
"metadata": {},
"outputs": [
@@ -118,7 +101,7 @@
"[]"
]
},
"execution_count": 11,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
@@ -131,35 +114,51 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "8c7b44ef-4816-496d-88a1-2f7327cf576d",
"metadata": {},
"outputs": [],
"source": [
"# Let's kick off a run\n",
"input = {\"messages\": [{\"role\": \"human\", \"content\": \"what's the weather in sf\"}]}\n",
"run = await client.runs.create(thread['thread_id'], assistant[\"assistant_id\"], input=input)\n"
"run = await client.runs.create(thread['thread_id'], assistant_id, input=input)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 7,
"id": "d84b4d80-b0aa-4d9f-a05d-0744b2fe8f72",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'run_id': 'e843abcb-e478-421b-91e1-a8ae171b14f4',\n",
" 'thread_id': '6ada015b-b47a-4c4f-a5cd-580893cb6d0c',\n",
"{'run_id': '1ef2fdea-814c-6165-8b2a-a40e2a028198',\n",
" 'thread_id': '5fc20631-47b7-48cd-8aa2-9f2eace9778d',\n",
" 'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca',\n",
" 'created_at': '2024-05-18T00:50:27.618761+00:00',\n",
" 'updated_at': '2024-05-18T00:50:27.618761+00:00',\n",
" 'created_at': '2024-06-21T14:58:02.095911+00:00',\n",
" 'updated_at': '2024-06-21T14:58:02.095911+00:00',\n",
" 'metadata': {},\n",
" 'status': 'pending',\n",
" 'metadata': {}}"
" 'kwargs': {'input': {'messages': [{'role': 'human',\n",
" 'content': 'what's the weather in sf'}]},\n",
" 'config': {'metadata': {'created_by': 'system'},\n",
" 'configurable': {'run_id': '1ef2fdea-814c-6165-8b2a-a40e2a028198',\n",
" 'user_id': '',\n",
" 'graph_id': 'agent',\n",
" 'thread_id': '5fc20631-47b7-48cd-8aa2-9f2eace9778d',\n",
" 'thread_ts': None,\n",
" 'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca'}},\n",
" 'webhook': None,\n",
" 'temporary': False,\n",
" 'stream_mode': ['events'],\n",
" 'feedback_keys': None,\n",
" 'interrupt_after': None,\n",
" 'interrupt_before': None},\n",
" 'multitask_strategy': 'reject'}"
]
},
"execution_count": 13,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
@@ -171,306 +170,50 @@
},
{
"cell_type": "code",
"execution_count": 14,
"id": "ce124bd3-f197-4b73-9ff6-bb36730dd003",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"[{'event_id': '3ac6d963-442f-481c-9fde-b8a27bc0e277',\n",
" 'run_id': 'e843abcb-e478-421b-91e1-a8ae171b14f4',\n",
" 'received_at': '2024-05-18T00:50:29.570649+00:00',\n",
" 'span_id': 'd4e4a6ee-da2f-4b5f-b656-1a1f73065161',\n",
" 'event': 'on_tool_start',\n",
" 'name': 'tavily_search_results_json',\n",
" 'data': {'input': {'query': 'weather in san francisco'}},\n",
" 'metadata': {'graph_id': 'agent',\n",
" 'thread_id': '6ada015b-b47a-4c4f-a5cd-580893cb6d0c',\n",
" 'created_by': 'system',\n",
" 'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca'},\n",
" 'tags': ['seq:step:1']},\n",
" {'event_id': 'f8961760-6f13-40e6-9eef-6d4d68e0ed19',\n",
" 'run_id': 'e843abcb-e478-421b-91e1-a8ae171b14f4',\n",
" 'received_at': '2024-05-18T00:50:29.569708+00:00',\n",
" 'span_id': '73295bb1-6cd3-403d-abc1-4f9d96a63894',\n",
" 'event': 'on_chain_start',\n",
" 'name': 'action',\n",
" 'data': {},\n",
" 'metadata': {'graph_id': 'agent',\n",
" 'thread_id': '6ada015b-b47a-4c4f-a5cd-580893cb6d0c',\n",
" 'created_by': 'system',\n",
" 'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca'},\n",
" 'tags': ['graph:step:2']},\n",
" {'event_id': '44b5f815-f60c-468f-8d23-96dfdaa0ed20',\n",
" 'run_id': 'e843abcb-e478-421b-91e1-a8ae171b14f4',\n",
" 'received_at': '2024-05-18T00:50:29.568202+00:00',\n",
" 'span_id': 'e843abcb-e478-421b-91e1-a8ae171b14f4',\n",
" 'event': 'on_chain_stream',\n",
" 'name': 'LangGraph',\n",
" 'data': {'chunk': {'messages': [{'id': '46b31c3a-01bf-4946-bd5a-fa6a7f6c97ce',\n",
" 'name': None,\n",
" 'type': 'human',\n",
" 'content': 'what's the weather in sf',\n",
" 'example': False,\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {}},\n",
" {'id': 'run-4885d5a0-cd89-4f00-8558-e85b542a710c',\n",
" 'name': None,\n",
" 'type': 'ai',\n",
" 'content': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'name': 'tavily_search_results_json',\n",
" 'type': 'tool_use',\n",
" 'input': {'query': 'weather in san francisco'}}],\n",
" 'example': False,\n",
" 'tool_calls': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'args': {'query': 'weather in san francisco'},\n",
" 'name': 'tavily_search_results_json'}],\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {},\n",
" 'invalid_tool_calls': []}]}},\n",
" 'metadata': {'graph_id': 'agent',\n",
" 'thread_id': '6ada015b-b47a-4c4f-a5cd-580893cb6d0c',\n",
" 'created_by': 'system',\n",
" 'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca'},\n",
" 'tags': []},\n",
" {'event_id': '0917b31d-f49d-43d4-a8ed-a9eebd8904e8',\n",
" 'run_id': 'e843abcb-e478-421b-91e1-a8ae171b14f4',\n",
" 'received_at': '2024-05-18T00:50:29.566761+00:00',\n",
" 'span_id': 'f469ac2e-17a3-491c-bc03-0c56aa30a68b',\n",
" 'event': 'on_chain_end',\n",
" 'name': 'agent',\n",
" 'data': {'input': {'messages': [{'role': 'human',\n",
" 'content': 'what's the weather in sf'}]},\n",
" 'output': {'messages': [{'id': 'run-4885d5a0-cd89-4f00-8558-e85b542a710c',\n",
" 'name': None,\n",
" 'type': 'ai',\n",
" 'content': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'name': 'tavily_search_results_json',\n",
" 'type': 'tool_use',\n",
" 'input': {'query': 'weather in san francisco'}}],\n",
" 'example': False,\n",
" 'tool_calls': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'args': {'query': 'weather in san francisco'},\n",
" 'name': 'tavily_search_results_json'}],\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {},\n",
" 'invalid_tool_calls': []}]}},\n",
" 'metadata': {'graph_id': 'agent',\n",
" 'thread_id': '6ada015b-b47a-4c4f-a5cd-580893cb6d0c',\n",
" 'created_by': 'system',\n",
" 'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca'},\n",
" 'tags': ['graph:step:1']},\n",
" {'event_id': 'bbe33ebf-04ba-43d5-8718-e2da23295675',\n",
" 'run_id': 'e843abcb-e478-421b-91e1-a8ae171b14f4',\n",
" 'received_at': '2024-05-18T00:50:29.566076+00:00',\n",
" 'span_id': 'f469ac2e-17a3-491c-bc03-0c56aa30a68b',\n",
" 'event': 'on_chain_stream',\n",
" 'name': 'agent',\n",
" 'data': {'chunk': {'messages': [{'id': 'run-4885d5a0-cd89-4f00-8558-e85b542a710c',\n",
" 'name': None,\n",
" 'type': 'ai',\n",
" 'content': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'name': 'tavily_search_results_json',\n",
" 'type': 'tool_use',\n",
" 'input': {'query': 'weather in san francisco'}}],\n",
" 'example': False,\n",
" 'tool_calls': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'args': {'query': 'weather in san francisco'},\n",
" 'name': 'tavily_search_results_json'}],\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {},\n",
" 'invalid_tool_calls': []}]}},\n",
" 'metadata': {'graph_id': 'agent',\n",
" 'thread_id': '6ada015b-b47a-4c4f-a5cd-580893cb6d0c',\n",
" 'created_by': 'system',\n",
" 'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca'},\n",
" 'tags': ['graph:step:1']},\n",
" {'event_id': '38333127-fa97-4830-8157-f76264778d81',\n",
" 'run_id': 'e843abcb-e478-421b-91e1-a8ae171b14f4',\n",
" 'received_at': '2024-05-18T00:50:29.564195+00:00',\n",
" 'span_id': 'ef55c681-be15-4f3d-9aee-3a9ff05d8746',\n",
" 'event': 'on_chain_end',\n",
" 'name': 'should_continue',\n",
" 'data': {'input': {'messages': [{'id': 'abc3581e-417b-4ca1-ab31-de7108e64b3b',\n",
" 'name': None,\n",
" 'type': 'human',\n",
" 'content': 'what's the weather in sf',\n",
" 'example': False,\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {}},\n",
" {'id': 'run-4885d5a0-cd89-4f00-8558-e85b542a710c',\n",
" 'name': None,\n",
" 'type': 'ai',\n",
" 'content': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'name': 'tavily_search_results_json',\n",
" 'type': 'tool_use',\n",
" 'input': {'query': 'weather in san francisco'}}],\n",
" 'example': False,\n",
" 'tool_calls': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'args': {'query': 'weather in san francisco'},\n",
" 'name': 'tavily_search_results_json'}],\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {},\n",
" 'invalid_tool_calls': []}]},\n",
" 'output': 'continue'},\n",
" 'metadata': {'graph_id': 'agent',\n",
" 'thread_id': '6ada015b-b47a-4c4f-a5cd-580893cb6d0c',\n",
" 'created_by': 'system',\n",
" 'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca'},\n",
" 'tags': ['seq:step:3']},\n",
" {'event_id': '408a7785-c715-4bcb-a5aa-950f414baa77',\n",
" 'run_id': 'e843abcb-e478-421b-91e1-a8ae171b14f4',\n",
" 'received_at': '2024-05-18T00:50:29.563289+00:00',\n",
" 'span_id': 'ef55c681-be15-4f3d-9aee-3a9ff05d8746',\n",
" 'event': 'on_chain_start',\n",
" 'name': 'should_continue',\n",
" 'data': {'input': {'messages': [{'id': 'abc3581e-417b-4ca1-ab31-de7108e64b3b',\n",
" 'name': None,\n",
" 'type': 'human',\n",
" 'content': 'what's the weather in sf',\n",
" 'example': False,\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {}},\n",
" {'id': 'run-4885d5a0-cd89-4f00-8558-e85b542a710c',\n",
" 'name': None,\n",
" 'type': 'ai',\n",
" 'content': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'name': 'tavily_search_results_json',\n",
" 'type': 'tool_use',\n",
" 'input': {'query': 'weather in san francisco'}}],\n",
" 'example': False,\n",
" 'tool_calls': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'args': {'query': 'weather in san francisco'},\n",
" 'name': 'tavily_search_results_json'}],\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {},\n",
" 'invalid_tool_calls': []}]}},\n",
" 'metadata': {'graph_id': 'agent',\n",
" 'thread_id': '6ada015b-b47a-4c4f-a5cd-580893cb6d0c',\n",
" 'created_by': 'system',\n",
" 'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca'},\n",
" 'tags': ['seq:step:3']},\n",
" {'event_id': '679c8ae7-5cd2-4462-936e-20f0ea45cfb8',\n",
" 'run_id': 'e843abcb-e478-421b-91e1-a8ae171b14f4',\n",
" 'received_at': '2024-05-18T00:50:29.560628+00:00',\n",
" 'span_id': '4885d5a0-cd89-4f00-8558-e85b542a710c',\n",
" 'event': 'on_chat_model_end',\n",
" 'name': 'ChatAnthropic',\n",
" 'data': {'input': {'messages': [[{'id': None,\n",
" 'name': None,\n",
" 'type': 'human',\n",
" 'content': 'what's the weather in sf',\n",
" 'example': False,\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {}}]]},\n",
" 'output': {'run': None,\n",
" 'llm_output': None,\n",
" 'generations': [[{'text': '',\n",
" 'type': 'ChatGeneration',\n",
" 'message': {'id': 'run-4885d5a0-cd89-4f00-8558-e85b542a710c',\n",
" 'name': None,\n",
" 'type': 'ai',\n",
" 'content': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'name': 'tavily_search_results_json',\n",
" 'type': 'tool_use',\n",
" 'input': {'query': 'weather in san francisco'}}],\n",
" 'example': False,\n",
" 'tool_calls': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'args': {'query': 'weather in san francisco'},\n",
" 'name': 'tavily_search_results_json'}],\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {},\n",
" 'invalid_tool_calls': []},\n",
" 'generation_info': None}]]}},\n",
" 'metadata': {'graph_id': 'agent',\n",
" 'thread_id': '6ada015b-b47a-4c4f-a5cd-580893cb6d0c',\n",
" 'created_by': 'system',\n",
" 'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca',\n",
" 'ls_model_type': 'chat'},\n",
" 'tags': ['seq:step:1']},\n",
" {'event_id': '055fcf73-36e7-444b-990d-6263ec50925c',\n",
" 'run_id': 'e843abcb-e478-421b-91e1-a8ae171b14f4',\n",
" 'received_at': '2024-05-18T00:50:29.559491+00:00',\n",
" 'span_id': '4885d5a0-cd89-4f00-8558-e85b542a710c',\n",
" 'event': 'on_chat_model_stream',\n",
" 'name': 'ChatAnthropic',\n",
" 'data': {'chunk': {'id': 'run-4885d5a0-cd89-4f00-8558-e85b542a710c',\n",
" 'name': None,\n",
" 'type': 'AIMessageChunk',\n",
" 'content': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'name': 'tavily_search_results_json',\n",
" 'type': 'tool_use',\n",
" 'input': {'query': 'weather in san francisco'}}],\n",
" 'example': False,\n",
" 'tool_calls': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'args': {'query': 'weather in san francisco'},\n",
" 'name': 'tavily_search_results_json'}],\n",
" 'tool_call_chunks': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'args': '{\"query\": \"weather in san francisco\"}',\n",
" 'name': 'tavily_search_results_json',\n",
" 'index': 0}],\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {},\n",
" 'invalid_tool_calls': []}},\n",
" 'metadata': {'graph_id': 'agent',\n",
" 'thread_id': '6ada015b-b47a-4c4f-a5cd-580893cb6d0c',\n",
" 'created_by': 'system',\n",
" 'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca',\n",
" 'ls_model_type': 'chat'},\n",
" 'tags': ['seq:step:1']},\n",
" {'event_id': 'cf90f755-5a12-46bd-8f60-adc862388635',\n",
" 'run_id': 'e843abcb-e478-421b-91e1-a8ae171b14f4',\n",
" 'received_at': '2024-05-18T00:50:27.873602+00:00',\n",
" 'span_id': '4885d5a0-cd89-4f00-8558-e85b542a710c',\n",
" 'event': 'on_chat_model_start',\n",
" 'name': 'ChatAnthropic',\n",
" 'data': {'input': {'messages': [[{'id': None,\n",
" 'name': None,\n",
" 'type': 'human',\n",
" 'content': 'what's the weather in sf',\n",
" 'example': False,\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {}}]]}},\n",
" 'metadata': {'graph_id': 'agent',\n",
" 'thread_id': '6ada015b-b47a-4c4f-a5cd-580893cb6d0c',\n",
" 'created_by': 'system',\n",
" 'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca',\n",
" 'ls_model_type': 'chat'},\n",
" 'tags': ['seq:step:1']}]"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 8,
"id": "3639da3c-bfe5-454c-ab1e-8ed7af394dfe",
"metadata": {},
"outputs": [],
"source": [
"# We can list events for the run\n",
"await client.runs.list_events(thread['thread_id'], run['run_id'])"
"# Wait until the run finishes\n",
"await client.runs.join(thread['thread_id'], run['run_id'])"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 9,
"id": "8fa206ed-515e-4607-9a80-bebafe76cc24",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'run_id': 'e843abcb-e478-421b-91e1-a8ae171b14f4',\n",
" 'thread_id': '6ada015b-b47a-4c4f-a5cd-580893cb6d0c',\n",
"{'run_id': '1ef2fdea-814c-6165-8b2a-a40e2a028198',\n",
" 'thread_id': '5fc20631-47b7-48cd-8aa2-9f2eace9778d',\n",
" 'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca',\n",
" 'created_at': '2024-05-18T00:50:27.618761+00:00',\n",
" 'updated_at': '2024-05-18T00:50:27.618761+00:00',\n",
" 'created_at': '2024-06-21T14:58:02.095911+00:00',\n",
" 'updated_at': '2024-06-21T14:58:02.095911+00:00',\n",
" 'metadata': {},\n",
" 'status': 'success',\n",
" 'metadata': {}}"
" 'kwargs': {'input': {'messages': [{'role': 'human',\n",
" 'content': 'what's the weather in sf'}]},\n",
" 'config': {'metadata': {'created_by': 'system'},\n",
" 'configurable': {'run_id': '1ef2fdea-814c-6165-8b2a-a40e2a028198',\n",
" 'user_id': '',\n",
" 'graph_id': 'agent',\n",
" 'thread_id': '5fc20631-47b7-48cd-8aa2-9f2eace9778d',\n",
" 'thread_ts': None,\n",
" 'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca'}},\n",
" 'webhook': None,\n",
" 'temporary': False,\n",
" 'stream_mode': ['events'],\n",
" 'feedback_keys': None,\n",
" 'interrupt_after': None,\n",
" 'interrupt_before': None},\n",
" 'multitask_strategy': 'reject'}"
]
},
"execution_count": 15,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
@@ -482,86 +225,114 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 10,
"id": "8de4495f-7873-487c-b1a8-ad2a78a1ff35",
"metadata": {},
"outputs": [],
"source": [
"# We can get the final results\n",
"results = await client.runs.list_events(thread['thread_id'], run['run_id'])"
"final_result = await client.threads.get_state(thread['thread_id'])"
]
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 11,
"id": "9da76fce-66e4-4f1b-8c24-09759889e50e",
"metadata": {},
"outputs": [],
"source": [
"# The results are sorted by time, so the most recent (final) step is the 0 index\n",
"final_result = results[0]"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "02279ff3-c153-4ec4-be4d-1613a0dff4ee",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'event_id': '1af2076e-8ec7-4f2e-bc2c-6fbbf586397c',\n",
" 'run_id': 'e843abcb-e478-421b-91e1-a8ae171b14f4',\n",
" 'received_at': '2024-05-18T00:50:35.557925+00:00',\n",
" 'span_id': 'e843abcb-e478-421b-91e1-a8ae171b14f4',\n",
" 'event': 'on_chain_end',\n",
" 'name': 'LangGraph',\n",
" 'data': {'output': {'messages': [{'id': '46b31c3a-01bf-4946-bd5a-fa6a7f6c97ce',\n",
" 'name': None,\n",
" 'type': 'human',\n",
" 'content': 'what's the weather in sf',\n",
" 'example': False,\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {}},\n",
" {'id': 'run-4885d5a0-cd89-4f00-8558-e85b542a710c',\n",
" 'name': None,\n",
" 'type': 'ai',\n",
" 'content': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'name': 'tavily_search_results_json',\n",
" 'type': 'tool_use',\n",
" 'input': {'query': 'weather in san francisco'}}],\n",
" 'example': False,\n",
" 'tool_calls': [{'id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'args': {'query': 'weather in san francisco'},\n",
" 'name': 'tavily_search_results_json'}],\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {},\n",
" 'invalid_tool_calls': []},\n",
" {'id': '045e936d-ee47-4236-95ff-793b6b32b590',\n",
" 'name': 'tavily_search_results_json',\n",
" 'type': 'tool',\n",
" 'content': '[{\"url\": \"https://www.weatherapi.com/\", \"content\": \"{\\'location\\': {\\'name\\': \\'San Francisco\\', \\'region\\': \\'California\\', \\'country\\': \\'United States of America\\', \\'lat\\': 37.78, \\'lon\\': -122.42, \\'tz_id\\': \\'America/Los_Angeles\\', \\'localtime_epoch\\': 1715993410, \\'localtime\\': \\'2024-05-17 17:50\\'}, \\'current\\': {\\'last_updated_epoch\\': 1715993100, \\'last_updated\\': \\'2024-05-17 17:45\\', \\'temp_c\\': 17.8, \\'temp_f\\': 64.0, \\'is_day\\': 1, \\'condition\\': {\\'text\\': \\'Partly cloudy\\', \\'icon\\': \\'//cdn.weatherapi.com/weather/64x64/day/116.png\\', \\'code\\': 1003}, \\'wind_mph\\': 15.0, \\'wind_kph\\': 24.1, \\'wind_degree\\': 300, \\'wind_dir\\': \\'WNW\\', \\'pressure_mb\\': 1013.0, \\'pressure_in\\': 29.9, \\'precip_mm\\': 0.0, \\'precip_in\\': 0.0, \\'humidity\\': 65, \\'cloud\\': 25, \\'feelslike_c\\': 17.8, \\'feelslike_f\\': 64.0, \\'vis_km\\': 16.0, \\'vis_miles\\': 9.0, \\'uv\\': 5.0, \\'gust_mph\\': 16.2, \\'gust_kph\\': 26.1}}\"}]',\n",
" 'tool_call_id': 'toolu_018yyEfJHihdVfWypRNLqDug',\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {}},\n",
" {'id': 'run-069f1ddd-64b3-451d-bb84-75dec23a7286',\n",
" 'name': None,\n",
" 'type': 'ai',\n",
" 'content': \"The search results provide the current weather conditions in San Francisco. According to the data, as of 5:45pm on May 17, 2024, the weather in San Francisco is partly cloudy with a temperature of around 64°F (17.8°C). The wind is blowing from the west-northwest at 15 mph (24 km/h) with gusts up to 16 mph (26 km/h). The humidity is 65% and visibility is 9 miles (16 km). The UV index is 5.\\n\\nSo in summary, it's a partly cloudy spring day in San Francisco with mild temperatures and moderate winds. The weather seems pleasant for being outdoors during the daytime hours.\",\n",
" 'example': False,\n",
" 'tool_calls': [],\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {},\n",
" 'invalid_tool_calls': []}]}},\n",
" 'metadata': {'graph_id': 'agent',\n",
" 'thread_id': '6ada015b-b47a-4c4f-a5cd-580893cb6d0c',\n",
"{'values': {'messages': [{'content': 'what's the weather in sf',\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {},\n",
" 'type': 'human',\n",
" 'name': None,\n",
" 'id': 'bfe07fff-cb40-40be-84d5-a061d2c40006',\n",
" 'example': False},\n",
" {'content': [{'id': 'toolu_01QUzhhfDQkpbPSediUrXvQb',\n",
" 'input': {'query': 'weather in san francisco'},\n",
" 'name': 'tavily_search_results_json',\n",
" 'type': 'tool_use'}],\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {},\n",
" 'type': 'ai',\n",
" 'name': None,\n",
" 'id': 'run-6d8665ca-a77d-4b44-9a7b-4e975b155fb1',\n",
" 'example': False,\n",
" 'tool_calls': [{'name': 'tavily_search_results_json',\n",
" 'args': {'query': 'weather in san francisco'},\n",
" 'id': 'toolu_01QUzhhfDQkpbPSediUrXvQb'}],\n",
" 'invalid_tool_calls': [],\n",
" 'usage_metadata': None},\n",
" {'content': '[{\"url\": \"https://www.timeanddate.com/weather/usa/san-francisco/historic\", \"content\": \"San Francisco Weather History for the Previous 24 Hours Show weather for: Previous 24 hours June 17, 2024 June 16, 2024 June 15, 2024 June 14, 2024 June 13, 2024 June 12, 2024 June 11, 2024 June 10, 2024 June 9, 2024 June 8, 2024 June 7, 2024 June 6, 2024 June 5, 2024 June 4, 2024 June 3, 2024 June 2, 2024\"}]',\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {},\n",
" 'type': 'tool',\n",
" 'name': 'tavily_search_results_json',\n",
" 'id': '257a1f29-2f66-4f9e-b35d-c8818dbbaa3f',\n",
" 'tool_call_id': 'toolu_01QUzhhfDQkpbPSediUrXvQb'},\n",
" {'content': [{'text': 'The search results provide historic weather data for San Francisco, but do not give the current weather conditions. To get the current weather forecast for San Francisco, I would need to refine my search query. Here is an updated search:',\n",
" 'type': 'text'},\n",
" {'id': 'toolu_01RLJEcWYRvRoBhiHdrhoRZx',\n",
" 'input': {'query': 'san francisco weather forecast today'},\n",
" 'name': 'tavily_search_results_json',\n",
" 'type': 'tool_use'}],\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {},\n",
" 'type': 'ai',\n",
" 'name': None,\n",
" 'id': 'run-ca41dbf8-7e89-4ff2-a245-87098d7928ba',\n",
" 'example': False,\n",
" 'tool_calls': [{'name': 'tavily_search_results_json',\n",
" 'args': {'query': 'san francisco weather forecast today'},\n",
" 'id': 'toolu_01RLJEcWYRvRoBhiHdrhoRZx'}],\n",
" 'invalid_tool_calls': [],\n",
" 'usage_metadata': None},\n",
" {'content': '[{\"url\": \"https://www.weatherapi.com/\", \"content\": \"{\\'location\\': {\\'name\\': \\'San Francisco\\', \\'region\\': \\'California\\', \\'country\\': \\'United States of America\\', \\'lat\\': 37.78, \\'lon\\': -122.42, \\'tz_id\\': \\'America/Los_Angeles\\', \\'localtime_epoch\\': 1718981382, \\'localtime\\': \\'2024-06-21 7:49\\'}, \\'current\\': {\\'last_updated_epoch\\': 1718981100, \\'last_updated\\': \\'2024-06-21 07:45\\', \\'temp_c\\': 12.8, \\'temp_f\\': 55.0, \\'is_day\\': 1, \\'condition\\': {\\'text\\': \\'Overcast\\', \\'icon\\': \\'//cdn.weatherapi.com/weather/64x64/day/122.png\\', \\'code\\': 1009}, \\'wind_mph\\': 6.9, \\'wind_kph\\': 11.2, \\'wind_degree\\': 200, \\'wind_dir\\': \\'SSW\\', \\'pressure_mb\\': 1011.0, \\'pressure_in\\': 29.84, \\'precip_mm\\': 0.01, \\'precip_in\\': 0.0, \\'humidity\\': 86, \\'cloud\\': 100, \\'feelslike_c\\': 12.2, \\'feelslike_f\\': 53.9, \\'windchill_c\\': 11.2, \\'windchill_f\\': 52.1, \\'heatindex_c\\': 12.0, \\'heatindex_f\\': 53.5, \\'dewpoint_c\\': 9.4, \\'dewpoint_f\\': 48.8, \\'vis_km\\': 16.0, \\'vis_miles\\': 9.0, \\'uv\\': 3.0, \\'gust_mph\\': 7.6, \\'gust_kph\\': 12.2}}\"}]',\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {},\n",
" 'type': 'tool',\n",
" 'name': 'tavily_search_results_json',\n",
" 'id': 'c80a3720-6a9f-4ff0-9ce2-6112e66a6f81',\n",
" 'tool_call_id': 'toolu_01RLJEcWYRvRoBhiHdrhoRZx'},\n",
" {'content': 'The updated search provides the current weather forecast for San Francisco. According to the results, as of 7:49am on June 21, 2024 in San Francisco, the temperature is 55°F (12.8°C), it is overcast with 100% cloud cover, and there are light winds from the south-southwest around 7 mph (11 km/h). The forecast also shows low precipitation of 0.01 mm, high humidity of 86%, and visibility of 9 miles (16 km).\\n\\nIn summary, the current weather in San Francisco is cool, overcast, and breezy based on this weather forecast data. Let me know if you need any other details!',\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {},\n",
" 'type': 'ai',\n",
" 'name': None,\n",
" 'id': 'run-4f23b53d-a8ec-4038-b3ed-08b2560bf81c',\n",
" 'example': False,\n",
" 'tool_calls': [],\n",
" 'invalid_tool_calls': [],\n",
" 'usage_metadata': None}]},\n",
" 'next': [],\n",
" 'config': {'configurable': {'thread_id': '5fc20631-47b7-48cd-8aa2-9f2eace9778d',\n",
" 'thread_ts': '1ef2fdea-f879-65a5-8005-443b6a4039aa'}},\n",
" 'metadata': {'step': 5,\n",
" 'run_id': '1ef2fdea-814c-6165-8b2a-a40e2a028198',\n",
" 'source': 'loop',\n",
" 'writes': {'agent': {'messages': [{'id': 'run-4f23b53d-a8ec-4038-b3ed-08b2560bf81c',\n",
" 'name': None,\n",
" 'type': 'ai',\n",
" 'content': 'The updated search provides the current weather forecast for San Francisco. According to the results, as of 7:49am on June 21, 2024 in San Francisco, the temperature is 55°F (12.8°C), it is overcast with 100% cloud cover, and there are light winds from the south-southwest around 7 mph (11 km/h). The forecast also shows low precipitation of 0.01 mm, high humidity of 86%, and visibility of 9 miles (16 km).\\n\\nIn summary, the current weather in San Francisco is cool, overcast, and breezy based on this weather forecast data. Let me know if you need any other details!',\n",
" 'example': False,\n",
" 'tool_calls': [],\n",
" 'usage_metadata': None,\n",
" 'additional_kwargs': {},\n",
" 'response_metadata': {},\n",
" 'invalid_tool_calls': []}]}},\n",
" 'user_id': '',\n",
" 'graph_id': 'agent',\n",
" 'thread_id': '5fc20631-47b7-48cd-8aa2-9f2eace9778d',\n",
" 'created_by': 'system',\n",
" 'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca'},\n",
" 'tags': []}"
" 'created_at': '2024-06-21T14:58:14.591805+00:00',\n",
" 'parent_config': {'configurable': {'thread_id': '5fc20631-47b7-48cd-8aa2-9f2eace9778d',\n",
" 'thread_ts': '1ef2fdea-d44c-6fc4-8004-d2713436777d'}}}"
]
},
"execution_count": 22,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
@@ -572,40 +343,32 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 12,
"id": "ddd6e698-4609-4389-b84a-bb8939fff08b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"The search results provide the current weather conditions in San Francisco. According to the data, as of 5:45pm on May 17, 2024, the weather in San Francisco is partly cloudy with a temperature of around 64°F (17.8°C). The wind is blowing from the west-northwest at 15 mph (24 km/h) with gusts up to 16 mph (26 km/h). The humidity is 65% and visibility is 9 miles (16 km). The UV index is 5.\\n\\nSo in summary, it's a partly cloudy spring day in San Francisco with mild temperatures and moderate winds. The weather seems pleasant for being outdoors during the daytime hours.\""
"'The updated search provides the current weather forecast for San Francisco. According to the results, as of 7:49am on June 21, 2024 in San Francisco, the temperature is 55°F (12.8°C), it is overcast with 100% cloud cover, and there are light winds from the south-southwest around 7 mph (11 km/h). The forecast also shows low precipitation of 0.01 mm, high humidity of 86%, and visibility of 9 miles (16 km).\\n\\nIn summary, the current weather in San Francisco is cool, overcast, and breezy based on this weather forecast data. Let me know if you need any other details!'"
]
},
"execution_count": 28,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# We can get the content of the final message\n",
"final_result['data']['output']['messages'][-1]['content']"
"final_result['values']['messages'][-1]['content']"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "535638f7-48a9-49bb-9a0b-57a5b36d0696",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "langgraph-example-dev",
"language": "python",
"name": "python3"
"name": "langgraph-example-dev"
},
"language_info": {
"codemirror_mode": {
@@ -617,7 +380,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.1"
"version": "3.11.9"
}
},
"nbformat": 4,
@@ -28,7 +28,7 @@
"outputs": [],
"source": [
"client = get_client()\n",
"assistant = await client.assistants.create(\"agent\")\n",
"assistant_id = \"agent\"\n",
"thread = await client.threads.create()"
]
},
@@ -41,7 +41,7 @@
"# this run will be interrupted\n",
"first_run = await client.runs.create(\n",
" thread[\"thread_id\"],\n",
" assistant[\"assistant_id\"],\n",
" assistant_id,\n",
" input={\"messages\": [{\"role\": \"human\", \"content\": \"what's the weather in sf?\"}]},\n",
")"
]
@@ -54,7 +54,7 @@
"source": [
"second_run = await client.runs.create(\n",
" thread[\"thread_id\"],\n",
" assistant[\"assistant_id\"],\n",
" assistant_id,\n",
" input={\"messages\": [{\"role\": \"human\", \"content\": \"what's the weather in nyc?\"}]},\n",
" multitask_strategy=\"enqueue\",\n",
")"
@@ -175,10 +175,14 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "",
"name": ""
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
@@ -35,35 +35,6 @@
"client = get_client()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "4947e9bc-111f-4991-8c41-1041da9bf0ba",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca',\n",
" 'graph_id': 'agent',\n",
" 'config': {},\n",
" 'created_at': '2024-05-18T00:19:39.688822+00:00',\n",
" 'updated_at': '2024-05-18T00:19:39.688822+00:00',\n",
" 'metadata': {'created_by': 'system'}}]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# There should always be a default assistant with no configuration\n",
"assistants = await client.assistants.search()\n",
"assistants = [a for a in assistants if not a['config']]\n",
"assistants"
]
},
{
"cell_type": "code",
"execution_count": 4,
@@ -87,8 +58,7 @@
}
],
"source": [
"assistant = assistants[0]\n",
"assistant"
"assistant_id = \"agent\""
]
},
{
@@ -188,7 +158,7 @@
"source": [
"input = {\"messages\": [{\"role\": \"human\", \"content\": \"what's the weather in sf\"}]}\n",
"async for chunk in client.runs.stream(\n",
" thread['thread_id'], assistant['assistant_id'], input=input, stream_mode=\"updates\", interrupt_before=['action']\n",
" thread['thread_id'], assistant_id, input=input, stream_mode=\"updates\", interrupt_before=['action']\n",
"):\n",
" print(f\"Receiving new event of type: {chunk.event}...\")\n",
" print(chunk.data)\n",
@@ -239,7 +209,7 @@
"source": [
"input = None\n",
"async for chunk in client.runs.stream(\n",
" thread['thread_id'], assistant['assistant_id'], input=input, stream_mode=\"updates\", interrupt_before=['action']\n",
" thread['thread_id'], assistant_id, input=input, stream_mode=\"updates\", interrupt_before=['action']\n",
"):\n",
" print(f\"Receiving new event of type: {chunk.event}...\")\n",
" print(chunk.data)\n",
@@ -289,7 +259,7 @@
"source": [
"input = {\"messages\": [{\"role\": \"human\", \"content\": \"what's the weather in la?\"}]}\n",
"async for chunk in client.runs.stream(\n",
" thread['thread_id'], assistant['assistant_id'], input=input, stream_mode=\"updates\", interrupt_before=['action']\n",
" thread['thread_id'], assistant_id, input=input, stream_mode=\"updates\", interrupt_before=['action']\n",
"):\n",
" print(f\"Receiving new event of type: {chunk.event}...\")\n",
" print(chunk.data)\n",
@@ -492,7 +462,7 @@
"source": [
"input = None\n",
"async for chunk in client.runs.stream(\n",
" thread['thread_id'], assistant['assistant_id'], input=input, stream_mode=\"updates\", interrupt_before=['action']\n",
" thread['thread_id'], assistant_id, input=input, stream_mode=\"updates\", interrupt_before=['action']\n",
"):\n",
" print(f\"Receiving new event of type: {chunk.event}...\")\n",
" print(chunk.data)\n",
@@ -641,7 +611,7 @@
"input = None\n",
"async for chunk in client.runs.stream(\n",
" thread['thread_id'], \n",
" assistant['assistant_id'], \n",
" assistant_id, \n",
" input=input, \n",
" stream_mode=\"updates\", \n",
" interrupt_before=['action'],\n",
@@ -677,7 +647,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.1"
"version": "3.11.9"
}
},
"nbformat": 4,
@@ -30,7 +30,7 @@
"outputs": [],
"source": [
"client = get_client()\n",
"assistant = await client.assistants.create(\"agent\")\n",
"assistant_id = \"agent\"\n",
"thread = await client.threads.create()"
]
},
@@ -43,13 +43,13 @@
"# the first run will be interrupted\n",
"interrupted_run = await client.runs.create(\n",
" thread[\"thread_id\"],\n",
" assistant[\"assistant_id\"],\n",
" assistant_id,\n",
" input={\"messages\": [{\"role\": \"human\", \"content\": \"what's the weather in sf?\"}]},\n",
")\n",
"await asyncio.sleep(2)\n",
"run = await client.runs.create(\n",
" thread[\"thread_id\"],\n",
" assistant[\"assistant_id\"],\n",
" assistant_id,\n",
" input={\"messages\": [{\"role\": \"human\", \"content\": \"what's the weather in nyc?\"}]},\n",
" multitask_strategy=\"interrupt\",\n",
")"
@@ -166,10 +166,14 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "",
"name": ""
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
@@ -28,24 +28,8 @@
"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": [
"client = get_client()\n",
"assistant_id = \"agent\"\n",
"thread = await client.threads.create()"
]
},
@@ -57,7 +41,7 @@
"source": [
"run = await client.runs.create(\n",
" thread[\"thread_id\"],\n",
" assistant[\"assistant_id\"],\n",
" assistant_id,\n",
" input={\"messages\": [{\"role\": \"human\", \"content\": \"what's the weather in sf?\"}]},\n",
")"
]
@@ -80,7 +64,7 @@
"try:\n",
" await client.runs.create(\n",
" thread[\"thread_id\"],\n",
" assistant[\"assistant_id\"],\n",
" assistant_id,\n",
" input={\"messages\": [{\"role\": \"human\", \"content\": \"what's the weather in nyc?\"}]},\n",
" multitask_strategy=\"reject\",\n",
" )\n",
@@ -163,10 +147,14 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "",
"name": ""
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
@@ -31,7 +31,7 @@
"outputs": [],
"source": [
"client = get_client()\n",
"assistant = await client.assistants.create(\"agent\")\n",
"assistant_id = \"agent\"\n",
"thread = await client.threads.create()"
]
},
@@ -44,13 +44,13 @@
"# the first run will be interrupted\n",
"rolled_back_run = await client.runs.create(\n",
" thread[\"thread_id\"],\n",
" assistant[\"assistant_id\"],\n",
" assistant_id,\n",
" input={\"messages\": [{\"role\": \"human\", \"content\": \"what's the weather in sf?\"}]},\n",
")\n",
"await asyncio.sleep(2)\n",
"run = await client.runs.create(\n",
" thread[\"thread_id\"],\n",
" assistant[\"assistant_id\"],\n",
" assistant_id,\n",
" input={\"messages\": [{\"role\": \"human\", \"content\": \"what's the weather in nyc?\"}]},\n",
" multitask_strategy=\"rollback\",\n",
")"
@@ -146,10 +146,14 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "",
"name": ""
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
File diff suppressed because it is too large Load Diff
+11 -57
View File
@@ -40,75 +40,29 @@
{
"cell_type": "code",
"execution_count": 3,
"id": "4947e9bc-111f-4991-8c41-1041da9bf0ba",
"id": "230c0464-a6e5-420f-9e38-ca514e5634ce",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca',\n",
" 'graph_id': 'agent',\n",
" 'config': {},\n",
" 'created_at': '2024-05-18T00:19:39.688822+00:00',\n",
" 'updated_at': '2024-05-18T00:19:39.688822+00:00',\n",
" 'metadata': {'created_by': 'system'}}]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"# There should always be a default assistant with no configuration\n",
"assistants = await client.assistants.search()\n",
"assistants = [a for a in assistants if not a['config']]\n",
"assistants"
"assistant_id = \"agent\""
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "230c0464-a6e5-420f-9e38-ca514e5634ce",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca',\n",
" 'graph_id': 'agent',\n",
" 'config': {},\n",
" 'created_at': '2024-05-18T00:19:39.688822+00:00',\n",
" 'updated_at': '2024-05-18T00:19:39.688822+00:00',\n",
" 'metadata': {'created_by': 'system'}}"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"assistant = assistants[0]\n",
"assistant"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "56aa5159-5583-4134-9210-709b969bda6f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'thread_id': '1eee9bd4-ec61-4300-a38a-2e13b8925d39',\n",
" 'created_at': '2024-05-18T19:57:36.509105+00:00',\n",
" 'updated_at': '2024-05-18T19:57:36.509105+00:00',\n",
"{'thread_id': '979e3c89-a702-4882-87c2-7a59a250ce16',\n",
" 'created_at': '2024-06-21T15:22:07.453100+00:00',\n",
" 'updated_at': '2024-06-21T15:22:07.453100+00:00',\n",
" 'metadata': {}}"
]
},
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
@@ -120,7 +74,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"id": "147c3f98-f889-4f05-a090-6b31f2a0b291",
"metadata": {},
"outputs": [
@@ -130,7 +84,7 @@
"[]"
]
},
"execution_count": 6,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
@@ -180,7 +134,7 @@
],
"source": [
"input = {\"messages\": [{\"role\": \"human\", \"content\": \"what's the weather in la\"}]}\n",
"async for chunk in client.runs.stream(thread['thread_id'], assistant['assistant_id'], input=input, stream_mode=\"updates\", ):\n",
"async for chunk in client.runs.stream(thread['thread_id'], assistant_id, input=input, stream_mode=\"updates\", ):\n",
" print(f\"Receiving new event of type: {chunk.event}...\")\n",
" print(chunk.data)\n",
" print(\"\\n\\n\")"
@@ -211,7 +165,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.1"
"version": "3.11.9"
}
},
"nbformat": 4,
+5 -51
View File
@@ -40,57 +40,11 @@
{
"cell_type": "code",
"execution_count": 3,
"id": "4947e9bc-111f-4991-8c41-1041da9bf0ba",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca',\n",
" 'graph_id': 'agent',\n",
" 'config': {},\n",
" 'created_at': '2024-05-18T00:19:39.688822+00:00',\n",
" 'updated_at': '2024-05-18T00:19:39.688822+00:00',\n",
" 'metadata': {'created_by': 'system'}}]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# There should always be a default assistant with no configuration\n",
"assistants = await client.assistants.search()\n",
"assistants = [a for a in assistants if not a['config']]\n",
"assistants"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "230c0464-a6e5-420f-9e38-ca514e5634ce",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca',\n",
" 'graph_id': 'agent',\n",
" 'config': {},\n",
" 'created_at': '2024-05-18T00:19:39.688822+00:00',\n",
" 'updated_at': '2024-05-18T00:19:39.688822+00:00',\n",
" 'metadata': {'created_by': 'system'}}"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"assistant = assistants[0]\n",
"assistant"
"assistant_id = \"agent\""
]
},
{
@@ -139,7 +93,7 @@
"source": [
"input = {\"messages\": [{\"role\": \"human\", \"content\": \"what's the weather in la\"}]}\n",
"thread = await client.threads.create()\n",
"async for chunk in client.runs.stream(thread['thread_id'], assistant['assistant_id'], input=input):\n",
"async for chunk in client.runs.stream(thread['thread_id'], assistant_id, input=input):\n",
" print(f\"Receiving new event of type: {chunk.event}...\")\n",
" print(chunk.data)\n",
" print(\"\\n\\n\")"
@@ -163,7 +117,7 @@
"input = {\"messages\": [{\"role\": \"human\", \"content\": \"what's the weather in la\"}]}\n",
"thread = await client.threads.create()\n",
"final_answer = None\n",
"async for chunk in client.runs.stream(thread['thread_id'], assistant['assistant_id'], input=input):\n",
"async for chunk in client.runs.stream(thread['thread_id'], assistant_id, input=input):\n",
" if chunk.event == \"values\":\n",
" final_answer = chunk.data"
]
@@ -250,7 +204,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.1"
"version": "3.11.9"
}
},
"nbformat": 4,