Improve tracing output for function nodes

- remove double entry in tracing tree when using functions as nodes
This commit is contained in:
Nuno Campos
2024-04-29 08:59:56 -07:00
parent 0e3c37ba25
commit fd9d30f144
4 changed files with 202 additions and 156 deletions
@@ -90,7 +90,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "d7ef57dd-5d6e-4ad3-9377-a92201c1310e",
"metadata": {},
"outputs": [],
@@ -118,7 +118,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"id": "892b54b9-75f0-4804-9ed0-88b5e5532989",
"metadata": {},
"outputs": [],
@@ -140,7 +140,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"id": "cd3cbae5-d92c-4559-a4aa-44721b80d107",
"metadata": {},
"outputs": [
@@ -148,7 +148,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/nuno/dev/langgraph/.venv/lib/python3.11/site-packages/langchain_core/_api/beta_decorator.py:87: LangChainBetaWarning: The function `bind_tools` is in beta. It is actively being worked on, so the API may change.\n",
"/Users/nuno/dev/langgraph/.venv/lib/python3.11/site-packages/langchain_core/_api/beta_decorator.py:87: LangChainBetaWarning: The method `ChatAnthropic.bind_tools` is in beta. It is actively being worked on, so the API may change.\n",
" warn_beta(\n"
]
}
@@ -159,7 +159,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"id": "ea793afa-2eab-4901-910d-6eed90cd6564",
"metadata": {},
"outputs": [],
@@ -202,7 +202,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"id": "3b541bb9-900c-40d0-964d-7b5dfee30667",
"metadata": {},
"outputs": [],
@@ -246,7 +246,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"id": "813ae66c-3b58-4283-a02a-36da72a2ab90",
"metadata": {},
"outputs": [],
@@ -308,7 +308,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"id": "8edb04b9-40b6-46f1-a7a8-4b2d8aba7752",
"metadata": {},
"outputs": [
@@ -316,12 +316,12 @@
"data": {
"text/plain": [
"{'messages': [HumanMessage(content='what is the weather in sf'),\n",
" AIMessage(content=[{'text': '<thinking>\\nThe relevant tool to answer this question is tavily_search_results_json, which can provide comprehensive results about current events like weather.\\n\\nTo call tavily_search_results_json, I need to provide a value for the required \"query\" parameter. The user\\'s request directly specifies the query to search for - \"weather in sf\". \"sf\" here likely refers to San Francisco.\\n\\nI have the required parameter value to make the API call, so I will proceed with the search.\\n</thinking>', 'type': 'text'}, {'id': 'toolu_01AnGNJEYsAvrJpJYh6MuV16', 'input': {'query': 'weather in San Francisco'}, 'name': 'tavily_search_results_json', 'type': 'tool_use'}], response_metadata={'id': 'msg_01BujbLhL23TFWN8zrarY4So', 'model': 'claude-3-opus-20240229', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'input_tokens': 507, 'output_tokens': 170}}, id='run-3c5a870b-48b4-4b94-8c70-f5dc322da35a-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'weather in San Francisco'}, 'id': 'toolu_01AnGNJEYsAvrJpJYh6MuV16'}]),\n",
" ToolMessage(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\\': 1712857380, \\'localtime\\': \\'2024-04-11 10:43\\'}, \\'current\\': {\\'last_updated_epoch\\': 1712856600, \\'last_updated\\': \\'2024-04-11 10:30\\', \\'temp_c\\': 15.6, \\'temp_f\\': 60.1, \\'is_day\\': 1, \\'condition\\': {\\'text\\': \\'Partly cloudy\\', \\'icon\\': \\'//cdn.weatherapi.com/weather/64x64/day/116.png\\', \\'code\\': 1003}, \\'wind_mph\\': 4.3, \\'wind_kph\\': 6.8, \\'wind_degree\\': 50, \\'wind_dir\\': \\'NE\\', \\'pressure_mb\\': 1015.0, \\'pressure_in\\': 29.96, \\'precip_mm\\': 0.0, \\'precip_in\\': 0.0, \\'humidity\\': 78, \\'cloud\\': 25, \\'feelslike_c\\': 15.6, \\'feelslike_f\\': 60.1, \\'vis_km\\': 16.0, \\'vis_miles\\': 9.0, \\'uv\\': 5.0, \\'gust_mph\\': 5.1, \\'gust_kph\\': 8.3}}\"}]', name='tavily_search_results_json', tool_call_id='toolu_01AnGNJEYsAvrJpJYh6MuV16'),\n",
" AIMessage(content=\"<search_quality_reflection>\\nThe search results provide a comprehensive weather report for San Francisco, including the current temperature, conditions, wind, humidity, and other relevant details. This should be sufficient to fully answer the question of what the current weather is like in San Francisco.\\n</search_quality_reflection>\\n<search_quality_score>5</search_quality_score>\\n\\n<result>\\nAccording to the weather report, the current weather in San Francisco is:\\n\\nTemperature: 60.1°F (15.6°C)\\nConditions: Partly cloudy \\nWind: 4.3 mph (6.8 km/h) from the northeast\\nHumidity: 78%\\n\\nIt feels like 60.1°F (15.6°C). Visibility is 9 miles (16 km). The UV index is 5 out of 10.\\n\\nSo in summary, it's a mild spring day in San Francisco with some cloud cover, light winds, and comfortable temperatures in the low 60s Fahrenheit. A light jacket or sweater should suffice for being outdoors.\\n</result>\", response_metadata={'id': 'msg_01KhNRhAaoyT8v7kk8QJUyYj', 'model': 'claude-3-opus-20240229', 'stop_reason': 'end_turn', 'stop_sequence': None, 'usage': {'input_tokens': 1102, 'output_tokens': 250}}, id='run-5694fbc4-8041-4577-a007-227e09ef5bd8-0')]}"
" AIMessage(content=[{'text': '<thinking>\\nThe relevant tool to answer this question is tavily_search_results_json, which can provide comprehensive information about current events like weather.\\n\\nTo call this function, I need to provide a value for the required \"query\" parameter. The user\\'s request directly specifies they want to know the weather in \"sf\", which I can reasonably infer refers to San Francisco.\\n\\nTherefore, I have enough information to populate the required parameter:\\nquery = \"weather in San Francisco\"\\n\\n</thinking>', 'type': 'text'}, {'id': 'toolu_0183a3MorRJu43zykiCWKAyo', 'input': {'query': 'weather in San Francisco'}, 'name': 'tavily_search_results_json', 'type': 'tool_use'}], response_metadata={'id': 'msg_01Lg8ZNFNwbDXz9VfxZyRCSb', 'model': 'claude-3-opus-20240229', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'input_tokens': 507, 'output_tokens': 166}}, id='run-587209cf-1406-47f1-9476-73f9c75f4650-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'weather in San Francisco'}, 'id': 'toolu_0183a3MorRJu43zykiCWKAyo'}]),\n",
" ToolMessage(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\\': 1714170321, \\'localtime\\': \\'2024-04-26 15:25\\'}, \\'current\\': {\\'last_updated_epoch\\': 1714169700, \\'last_updated\\': \\'2024-04-26 15:15\\', \\'temp_c\\': 17.2, \\'temp_f\\': 63.0, \\'is_day\\': 1, \\'condition\\': {\\'text\\': \\'Partly cloudy\\', \\'icon\\': \\'//cdn.weatherapi.com/weather/64x64/day/116.png\\', \\'code\\': 1003}, \\'wind_mph\\': 34.9, \\'wind_kph\\': 56.2, \\'wind_degree\\': 280, \\'wind_dir\\': \\'W\\', \\'pressure_mb\\': 1017.0, \\'pressure_in\\': 30.02, \\'precip_mm\\': 0.0, \\'precip_in\\': 0.0, \\'humidity\\': 60, \\'cloud\\': 50, \\'feelslike_c\\': 17.2, \\'feelslike_f\\': 63.0, \\'vis_km\\': 16.0, \\'vis_miles\\': 9.0, \\'uv\\': 4.0, \\'gust_mph\\': 39.4, \\'gust_kph\\': 63.4}}\"}]', name='tavily_search_results_json', tool_call_id='toolu_0183a3MorRJu43zykiCWKAyo'),\n",
" AIMessage(content=\"<search_quality_reflection>\\nThe search results provide a comprehensive and up-to-date weather report for San Francisco, including key details like the current temperature, weather conditions, wind, humidity, and more. This should be sufficient to fully answer the question of what the current weather is like in San Francisco.\\n</search_quality_reflection>\\n\\n<search_quality_score>5</search_quality_score>\\n\\n<result>\\nAccording to the current weather report, the weather in San Francisco right now is:\\n\\nTemperature: 63°F (17.2°C)\\nConditions: Partly cloudy \\nWind: 34.9 mph (56.2 km/h) winds from the west\\nHumidity: 60%\\n\\nIt feels like 63°F (17.2°C). Visibility is good at 9 miles (16 km). The UV index is moderate at 4.0 out of 11. \\n\\nOverall, it's a mild spring day in San Francisco with some cloud cover and breezy conditions. A light jacket or sweater should suffice for being outdoors.\\n</result>\", response_metadata={'id': 'msg_01LS72RMeicMF1xT7enopKpJ', 'model': 'claude-3-opus-20240229', 'stop_reason': 'end_turn', 'stop_sequence': None, 'usage': {'input_tokens': 1097, 'output_tokens': 251}}, id='run-794deb88-bea5-4d0d-93db-bf5dc38445f0-0')]}"
]
},
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}