参考自https://www.deeplearning.ai/short-courses/ai-agents-in-langgraph,以下为代码的实现。
- 这里用LangGraph把L1的ReAct_Agent实现,可以看出用LangGraph流程化了很多。
LangGraph Components
import os
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
# print(os.environ.get('OPENAI_API_KEY'))
# print(os.environ.get('TAVILY_API_KEY'))
# print(os.environ.get('OPENAI_BASE_URL'))
from langgraph.graph import StateGraph, END
from typing import TypedDict, Annotated
import operator
from langchain_core.messages import AnyMessage, SystemMessage, HumanMessage, ToolMessage
from langchain_openai import ChatOpenAI
from langchain_community.tools.tavily_search import TavilySearchResults
tool = TavilySearchResults(max_results=2) #increased number of results
print(type(tool))
print(tool.name)
<class 'langchain_community.tools.tavily_search.tool.TavilySearchResults'>
tavily_search_results_json
class AgentState(TypedDict):
messages: Annotated[list[AnyMessage], operator.add]
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class Agent:
def __init__(self, model, tools, system=""):
self.system = system
graph = StateGraph(AgentState)
graph.add_node("llm", self.call_openai)
graph.add_node("action", self.take_action)
graph.add_conditional_edges(
"llm",
self.exists_action,
{True: "action", False: END}
)
graph.add_edge("action", "llm")
graph.set_entry_point("llm")
self.graph = graph.compile()
self.tools = {t.name: t for t in tools}
self.model = model.bind_tools(tools)
logger.info(f"model: {self.model}")
def exists_action(self, state: AgentState):
result = state['messages'][-1]
logger.info(f"exists_action result: {result}")
return len(result.tool_calls) > 0
def call_openai(self, state: AgentState):
logger.info(f"state: {state}")
messages = state['messages']
if self.system:
messages = [SystemMessage(content=self.system)] + messages
message = self.model.invoke(messages)
logger.info(f"LLM message: {message}")
return {'messages': [message]}
def take_action(self, state: AgentState):
import threading
print(f"take_action called in thread: {threading.current_thread().name}")
tool_calls = state['messages'][-1].tool_calls
results = []
print(f"take_action called with tool_calls: {tool_calls}")
for t in tool_calls:
logger.info(f"Calling: {t}")
print(f"Calling: {t}")
if not t['name'] in self.tools: # check for bad tool name from LLM
print("\n ....bad tool name....")
result = "bad tool name, retry" # instruct LLM to retry if bad
else:
result = self.tools[t['name']].invoke(t['args'])
logger.info(f"action {t['name']}, result: {result}")
print(f"action {t['name']}, result: {result}")
results.append(ToolMessage(tool_call_id=t['id'], name=t['name'], content=str(result)))
print("Back to the model!")
return {'messages': results}
prompt = """You are a smart research assistant. Use the search engine to look up information. \
You are allowed to make multiple calls (either together or in sequence). \
Only look up information when you are sure of what you want. \
If you need to look up some information before asking a follow up question, you are allowed to do that!
"""
model = ChatOpenAI(model="gpt-4o") #reduce inference cost
# model = ChatOpenAI(model="yi-large")
abot = Agent(model, [tool], system=prompt)
INFO:__main__:model: bound=ChatOpenAI(client=<openai.resources.chat.completions.Completions object at 0x0000029BECD41520>, async_client=<openai.resources.chat.completions.AsyncCompletions object at 0x0000029BECD43200>, model_name='gpt-4o', openai_api_key=SecretStr('**********'), openai_proxy='') kwargs={'tools': [{'type': 'function', 'function': {'name': 'tavily_search_results_json', 'description': 'A search engine optimized for comprehensive, accurate, and trusted results. Useful for when you need to answer questions about current events. Input should be a search query.', 'parameters': {'type': 'object', 'properties': {'query': {'description': 'search query to look up', 'type': 'string'}}, 'required': ['query']}}}]}
from IPython.display import Image
Image(abot.graph.get_graph().draw_png())
messages = [HumanMessage(content="What is the weather in sf?")]
result = abot.graph.invoke({"messages": messages})
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in sf?')]}
INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content='' additional_kwargs={'tool_calls': [{'id': 'call_G1NzidVGnce0IG6VGUPp9xNk', 'function': {'arguments': '{"query":"current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]} response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 152, 'total_tokens': 174}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-a06698d1-8bf1-4687-b27d-9dc66850dc7b-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_G1NzidVGnce0IG6VGUPp9xNk'}] usage_metadata={'input_tokens': 152, 'output_tokens': 22, 'total_tokens': 174}
INFO:__main__:exists_action result: content='' additional_kwargs={'tool_calls': [{'id': 'call_G1NzidVGnce0IG6VGUPp9xNk', 'function': {'arguments': '{"query":"current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]} response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 152, 'total_tokens': 174}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-a06698d1-8bf1-4687-b27d-9dc66850dc7b-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_G1NzidVGnce0IG6VGUPp9xNk'}] usage_metadata={'input_tokens': 152, 'output_tokens': 22, 'total_tokens': 174}
INFO:__main__:Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_G1NzidVGnce0IG6VGUPp9xNk'}
take_action called in thread: ThreadPoolExecutor-0_0
take_action called with tool_calls: [{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_G1NzidVGnce0IG6VGUPp9xNk'}]
Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_G1NzidVGnce0IG6VGUPp9xNk'}
INFO:__main__:action tavily_search_results_json, result: [{'url': 'https://www.timeanddate.com/weather/usa/san-francisco/hourly', 'content': 'Hour-by-Hour Forecast for San Francisco, California, USA. Currently: 54 °F. Passing clouds. (Weather station: San Francisco International Airport, USA). See more current weather.'}, {'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': 1720592691, 'localtime': '2024-07-09 23:24'}, 'current': {'last_updated_epoch': 1720592100, 'last_updated': '2024-07-09 23:15', 'temp_c': 16.1, 'temp_f': 61.0, 'is_day': 0, 'condition': {'text': 'Partly cloudy', 'icon': '//cdn.weatherapi.com/weather/64x64/night/116.png', 'code': 1003}, 'wind_mph': 9.4, 'wind_kph': 15.1, 'wind_degree': 290, 'wind_dir': 'WNW', 'pressure_mb': 1013.0, 'pressure_in': 29.9, 'precip_mm': 0.0, 'precip_in': 0.0, 'humidity': 90, 'cloud': 75, 'feelslike_c': 16.1, 'feelslike_f': 61.0, 'windchill_c': 13.5, 'windchill_f': 56.4, 'heatindex_c': 14.3, 'heatindex_f': 57.7, 'dewpoint_c': 12.7, 'dewpoint_f': 54.9, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 11.8, 'gust_kph': 19.0}}"}]
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in sf?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_G1NzidVGnce0IG6VGUPp9xNk', 'function': {'arguments': '{"query":"current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 152, 'total_tokens': 174}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-a06698d1-8bf1-4687-b27d-9dc66850dc7b-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_G1NzidVGnce0IG6VGUPp9xNk'}], usage_metadata={'input_tokens': 152, 'output_tokens': 22, 'total_tokens': 174}), ToolMessage(content='[{\'url\': \'https://www.timeanddate.com/weather/usa/san-francisco/hourly\', \'content\': \'Hour-by-Hour Forecast for San Francisco, California, USA. Currently: 54 °F. Passing clouds. (Weather station: San Francisco International Airport, USA). See more current weather.\'}, {\'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\': 1720592691, \'localtime\': \'2024-07-09 23:24\'}, \'current\': {\'last_updated_epoch\': 1720592100, \'last_updated\': \'2024-07-09 23:15\', \'temp_c\': 16.1, \'temp_f\': 61.0, \'is_day\': 0, \'condition\': {\'text\': \'Partly cloudy\', \'icon\': \'//cdn.weatherapi.com/weather/64x64/night/116.png\', \'code\': 1003}, \'wind_mph\': 9.4, \'wind_kph\': 15.1, \'wind_degree\': 290, \'wind_dir\': \'WNW\', \'pressure_mb\': 1013.0, \'pressure_in\': 29.9, \'precip_mm\': 0.0, \'precip_in\': 0.0, \'humidity\': 90, \'cloud\': 75, \'feelslike_c\': 16.1, \'feelslike_f\': 61.0, \'windchill_c\': 13.5, \'windchill_f\': 56.4, \'heatindex_c\': 14.3, \'heatindex_f\': 57.7, \'dewpoint_c\': 12.7, \'dewpoint_f\': 54.9, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 11.8, \'gust_kph\': 19.0}}"}]', name='tavily_search_results_json', tool_call_id='call_G1NzidVGnce0IG6VGUPp9xNk')]}
action tavily_search_results_json, result: [{'url': 'https://www.timeanddate.com/weather/usa/san-francisco/hourly', 'content': 'Hour-by-Hour Forecast for San Francisco, California, USA. Currently: 54 °F. Passing clouds. (Weather station: San Francisco International Airport, USA). See more current weather.'}, {'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': 1720592691, 'localtime': '2024-07-09 23:24'}, 'current': {'last_updated_epoch': 1720592100, 'last_updated': '2024-07-09 23:15', 'temp_c': 16.1, 'temp_f': 61.0, 'is_day': 0, 'condition': {'text': 'Partly cloudy', 'icon': '//cdn.weatherapi.com/weather/64x64/night/116.png', 'code': 1003}, 'wind_mph': 9.4, 'wind_kph': 15.1, 'wind_degree': 290, 'wind_dir': 'WNW', 'pressure_mb': 1013.0, 'pressure_in': 29.9, 'precip_mm': 0.0, 'precip_in': 0.0, 'humidity': 90, 'cloud': 75, 'feelslike_c': 16.1, 'feelslike_f': 61.0, 'windchill_c': 13.5, 'windchill_f': 56.4, 'heatindex_c': 14.3, 'heatindex_f': 57.7, 'dewpoint_c': 12.7, 'dewpoint_f': 54.9, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 11.8, 'gust_kph': 19.0}}"}]
Back to the model!
INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content='The current weather in San Francisco is partly cloudy with a temperature of 61°F (16.1°C). The wind is blowing from the west-northwest at 9.4 mph (15.1 kph), and the humidity is at 90%.' response_metadata={'token_usage': {'completion_tokens': 54, 'prompt_tokens': 658, 'total_tokens': 712}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'stop', 'logprobs': None} id='run-7543ad68-73c8-454e-b4de-14e16d7ad8c8-0' usage_metadata={'input_tokens': 658, 'output_tokens': 54, 'total_tokens': 712}
INFO:__main__:exists_action result: content='The current weather in San Francisco is partly cloudy with a temperature of 61°F (16.1°C). The wind is blowing from the west-northwest at 9.4 mph (15.1 kph), and the humidity is at 90%.' response_metadata={'token_usage': {'completion_tokens': 54, 'prompt_tokens': 658, 'total_tokens': 712}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'stop', 'logprobs': None} id='run-7543ad68-73c8-454e-b4de-14e16d7ad8c8-0' usage_metadata={'input_tokens': 658, 'output_tokens': 54, 'total_tokens': 712}
result
{'messages': [HumanMessage(content='What is the weather in sf?'),
AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_G1NzidVGnce0IG6VGUPp9xNk', 'function': {'arguments': '{"query":"current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 152, 'total_tokens': 174}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-a06698d1-8bf1-4687-b27d-9dc66850dc7b-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_G1NzidVGnce0IG6VGUPp9xNk'}], usage_metadata={'input_tokens': 152, 'output_tokens': 22, 'total_tokens': 174}),
ToolMessage(content='[{\'url\': \'https://www.timeanddate.com/weather/usa/san-francisco/hourly\', \'content\': \'Hour-by-Hour Forecast for San Francisco, California, USA. Currently: 54 °F. Passing clouds. (Weather station: San Francisco International Airport, USA). See more current weather.\'}, {\'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\': 1720592691, \'localtime\': \'2024-07-09 23:24\'}, \'current\': {\'last_updated_epoch\': 1720592100, \'last_updated\': \'2024-07-09 23:15\', \'temp_c\': 16.1, \'temp_f\': 61.0, \'is_day\': 0, \'condition\': {\'text\': \'Partly cloudy\', \'icon\': \'//cdn.weatherapi.com/weather/64x64/night/116.png\', \'code\': 1003}, \'wind_mph\': 9.4, \'wind_kph\': 15.1, \'wind_degree\': 290, \'wind_dir\': \'WNW\', \'pressure_mb\': 1013.0, \'pressure_in\': 29.9, \'precip_mm\': 0.0, \'precip_in\': 0.0, \'humidity\': 90, \'cloud\': 75, \'feelslike_c\': 16.1, \'feelslike_f\': 61.0, \'windchill_c\': 13.5, \'windchill_f\': 56.4, \'heatindex_c\': 14.3, \'heatindex_f\': 57.7, \'dewpoint_c\': 12.7, \'dewpoint_f\': 54.9, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 11.8, \'gust_kph\': 19.0}}"}]', name='tavily_search_results_json', tool_call_id='call_G1NzidVGnce0IG6VGUPp9xNk'),
AIMessage(content='The current weather in San Francisco is partly cloudy with a temperature of 61°F (16.1°C). The wind is blowing from the west-northwest at 9.4 mph (15.1 kph), and the humidity is at 90%.', response_metadata={'token_usage': {'completion_tokens': 54, 'prompt_tokens': 658, 'total_tokens': 712}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'stop', 'logprobs': None}, id='run-7543ad68-73c8-454e-b4de-14e16d7ad8c8-0', usage_metadata={'input_tokens': 658, 'output_tokens': 54, 'total_tokens': 712})]}
result['messages'][-1].content
'The current weather in San Francisco is partly cloudy with a temperature of 61°F (16.1°C). The wind is blowing from the west-northwest at 9.4 mph (15.1 kph), and the humidity is at 90%.'
messages = [HumanMessage(content="What is the weather in SF and LA?")]
result = abot.graph.invoke({"messages": messages})
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in SF and LA?')]}
INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content='' additional_kwargs={'tool_calls': [{'id': 'call_kdq99sJ89Icj8XO3JiDBqgzg', 'function': {'arguments': '{"query": "current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}, {'id': 'call_LFYn4VtDMAhv014a7EfZoKS4', 'function': {'arguments': '{"query": "current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]} response_metadata={'token_usage': {'completion_tokens': 60, 'prompt_tokens': 154, 'total_tokens': 214}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-4f5b63b9-857e-4a59-ae40-b9804bb1f5be-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_kdq99sJ89Icj8XO3JiDBqgzg'}, {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_LFYn4VtDMAhv014a7EfZoKS4'}] usage_metadata={'input_tokens': 154, 'output_tokens': 60, 'total_tokens': 214}
INFO:__main__:exists_action result: content='' additional_kwargs={'tool_calls': [{'id': 'call_kdq99sJ89Icj8XO3JiDBqgzg', 'function': {'arguments': '{"query": "current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}, {'id': 'call_LFYn4VtDMAhv014a7EfZoKS4', 'function': {'arguments': '{"query": "current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]} response_metadata={'token_usage': {'completion_tokens': 60, 'prompt_tokens': 154, 'total_tokens': 214}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-4f5b63b9-857e-4a59-ae40-b9804bb1f5be-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_kdq99sJ89Icj8XO3JiDBqgzg'}, {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_LFYn4VtDMAhv014a7EfZoKS4'}] usage_metadata={'input_tokens': 154, 'output_tokens': 60, 'total_tokens': 214}
INFO:__main__:Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_kdq99sJ89Icj8XO3JiDBqgzg'}
take_action called in thread: ThreadPoolExecutor-1_0
take_action called with tool_calls: [{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_kdq99sJ89Icj8XO3JiDBqgzg'}, {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_LFYn4VtDMAhv014a7EfZoKS4'}]
Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_kdq99sJ89Icj8XO3JiDBqgzg'}
INFO:__main__:action tavily_search_results_json, result: [{'url': 'https://www.wunderground.com/hourly/us/ca/san-francisco/94188/date/2024-7-10', 'content': 'San Francisco Weather Forecasts. Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the San Francisco area. ... Wednesday 07/ ...'}, {'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': 1720592691, 'localtime': '2024-07-09 23:24'}, 'current': {'last_updated_epoch': 1720592100, 'last_updated': '2024-07-09 23:15', 'temp_c': 16.1, 'temp_f': 61.0, 'is_day': 0, 'condition': {'text': 'Partly cloudy', 'icon': '//cdn.weatherapi.com/weather/64x64/night/116.png', 'code': 1003}, 'wind_mph': 9.4, 'wind_kph': 15.1, 'wind_degree': 290, 'wind_dir': 'WNW', 'pressure_mb': 1013.0, 'pressure_in': 29.9, 'precip_mm': 0.0, 'precip_in': 0.0, 'humidity': 90, 'cloud': 75, 'feelslike_c': 16.1, 'feelslike_f': 61.0, 'windchill_c': 13.5, 'windchill_f': 56.4, 'heatindex_c': 14.3, 'heatindex_f': 57.7, 'dewpoint_c': 12.7, 'dewpoint_f': 54.9, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 11.8, 'gust_kph': 19.0}}"}]
INFO:__main__:Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_LFYn4VtDMAhv014a7EfZoKS4'}
action tavily_search_results_json, result: [{'url': 'https://www.wunderground.com/hourly/us/ca/san-francisco/94188/date/2024-7-10', 'content': 'San Francisco Weather Forecasts. Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the San Francisco area. ... Wednesday 07/ ...'}, {'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': 1720592691, 'localtime': '2024-07-09 23:24'}, 'current': {'last_updated_epoch': 1720592100, 'last_updated': '2024-07-09 23:15', 'temp_c': 16.1, 'temp_f': 61.0, 'is_day': 0, 'condition': {'text': 'Partly cloudy', 'icon': '//cdn.weatherapi.com/weather/64x64/night/116.png', 'code': 1003}, 'wind_mph': 9.4, 'wind_kph': 15.1, 'wind_degree': 290, 'wind_dir': 'WNW', 'pressure_mb': 1013.0, 'pressure_in': 29.9, 'precip_mm': 0.0, 'precip_in': 0.0, 'humidity': 90, 'cloud': 75, 'feelslike_c': 16.1, 'feelslike_f': 61.0, 'windchill_c': 13.5, 'windchill_f': 56.4, 'heatindex_c': 14.3, 'heatindex_f': 57.7, 'dewpoint_c': 12.7, 'dewpoint_f': 54.9, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 11.8, 'gust_kph': 19.0}}"}]
Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_LFYn4VtDMAhv014a7EfZoKS4'}
INFO:__main__:action tavily_search_results_json, result: [{'url': 'https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10', 'content': 'Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the Los Angeles area. ... Wednesday 07/10 Hourly for Tomorrow, Wed 07/10'}, {'url': 'https://www.weatherapi.com/', 'content': "{'location': {'name': 'Los Angeles', 'region': 'California', 'country': 'United States of America', 'lat': 34.05, 'lon': -118.24, 'tz_id': 'America/Los_Angeles', 'localtime_epoch': 1720592759, 'localtime': '2024-07-09 23:25'}, 'current': {'last_updated_epoch': 1720592100, 'last_updated': '2024-07-09 23:15', 'temp_c': 18.3, 'temp_f': 64.9, 'is_day': 0, 'condition': {'text': 'Partly cloudy', 'icon': '//cdn.weatherapi.com/weather/64x64/night/116.png', 'code': 1003}, 'wind_mph': 3.8, 'wind_kph': 6.1, 'wind_degree': 290, 'wind_dir': 'WNW', 'pressure_mb': 1010.0, 'pressure_in': 29.83, 'precip_mm': 0.0, 'precip_in': 0.0, 'humidity': 84, 'cloud': 50, 'feelslike_c': 18.3, 'feelslike_f': 64.9, 'windchill_c': 24.8, 'windchill_f': 76.6, 'heatindex_c': 25.7, 'heatindex_f': 78.3, 'dewpoint_c': 13.9, 'dewpoint_f': 57.0, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 3.9, 'gust_kph': 6.2}}"}]
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in SF and LA?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_kdq99sJ89Icj8XO3JiDBqgzg', 'function': {'arguments': '{"query": "current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}, {'id': 'call_LFYn4VtDMAhv014a7EfZoKS4', 'function': {'arguments': '{"query": "current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 60, 'prompt_tokens': 154, 'total_tokens': 214}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-4f5b63b9-857e-4a59-ae40-b9804bb1f5be-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_kdq99sJ89Icj8XO3JiDBqgzg'}, {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_LFYn4VtDMAhv014a7EfZoKS4'}], usage_metadata={'input_tokens': 154, 'output_tokens': 60, 'total_tokens': 214}), ToolMessage(content='[{\'url\': \'https://www.wunderground.com/hourly/us/ca/san-francisco/94188/date/2024-7-10\', \'content\': \'San Francisco Weather Forecasts. Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the San Francisco area. ... Wednesday 07/ ...\'}, {\'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\': 1720592691, \'localtime\': \'2024-07-09 23:24\'}, \'current\': {\'last_updated_epoch\': 1720592100, \'last_updated\': \'2024-07-09 23:15\', \'temp_c\': 16.1, \'temp_f\': 61.0, \'is_day\': 0, \'condition\': {\'text\': \'Partly cloudy\', \'icon\': \'//cdn.weatherapi.com/weather/64x64/night/116.png\', \'code\': 1003}, \'wind_mph\': 9.4, \'wind_kph\': 15.1, \'wind_degree\': 290, \'wind_dir\': \'WNW\', \'pressure_mb\': 1013.0, \'pressure_in\': 29.9, \'precip_mm\': 0.0, \'precip_in\': 0.0, \'humidity\': 90, \'cloud\': 75, \'feelslike_c\': 16.1, \'feelslike_f\': 61.0, \'windchill_c\': 13.5, \'windchill_f\': 56.4, \'heatindex_c\': 14.3, \'heatindex_f\': 57.7, \'dewpoint_c\': 12.7, \'dewpoint_f\': 54.9, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 11.8, \'gust_kph\': 19.0}}"}]', name='tavily_search_results_json', tool_call_id='call_kdq99sJ89Icj8XO3JiDBqgzg'), ToolMessage(content='[{\'url\': \'https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10\', \'content\': \'Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the Los Angeles area. ... Wednesday 07/10 Hourly for Tomorrow, Wed 07/10\'}, {\'url\': \'https://www.weatherapi.com/\', \'content\': "{\'location\': {\'name\': \'Los Angeles\', \'region\': \'California\', \'country\': \'United States of America\', \'lat\': 34.05, \'lon\': -118.24, \'tz_id\': \'America/Los_Angeles\', \'localtime_epoch\': 1720592759, \'localtime\': \'2024-07-09 23:25\'}, \'current\': {\'last_updated_epoch\': 1720592100, \'last_updated\': \'2024-07-09 23:15\', \'temp_c\': 18.3, \'temp_f\': 64.9, \'is_day\': 0, \'condition\': {\'text\': \'Partly cloudy\', \'icon\': \'//cdn.weatherapi.com/weather/64x64/night/116.png\', \'code\': 1003}, \'wind_mph\': 3.8, \'wind_kph\': 6.1, \'wind_degree\': 290, \'wind_dir\': \'WNW\', \'pressure_mb\': 1010.0, \'pressure_in\': 29.83, \'precip_mm\': 0.0, \'precip_in\': 0.0, \'humidity\': 84, \'cloud\': 50, \'feelslike_c\': 18.3, \'feelslike_f\': 64.9, \'windchill_c\': 24.8, \'windchill_f\': 76.6, \'heatindex_c\': 25.7, \'heatindex_f\': 78.3, \'dewpoint_c\': 13.9, \'dewpoint_f\': 57.0, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 3.9, \'gust_kph\': 6.2}}"}]', name='tavily_search_results_json', tool_call_id='call_LFYn4VtDMAhv014a7EfZoKS4')]}
action tavily_search_results_json, result: [{'url': 'https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10', 'content': 'Weather Underground provides local & long-range weather forecasts, weatherreports, maps & tropical weather conditions for the Los Angeles area. ... Wednesday 07/10 Hourly for Tomorrow, Wed 07/10'}, {'url': 'https://www.weatherapi.com/', 'content': "{'location': {'name': 'Los Angeles', 'region': 'California', 'country': 'United States of America', 'lat': 34.05, 'lon': -118.24, 'tz_id': 'America/Los_Angeles', 'localtime_epoch': 1720592759, 'localtime': '2024-07-09 23:25'}, 'current': {'last_updated_epoch': 1720592100, 'last_updated': '2024-07-09 23:15', 'temp_c': 18.3, 'temp_f': 64.9, 'is_day': 0, 'condition': {'text': 'Partly cloudy', 'icon': '//cdn.weatherapi.com/weather/64x64/night/116.png', 'code': 1003}, 'wind_mph': 3.8, 'wind_kph': 6.1, 'wind_degree': 290, 'wind_dir': 'WNW', 'pressure_mb': 1010.0, 'pressure_in': 29.83, 'precip_mm': 0.0, 'precip_in': 0.0, 'humidity': 84, 'cloud': 50, 'feelslike_c': 18.3, 'feelslike_f': 64.9, 'windchill_c': 24.8, 'windchill_f': 76.6, 'heatindex_c': 25.7, 'heatindex_f': 78.3, 'dewpoint_c': 13.9, 'dewpoint_f': 57.0, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 3.9, 'gust_kph': 6.2}}"}]
Back to the model!
INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content='### San Francisco Weather:\n- **Temperature**: 16.1°C (61.0°F)\n- **Condition**: Partly cloudy\n- **Wind**: 9.4 mph (15.1 kph) from WNW\n- **Humidity**: 90%\n- **Visibility**: 16 km (9 miles)\n- **Pressure**: 1013 mb\n- **UV Index**: 1.0\n\n### Los Angeles Weather:\n- **Temperature**: 18.3°C (64.9°F)\n- **Condition**: Partly cloudy\n- **Wind**: 3.8 mph (6.1 kph) from WNW\n- **Humidity**: 84%\n- **Visibility**: 16 km (9 miles)\n- **Pressure**: 1010 mb\n- **UV Index**: 1.0' response_metadata={'token_usage': {'completion_tokens': 184, 'prompt_tokens': 1190, 'total_tokens': 1374}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_4008e3b719', 'finish_reason': 'stop', 'logprobs': None} id='run-c8c63c14-0b42-4b2a-8a52-5542b14311f5-0' usage_metadata={'input_tokens': 1190, 'output_tokens': 184, 'total_tokens': 1374}
INFO:__main__:exists_action result: content='### San Francisco Weather:\n- **Temperature**: 16.1°C (61.0°F)\n- **Condition**: Partly cloudy\n- **Wind**: 9.4 mph (15.1 kph) from WNW\n- **Humidity**: 90%\n- **Visibility**: 16 km (9 miles)\n- **Pressure**: 1013 mb\n- **UV Index**: 1.0\n\n### Los Angeles Weather:\n- **Temperature**: 18.3°C (64.9°F)\n- **Condition**: Partly cloudy\n- **Wind**: 3.8 mph (6.1 kph) from WNW\n- **Humidity**: 84%\n- **Visibility**: 16 km (9 miles)\n- **Pressure**: 1010 mb\n- **UV Index**: 1.0' response_metadata={'token_usage': {'completion_tokens': 184, 'prompt_tokens': 1190, 'total_tokens': 1374}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_4008e3b719', 'finish_reason': 'stop', 'logprobs': None} id='run-c8c63c14-0b42-4b2a-8a52-5542b14311f5-0' usage_metadata={'input_tokens': 1190, 'output_tokens': 184, 'total_tokens': 1374}
result['messages'][-1].content
'### San Francisco Weather:\n- **Temperature**: 16.1°C (61.0°F)\n- **Condition**: Partly cloudy\n- **Wind**: 9.4 mph (15.1 kph) from WNW\n- **Humidity**: 90%\n- **Visibility**: 16 km (9 miles)\n- **Pressure**: 1013 mb\n- **UV Index**: 1.0\n\n### Los Angeles Weather:\n- **Temperature**: 18.3°C (64.9°F)\n- **Condition**: Partly cloudy\n- **Wind**: 3.8 mph (6.1 kph) from WNW\n- **Humidity**: 84%\n- **Visibility**: 16 km (9 miles)\n- **Pressure**: 1010 mb\n- **UV Index**: 1.0'
query = "Who won the super bowl in 2024? In what state is the winning team headquarters located? \
What is the GDP of that state? Answer each question."
messages = [HumanMessage(content=query)]
result = abot.graph.invoke({"messages": messages})
INFO:__main__:state: {'messages': [HumanMessage(content='Who won the super bowl in 2024? In what state is the winning team headquarters located? What is the GDP of that state? Answer each question.')]}
INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content='' additional_kwargs={'tool_calls': [{'id': 'call_r4Su82QJqD03HLQ2Anh5f6eG', 'function': {'arguments': '{"query": "Super Bowl 2024 winner"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}, {'id': 'call_uNfBjk7uNU7yuDj0HEkgIzsc', 'function': {'arguments': '{"query": "GDP of state where the Super Bowl 2024 winning team is located"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]} response_metadata={'token_usage': {'completion_tokens': 70, 'prompt_tokens': 177, 'total_tokens': 247}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_298125635f', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-c9583580-7404-491a-9e08-69fab8c54719-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'Super Bowl 2024 winner'}, 'id': 'call_r4Su82QJqD03HLQ2Anh5f6eG'}, {'name': 'tavily_search_results_json', 'args': {'query': 'GDP of state where the Super Bowl 2024 winning team is located'}, 'id': 'call_uNfBjk7uNU7yuDj0HEkgIzsc'}] usage_metadata={'input_tokens': 177, 'output_tokens': 70, 'total_tokens': 247}
INFO:__main__:exists_action result: content='' additional_kwargs={'tool_calls': [{'id': 'call_r4Su82QJqD03HLQ2Anh5f6eG', 'function': {'arguments': '{"query": "Super Bowl 2024 winner"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}, {'id': 'call_uNfBjk7uNU7yuDj0HEkgIzsc', 'function': {'arguments': '{"query": "GDP of state where the Super Bowl 2024 winning team is located"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]} response_metadata={'token_usage': {'completion_tokens': 70, 'prompt_tokens': 177, 'total_tokens': 247}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_298125635f', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-c9583580-7404-491a-9e08-69fab8c54719-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'Super Bowl 2024 winner'}, 'id': 'call_r4Su82QJqD03HLQ2Anh5f6eG'}, {'name': 'tavily_search_results_json', 'args': {'query': 'GDP of state where the Super Bowl 2024 winning team is located'}, 'id': 'call_uNfBjk7uNU7yuDj0HEkgIzsc'}] usage_metadata={'input_tokens': 177, 'output_tokens': 70, 'total_tokens': 247}
INFO:__main__:Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'Super Bowl 2024 winner'}, 'id': 'call_r4Su82QJqD03HLQ2Anh5f6eG'}
take_action called in thread: ThreadPoolExecutor-2_0
take_action called with tool_calls: [{'name': 'tavily_search_results_json', 'args': {'query': 'Super Bowl 2024 winner'}, 'id': 'call_r4Su82QJqD03HLQ2Anh5f6eG'}, {'name': 'tavily_search_results_json', 'args': {'query': 'GDP of state where the Super Bowl 2024 winning team is located'}, 'id': 'call_uNfBjk7uNU7yuDj0HEkgIzsc'}]
Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'Super Bowl 2024 winner'}, 'id': 'call_r4Su82QJqD03HLQ2Anh5f6eG'}
INFO:__main__:action tavily_search_results_json, result: [{'url': 'https://apnews.com/live/super-bowl-2024-updates', 'content': 'Throw in the fact that Chiefs coach Andy Reid will be in his fifth Super Bowl, the third most in NFL history, and has a chance to win a third ring, and the knowledge on the Kansas City sideline will be an advantage too big for the 49ers to overcome.\n She performed in Japan on Saturday night before a flight across nine time zones and the international date line to reach the U.S.\nRihanna performs during halftime of the NFL Super Bowl 57 football game between the Philadelphia Eagles and the Kansas City Chiefs, Sunday, Feb. 12, 2023, in Glendale, Ariz. (AP Photo/David J. Phillip)\n After the teams take the field, Post Malone will perform “America the Beautiful” and Reba McEntire will sing “The Star-Spangled Banner.”\nSan Francisco 49ers quarterback Brock Purdy (13) warms up before the NFL Super Bowl 58 football game against the Kansas City Chiefs, Sunday, Feb. 11, 2024, in Las Vegas. He was also the referee when the Chiefs beat the 49ers in the Super Bowl four years ago — and when the Rams beat the Saints in the 2019 NFC championship game after an infamous missed call.\n Purdy’s comeback from the injury to his throwing arm suffered in last season’s NFC championship loss to the Philadelphia Eagles has been part of the storybook start to his career that started as Mr. Irrelevant as the 262nd pick in the 2022 draft.\n'}, {'url': 'https://www.cbssports.com/nfl/news/2024-super-bowl-chiefs-vs-49ers-score-patrick-mahomes-leads-ot-comeback-as-k-c-wins-back-to-back-titles/live/', 'content': "The championship-winning drive, which included a fourth-and-1 scramble from Mahomes and a clutch 7-yard catch from tight end Travis Kelce, was a must-score for K.C. The NFL's new playoff overtime rules -- both teams are guaranteed at least one possession in the extra period -- were in effect for the first time, and the Chiefs needed to answer the Niners' field goal.\n Held out of the end zone until that point, Kansas City grabbed its first lead of the game at 13-10.\nJennings' touchdown receiving (followed by a missed extra point) concluded a 75-yard drive that put the Niners back on top, 16-13, as the wideout joined former Philadelphia Eagles quarterback Nick Foles as the only players to throw and catch a touchdown in a Super Bowl.\n He spread the ball around -- eight pass-catchers had at least two receptions -- slowly but surely overcoming a threatening 49ers defense that knocked him off his spot consistently in the first half.\nMahomes, with his third Super Bowl MVP, now sits alongside Tom Brady (five) and Joe Montana (three) atop the mountain while becoming just the third player to win the award back-to-back, joining Bart Starr (I-II) and Terry Bradshaw (XIII-XIV).\n The muffed punt that bounced off of cornerback Darrell Luter Jr.'s ankle was also the big break that the Chiefs needed as they scored on the very next play to take the lead for the first time in the game. College Pick'em\nA Daily SportsLine Betting Podcast\nNFL Playoff Time!\n2024 Super Bowl, Chiefs vs. 49ers score: Patrick Mahomes leads OT comeback as K.C. wins back-to-back titles\nCall it a dynasty; the Chiefs are the first team to win consecutive Super Bowls since 2003-04\nThe Kansas City Chiefs are Super Bowl champions, again."}]
INFO:__main__:Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'GDP of state where the Super Bowl 2024 winning team is located'}, 'id': 'call_uNfBjk7uNU7yuDj0HEkgIzsc'}
action tavily_search_results_json, result: [{'url': 'https://apnews.com/live/super-bowl-2024-updates', 'content': 'Throw in the fact that Chiefs coach Andy Reid will be in his fifth Super Bowl, the third most in NFL history, and has a chance to win a third ring, and the knowledge on the Kansas City sideline will be an advantage too big for the 49ers to overcome.\n She performed in Japan on Saturday night before a flight across nine time zones and the international date line to reach the U.S.\nRihanna performs during halftime of the NFL Super Bowl 57 football game between the Philadelphia Eagles and the Kansas City Chiefs, Sunday, Feb. 12, 2023, in Glendale, Ariz. (AP Photo/David J. Phillip)\n After the teams take the field, Post Malone will perform “America the Beautiful” and Reba McEntire will sing “The Star-Spangled Banner.”\nSan Francisco 49ers quarterback Brock Purdy (13) warms up before the NFL Super Bowl 58 football game against the Kansas City Chiefs, Sunday, Feb. 11, 2024, in Las Vegas. He was also the referee when the Chiefs beat the 49ers in the Super Bowl four years ago — and when the Rams beat the Saints in the 2019 NFC championship game after an infamous missed call.\n Purdy’s comeback from the injury to his throwing arm suffered in last season’s NFC championship loss to the Philadelphia Eagles has been part of the storybook start to his career that started as Mr. Irrelevant as the 262nd pick in the 2022 draft.\n'}, {'url': 'https://www.cbssports.com/nfl/news/2024-super-bowl-chiefs-vs-49ers-score-patrick-mahomes-leads-ot-comeback-as-k-c-wins-back-to-back-titles/live/', 'content': "The championship-winning drive, which included a fourth-and-1 scramble from Mahomes and a clutch 7-yard catch from tight end Travis Kelce, was a must-score for K.C. The NFL's new playoff overtime rules -- both teams are guaranteed at least one possession in the extra period -- were in effect for the first time, and the Chiefs needed to answer the Niners' field goal.\n Held out of the end zone until that point, Kansas City grabbed its first lead of the game at 13-10.\nJennings' touchdown receiving (followed by a missed extra point) concluded a 75-yard drive that put the Niners back on top, 16-13, as the wideout joined former Philadelphia Eagles quarterback Nick Foles as the only players to throw and catch a touchdown in a Super Bowl.\n He spread the ball around -- eight pass-catchers had at least two receptions -- slowly but surely overcoming a threatening 49ers defense that knocked him off his spot consistently in the first half.\nMahomes, with his third Super Bowl MVP, now sits alongside Tom Brady (five) and Joe Montana (three) atop the mountain while becoming just the third player to win the award back-to-back, joining Bart Starr (I-II) and Terry Bradshaw (XIII-XIV).\n The muffed punt that bounced off of cornerback Darrell Luter Jr.'s ankle was also the big break that the Chiefs needed as they scored on the very next play to take the lead for the first time in the game. College Pick'em\nA Daily SportsLine Betting Podcast\nNFL Playoff Time!\n2024 Super Bowl, Chiefs vs. 49ers score: Patrick Mahomes leads OT comeback as K.C. wins back-to-back titles\nCall it a dynasty; the Chiefs are the first team to win consecutive Super Bowls since 2003-04\nThe Kansas City Chiefs are Super Bowl champions, again."}]
Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'GDP of state where the Super Bowl 2024 winning team is located'}, 'id': 'call_uNfBjk7uNU7yuDj0HEkgIzsc'}
INFO:__main__:action tavily_search_results_json, result: [{'url': 'https://www.forbes.com/sites/jefffedotin/2024/06/03/super-bowl-lviii-generated-1-billion-economic-impact-for-las-vegas/', 'content': 'An average of 123.7 million watched the Kansas City Chiefs defeat the San Francisco 49ers in a 25-22, overtime classic on Super Bowl Sunday, but for Las Vegas, the economic impact started much ...'}, {'url': 'https://www.rollingstone.com/culture/culture-features/2024-super-bowl-helping-las-vegas-economy-1234964688/', 'content': "The 2024 Super Bowl Is Helping Las Vegas' Economy More Than Usual. big profits. Las Vegas Spent Decades Deprived of the Super Bowl. Now It Could Bring in $700 Million. After years of the NFL ..."}]
INFO:__main__:state: {'messages': [HumanMessage(content='Who won the super bowl in 2024? In what state is the winning team headquarters located? What is the GDP of that state? Answer each question.'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_r4Su82QJqD03HLQ2Anh5f6eG', 'function': {'arguments': '{"query": "Super Bowl 2024 winner"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}, {'id': 'call_uNfBjk7uNU7yuDj0HEkgIzsc', 'function': {'arguments': '{"query": "GDP of state where the Super Bowl 2024 winning team is located"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 70, 'prompt_tokens': 177, 'total_tokens': 247}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_298125635f', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-c9583580-7404-491a-9e08-69fab8c54719-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'Super Bowl 2024 winner'}, 'id': 'call_r4Su82QJqD03HLQ2Anh5f6eG'}, {'name': 'tavily_search_results_json', 'args': {'query': 'GDP of state where the Super Bowl 2024 winning team is located'}, 'id': 'call_uNfBjk7uNU7yuDj0HEkgIzsc'}], usage_metadata={'input_tokens': 177, 'output_tokens': 70, 'total_tokens': 247}), ToolMessage(content='[{\'url\': \'https://apnews.com/live/super-bowl-2024-updates\', \'content\': \'Throw in the fact that Chiefs coach Andy Reid will be in his fifth Super Bowl, the third most in NFL history, and has a chance to win a third ring, and the knowledge on the Kansas City sideline will be an advantage too big for the 49ers to overcome.\\n She performed in Japan on Saturday night before a flight across nine time zones and the international date line to reach the U.S.\\nRihanna performs during halftime of the NFL Super Bowl 57 football game between the Philadelphia Eagles and the Kansas City Chiefs, Sunday, Feb. 12, 2023, in Glendale, Ariz. (AP Photo/David J. Phillip)\\n After the teams take the field, Post Malone will perform “America the Beautiful” and Reba McEntire will sing “The Star-Spangled Banner.”\\nSan Francisco 49ers quarterback Brock Purdy (13) warms up before the NFL Super Bowl 58 football game against the Kansas City Chiefs, Sunday, Feb. 11, 2024, in Las Vegas. He was also the referee when the Chiefs beat the 49ers in the Super Bowl four years ago — and when the Rams beat the Saints in the 2019 NFC championship game after an infamous missed call.\\n Purdy’s comeback from the injury to his throwing arm suffered in last season’s NFC championship loss to the Philadelphia Eagles has been part of the storybook start to his career that started as Mr. Irrelevant as the 262nd pick in the 2022 draft.\\n\'}, {\'url\': \'https://www.cbssports.com/nfl/news/2024-super-bowl-chiefs-vs-49ers-score-patrick-mahomes-leads-ot-comeback-as-k-c-wins-back-to-back-titles/live/\', \'content\': "The championship-winning drive, which included a fourth-and-1 scramble from Mahomes and a clutch 7-yard catch from tight end Travis Kelce, was a must-score for K.C. The NFL\'s new playoff overtime rules -- both teams are guaranteed at least one possession in the extra period -- were in effect for the first time, and the Chiefs needed to answer the Niners\' field goal.\\n Held out of the end zone until that point, Kansas City grabbed its first lead of the game at 13-10.\\nJennings\' touchdown receiving (followed by a missed extra point) concluded a 75-yard drive that put the Niners back on top, 16-13, as the wideout joined former Philadelphia Eagles quarterback Nick Foles as the only players to throw and catch a touchdown in a Super Bowl.\\n He spread the ball around -- eight pass-catchers had at least two receptions -- slowly but surely overcoming a threatening 49ers defense that knocked him off his spot consistently in the first half.\\nMahomes, with his third Super Bowl MVP, now sits alongside Tom Brady (five) and Joe Montana (three) atop the mountain while becoming just the third player to win the award back-to-back, joining Bart Starr (I-II) and Terry Bradshaw (XIII-XIV).\\n The muffed punt that bounced off of cornerback Darrell Luter Jr.\'s ankle was also the big break that the Chiefs needed as they scored on the very next play to take the lead for the first time in the game. College Pick\'em\\nA Daily SportsLine Betting Podcast\\nNFL Playoff Time!\\n2024 Super Bowl, Chiefs vs. 49ers score: Patrick Mahomes leads OT comeback as K.C. wins back-to-back titles\\nCall it a dynasty; the Chiefs are the first team to win consecutive Super Bowls since 2003-04\\nThe Kansas City Chiefs are Super Bowl champions, again."}]', name='tavily_search_results_json', tool_call_id='call_r4Su82QJqD03HLQ2Anh5f6eG'), ToolMessage(content='[{\'url\': \'https://www.forbes.com/sites/jefffedotin/2024/06/03/super-bowl-lviii-generated-1-billion-economic-impact-for-las-vegas/\', \'content\': \'An average of 123.7 million watched the Kansas City Chiefs defeat the San Francisco 49ers in a 25-22, overtime classic on Super Bowl Sunday, but for Las Vegas, the economic impact started much ...\'}, {\'url\': \'https://www.rollingstone.com/culture/culture-features/2024-super-bowl-helping-las-vegas-economy-1234964688/\', \'content\': "The 2024 Super Bowl Is Helping Las Vegas\' Economy More Than Usual. big profits. Las Vegas Spent Decades Deprived of the Super Bowl. Now It Could Bring in $700 Million. After years of the NFL ..."}]', name='tavily_search_results_json', tool_call_id='call_uNfBjk7uNU7yuDj0HEkgIzsc')]}
action tavily_search_results_json, result: [{'url': 'https://www.forbes.com/sites/jefffedotin/2024/06/03/super-bowl-lviii-generated-1-billion-economic-impact-for-las-vegas/', 'content': 'An average of 123.7 million watched the Kansas City Chiefs defeat the San Francisco 49ers in a 25-22, overtime classic on Super Bowl Sunday, but for Las Vegas, the economic impact started much ...'}, {'url': 'https://www.rollingstone.com/culture/culture-features/2024-super-bowl-helping-las-vegas-economy-1234964688/', 'content': "The 2024 Super Bowl Is Helping Las Vegas' Economy More Than Usual. big profits. Las Vegas Spent Decades Deprived of the Super Bowl. Now It Could Bring in $700 Million. After years of the NFL ..."}]
Back to the model!
INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content='1. The Kansas City Chiefs won the Super Bowl in 2024.\n2. The headquarters of the Kansas City Chiefs is located in Kansas City, Missouri.\n3. I will now look up the GDP of Missouri.' additional_kwargs={'tool_calls': [{'id': 'call_yHyeCHMR88aog66cjLdOYTYf', 'function': {'arguments': '{"query":"GDP of Missouri 2024"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]} response_metadata={'token_usage': {'completion_tokens': 68, 'prompt_tokens': 1267, 'total_tokens': 1335}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-dfad5985-c34f-4c56-ab0f-7eec127e4419-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'GDP of Missouri 2024'}, 'id': 'call_yHyeCHMR88aog66cjLdOYTYf'}] usage_metadata={'input_tokens': 1267, 'output_tokens': 68, 'total_tokens': 1335}
INFO:__main__:exists_action result: content='1. The Kansas City Chiefs won the Super Bowl in 2024.\n2. The headquarters of the Kansas City Chiefs is located in Kansas City, Missouri.\n3. I will now look up the GDP of Missouri.' additional_kwargs={'tool_calls': [{'id': 'call_yHyeCHMR88aog66cjLdOYTYf', 'function': {'arguments': '{"query":"GDP of Missouri 2024"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]} response_metadata={'token_usage': {'completion_tokens': 68, 'prompt_tokens': 1267, 'total_tokens': 1335}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-dfad5985-c34f-4c56-ab0f-7eec127e4419-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'GDP of Missouri 2024'}, 'id': 'call_yHyeCHMR88aog66cjLdOYTYf'}] usage_metadata={'input_tokens': 1267, 'output_tokens': 68, 'total_tokens': 1335}
INFO:__main__:Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'GDP of Missouri 2024'}, 'id': 'call_yHyeCHMR88aog66cjLdOYTYf'}
take_action called in thread: ThreadPoolExecutor-2_0
take_action called with tool_calls: [{'name': 'tavily_search_results_json', 'args': {'query': 'GDP of Missouri 2024'}, 'id': 'call_yHyeCHMR88aog66cjLdOYTYf'}]
Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'GDP of Missouri 2024'}, 'id': 'call_yHyeCHMR88aog66cjLdOYTYf'}
INFO:__main__:action tavily_search_results_json, result: [{'url': 'https://usafacts.org/topics/economy/state/missouri/', 'content': "Real gross domestic product (GDP) Missouri's share of the US economy. Real gross domestic product (GDP) by industry. ... A majority of funding for the 2024 election — over 65%, or nearly $5.6 billion — comes from political action committees, also known as PACs. Published on May 17, 2024."}, {'url': 'https://www.bea.gov/data/gdp/gdp-state', 'content': 'Gross Domestic Product by State and Personal Income by State, 1st Quarter 2024. Real gross domestic product (GDP) increased in 39 states and the District of Columbia in the first quarter of 2024, with the percent change ranging from 5.0 percent at an annual rate in Idaho to -4.2 percent in South Dakota. Current Release. Current Release: June ...'}]
INFO:__main__:state: {'messages': [HumanMessage(content='Who won the super bowl in 2024? In what state is the winning team headquarters located? What is the GDP of that state? Answer each question.'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_r4Su82QJqD03HLQ2Anh5f6eG', 'function': {'arguments': '{"query": "Super Bowl 2024 winner"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}, {'id': 'call_uNfBjk7uNU7yuDj0HEkgIzsc', 'function': {'arguments': '{"query": "GDP of state where the Super Bowl 2024 winning team is located"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 70, 'prompt_tokens': 177, 'total_tokens': 247}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_298125635f', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-c9583580-7404-491a-9e08-69fab8c54719-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'Super Bowl 2024 winner'}, 'id': 'call_r4Su82QJqD03HLQ2Anh5f6eG'}, {'name': 'tavily_search_results_json', 'args': {'query': 'GDP of state where the Super Bowl 2024 winning team is located'}, 'id': 'call_uNfBjk7uNU7yuDj0HEkgIzsc'}], usage_metadata={'input_tokens': 177, 'output_tokens': 70, 'total_tokens': 247}), ToolMessage(content='[{\'url\': \'https://apnews.com/live/super-bowl-2024-updates\', \'content\': \'Throw in the fact that Chiefs coach Andy Reid will be in his fifth Super Bowl, the third most in NFL history, and has a chance to win a third ring, and the knowledge on the Kansas City sideline will be an advantage too big for the 49ers to overcome.\\n She performed in Japan on Saturday night before a flight across nine time zones and the international date line to reach the U.S.\\nRihanna performs during halftime of the NFL Super Bowl 57 football game between the Philadelphia Eagles and the Kansas City Chiefs, Sunday, Feb. 12, 2023, in Glendale, Ariz. (AP Photo/David J. Phillip)\\n After the teams take the field, Post Malone will perform “America the Beautiful” and Reba McEntire will sing “The Star-Spangled Banner.”\\nSan Francisco 49ers quarterback Brock Purdy (13) warms up before the NFL Super Bowl 58 football game against the Kansas City Chiefs, Sunday, Feb. 11, 2024, in Las Vegas. He was also the referee when the Chiefs beat the 49ers in the Super Bowl four years ago — and when the Rams beat the Saints in the 2019 NFC championship game after an infamous missed call.\\n Purdy’s comeback from the injury to his throwing arm suffered in last season’s NFC championship loss to the Philadelphia Eagles has been part of the storybook start to his career that started as Mr. Irrelevant as the 262nd pick in the 2022 draft.\\n\'}, {\'url\': \'https://www.cbssports.com/nfl/news/2024-super-bowl-chiefs-vs-49ers-score-patrick-mahomes-leads-ot-comeback-as-k-c-wins-back-to-back-titles/live/\', \'content\': "The championship-winning drive, which included a fourth-and-1 scramble from Mahomes and a clutch 7-yard catch from tight end Travis Kelce, was a must-score for K.C. The NFL\'s new playoff overtime rules -- both teams are guaranteed at least one possession in the extra period -- were in effect for the first time, and the Chiefs needed to answer the Niners\' field goal.\\n Held out of the end zone until that point, Kansas City grabbed its first lead of the game at 13-10.\\nJennings\' touchdown receiving (followed by a missed extra point) concluded a 75-yard drive that put the Niners back on top, 16-13, as the wideout joined former Philadelphia Eagles quarterback Nick Foles as the only players to throw and catch a touchdown in a Super Bowl.\\n He spread the ball around -- eight pass-catchers had at least two receptions -- slowly but surely overcoming a threatening 49ers defense that knocked him off his spot consistently in the first half.\\nMahomes, with his third Super Bowl MVP, now sits alongside Tom Brady (five) and Joe Montana (three) atop the mountain while becoming just the third player to win the award back-to-back, joining Bart Starr (I-II) and Terry Bradshaw (XIII-XIV).\\n The muffed punt that bounced off of cornerback Darrell Luter Jr.\'s ankle was also the big break that the Chiefs needed as they scored on the very next play to take the lead for the first time in the game. College Pick\'em\\nA Daily SportsLine Betting Podcast\\nNFL Playoff Time!\\n2024 Super Bowl, Chiefs vs. 49ers score: Patrick Mahomes leads OT comeback as K.C. wins back-to-back titles\\nCall it a dynasty; the Chiefs are the first team to win consecutive Super Bowls since 2003-04\\nThe Kansas City Chiefs are Super Bowl champions, again."}]', name='tavily_search_results_json', tool_call_id='call_r4Su82QJqD03HLQ2Anh5f6eG'), ToolMessage(content='[{\'url\': \'https://www.forbes.com/sites/jefffedotin/2024/06/03/super-bowl-lviii-generated-1-billion-economic-impact-for-las-vegas/\', \'content\': \'An average of 123.7 million watched the Kansas City Chiefs defeat the San Francisco 49ers in a 25-22, overtime classic on Super Bowl Sunday, but for Las Vegas, the economic impact started much ...\'}, {\'url\': \'https://www.rollingstone.com/culture/culture-features/2024-super-bowl-helping-las-vegas-economy-1234964688/\', \'content\': "The 2024 Super Bowl Is Helping Las Vegas\' Economy More Than Usual. big profits. Las Vegas Spent Decades Deprived of the Super Bowl. Now It Could Bring in $700 Million. After years of the NFL ..."}]', name='tavily_search_results_json', tool_call_id='call_uNfBjk7uNU7yuDj0HEkgIzsc'), AIMessage(content='1. The Kansas City Chiefs won the Super Bowl in 2024.\n2. The headquarters of the Kansas City Chiefs is located in Kansas City, Missouri.\n3. I will now look up the GDP of Missouri.', additional_kwargs={'tool_calls': [{'id': 'call_yHyeCHMR88aog66cjLdOYTYf', 'function': {'arguments': '{"query":"GDP of Missouri 2024"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 68, 'prompt_tokens': 1267, 'total_tokens': 1335}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-dfad5985-c34f-4c56-ab0f-7eec127e4419-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'GDP of Missouri 2024'}, 'id': 'call_yHyeCHMR88aog66cjLdOYTYf'}], usage_metadata={'input_tokens': 1267, 'output_tokens': 68, 'total_tokens': 1335}), ToolMessage(content='[{\'url\': \'https://usafacts.org/topics/economy/state/missouri/\', \'content\': "Real gross domestic product (GDP) Missouri\'s share of the US economy. Real gross domestic product (GDP) by industry. ... A majority of funding for the 2024 election — over 65%, or nearly $5.6 billion — comes from political action committees, also known as PACs. Published on May 17, 2024."}, {\'url\': \'https://www.bea.gov/data/gdp/gdp-state\', \'content\': \'Gross Domestic Product by State and Personal Income by State, 1st Quarter 2024. Real gross domestic product (GDP) increased in 39 states and the District of Columbia in the first quarter of 2024, with the percent change ranging from 5.0 percent at an annual rate in Idaho to -4.2 percent in South Dakota. Current Release. Current Release: June ...\'}]', name='tavily_search_results_json', tool_call_id='call_yHyeCHMR88aog66cjLdOYTYf')]}
action tavily_search_results_json, result: [{'url': 'https://usafacts.org/topics/economy/state/missouri/', 'content': "Real gross domestic product (GDP) Missouri's share of the US economy. Real gross domestic product (GDP) by industry. ... A majority of funding for the 2024 election — over 65%, or nearly $5.6 billion — comes from political action committees, also known as PACs. Published on May 17, 2024."}, {'url': 'https://www.bea.gov/data/gdp/gdp-state', 'content': 'Gross Domestic Product by State and Personal Income by State, 1st Quarter 2024. Real gross domestic product (GDP) increased in 39 states and the District of Columbia in the first quarter of 2024, with the percent change ranging from 5.0 percent at an annual rate in Idaho to -4.2 percent in South Dakota. Current Release. Current Release: June ...'}]
Back to the model!
INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content="1. **Super Bowl 2024 Winner**: The Kansas City Chiefs won the Super Bowl in 2024.\n2. **Location of Winning Team's Headquarters**: The headquarters of the Kansas City Chiefs is located in Kansas City, Missouri.\n3. **GDP of Missouri**: The most recent data indicates that Missouri's GDP is detailed on the [Bureau of Economic Analysis (BEA) website](https://www.bea.gov/data/gdp/gdp-state). As of the first quarter of 2024, Missouri is part of the states where the real gross domestic product (GDP) increased, but specific figures for Missouri's GDP in 2024 were not provided in the search results. For precise and updated figures, you can check the BEA's latest release on state GDP." response_metadata={'token_usage': {'completion_tokens': 162, 'prompt_tokens': 1549, 'total_tokens': 1711}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'stop', 'logprobs': None} id='run-3d28fe7f-51c1-40d1-85eb-45689a3cd2bd-0' usage_metadata={'input_tokens': 1549, 'output_tokens': 162, 'total_tokens': 1711}
INFO:__main__:exists_action result: content="1. **Super Bowl 2024 Winner**: The Kansas City Chiefs won the Super Bowl in 2024.\n2. **Location of Winning Team's Headquarters**: The headquarters of the Kansas City Chiefs is located in Kansas City, Missouri.\n3. **GDP of Missouri**: The most recent data indicates that Missouri's GDP is detailed on the [Bureau of Economic Analysis (BEA) website](https://www.bea.gov/data/gdp/gdp-state). As of the first quarter of 2024, Missouri is part of the states where the real gross domestic product (GDP) increased, but specific figures for Missouri's GDP in 2024 were not provided in the search results. For precise and updated figures, you can check the BEA's latest release on state GDP." response_metadata={'token_usage': {'completion_tokens': 162, 'prompt_tokens': 1549, 'total_tokens': 1711}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'stop', 'logprobs': None} id='run-3d28fe7f-51c1-40d1-85eb-45689a3cd2bd-0' usage_metadata={'input_tokens': 1549, 'output_tokens': 162, 'total_tokens': 1711}
print(result['messages'][-1].content)
1. **Super Bowl 2024 Winner**: The Kansas City Chiefs won the Super Bowl in 2024.
2. **Location of Winning Team's Headquarters**: The headquarters of the Kansas City Chiefs is located in Kansas City, Missouri.
3. **GDP of Missouri**: The most recent data indicates that Missouri's GDP is detailed on the [Bureau of Economic Analysis (BEA) website](https://www.bea.gov/data/gdp/gdp-state). As of the first quarter of 2024, Missouri is part of the states where the real gross domestic product (GDP) increased, but specific figures for Missouri's GDP in 2024 were not provided in the search results. For precise and updated figures, you can check the BEA's latest release on state GDP.
he first quarter of 2024, Missouri is part of the states where the real gross domestic product (GDP) increased, but specific figures for Missouri's GDP in 2024 were not provided in the search results. For precise and updated figures, you can check the BEA's latest release on state GDP.