L4 Persistence and Streaming

参考自https://www.deeplearning.ai/short-courses/ai-agents-in-langgraph,以下为代码的实现。

  • 这里主要是加入了memory,这样通过self.graph = graph.compile(checkpointer=checkpointer)就可以加入持久性的检查点
  • 通过thread = {"configurable": {"thread_id": "1"}}指示线程id和其对应的持久性的检查点
  • SqliteSaver使用Sqlite数据库进行流式处理
  • 把检查点的SqliteSaver改成异步的AsyncSqliteSaver,可以在token级进行流式处理
import os
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
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)
class AgentState(TypedDict):
    messages: Annotated[list[AnyMessage], operator.add]
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
from langgraph.checkpoint.sqlite import SqliteSaver

memory = SqliteSaver.from_conn_string(":memory:")
class Agent:
    def __init__(self, model, tools, checkpointer, 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(checkpointer=checkpointer)
        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")
abot = Agent(model, [tool], system=prompt, checkpointer=memory)
INFO:__main__:model: bound=ChatOpenAI(client=<openai.resources.chat.completions.Completions object at 0x000002A44F2D6CC0>, async_client=<openai.resources.chat.completions.AsyncCompletions object at 0x000002A44AEE7920>, 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']}}}]}
messages = [HumanMessage(content="What is the weather in sf?")]
thread = {"configurable": {"thread_id": "1"}}
for event in abot.graph.stream({"messages": messages}, thread):
    for v in event.values():
        print(v['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_DymVmpw1GN1w4gvOLU93NB1B', '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': 151, 'total_tokens': 173}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-a3434171-5959-4b14-ae38-2b41105ef13a-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}] usage_metadata={'input_tokens': 151, 'output_tokens': 22, 'total_tokens': 173}
INFO:__main__:exists_action result: content='' additional_kwargs={'tool_calls': [{'id': 'call_DymVmpw1GN1w4gvOLU93NB1B', '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': 151, 'total_tokens': 173}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-a3434171-5959-4b14-ae38-2b41105ef13a-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}] usage_metadata={'input_tokens': 151, 'output_tokens': 22, 'total_tokens': 173}
INFO:__main__:Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}


[AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_DymVmpw1GN1w4gvOLU93NB1B', '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': 151, 'total_tokens': 173}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-a3434171-5959-4b14-ae38-2b41105ef13a-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}], usage_metadata={'input_tokens': 151, 'output_tokens': 22, 'total_tokens': 173})]
take_action called in thread: ThreadPoolExecutor-0_1
take_action called with tool_calls: [{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}]
Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}


INFO:__main__:action tavily_search_results_json, result: HTTPError('502 Server Error: Bad Gateway for url: https://api.tavily.com/search')
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in sf?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_DymVmpw1GN1w4gvOLU93NB1B', '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': 151, 'total_tokens': 173}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-a3434171-5959-4b14-ae38-2b41105ef13a-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}], usage_metadata={'input_tokens': 151, 'output_tokens': 22, 'total_tokens': 173}), ToolMessage(content="HTTPError('502 Server Error: Bad Gateway for url: https://api.tavily.com/search')", name='tavily_search_results_json', tool_call_id='call_DymVmpw1GN1w4gvOLU93NB1B')]}


action tavily_search_results_json, result: HTTPError('502 Server Error: Bad Gateway for url: https://api.tavily.com/search')
Back to the model!
[ToolMessage(content="HTTPError('502 Server Error: Bad Gateway for url: https://api.tavily.com/search')", name='tavily_search_results_json', tool_call_id='call_DymVmpw1GN1w4gvOLU93NB1B')]


INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content="It seems there was an issue retrieving the current weather information for San Francisco. You might want to check a reliable weather service like Weather.com, AccuWeather, or a similar platform for real-time updates. Alternatively, I can try searching again if you'd like." response_metadata={'token_usage': {'completion_tokens': 53, 'prompt_tokens': 206, 'total_tokens': 259}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None} id='run-480cf4e1-eae8-4d33-aeb7-0c662f441e69-0' usage_metadata={'input_tokens': 206, 'output_tokens': 53, 'total_tokens': 259}
INFO:__main__:exists_action result: content="It seems there was an issue retrieving the current weather information for San Francisco. You might want to check a reliable weather service like Weather.com, AccuWeather, or a similar platform for real-time updates. Alternatively, I can try searching again if you'd like." response_metadata={'token_usage': {'completion_tokens': 53, 'prompt_tokens': 206, 'total_tokens': 259}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None} id='run-480cf4e1-eae8-4d33-aeb7-0c662f441e69-0' usage_metadata={'input_tokens': 206, 'output_tokens': 53, 'total_tokens': 259}


[AIMessage(content="It seems there was an issue retrieving the current weather information for San Francisco. You might want to check a reliable weather service like Weather.com, AccuWeather, or a similar platform for real-time updates. Alternatively, I can try searching again if you'd like.", response_metadata={'token_usage': {'completion_tokens': 53, 'prompt_tokens': 206, 'total_tokens': 259}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-480cf4e1-eae8-4d33-aeb7-0c662f441e69-0', usage_metadata={'input_tokens': 206, 'output_tokens': 53, 'total_tokens': 259})]
messages = [HumanMessage(content="What about in la?")]
thread = {"configurable": {"thread_id": "1"}}
for event in abot.graph.stream({"messages": messages}, thread):
    for v in event.values():
        print(v)
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in sf?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_DymVmpw1GN1w4gvOLU93NB1B', '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': 151, 'total_tokens': 173}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-a3434171-5959-4b14-ae38-2b41105ef13a-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}], usage_metadata={'input_tokens': 151, 'output_tokens': 22, 'total_tokens': 173}), ToolMessage(content="HTTPError('502 Server Error: Bad Gateway for url: https://api.tavily.com/search')", name='tavily_search_results_json', tool_call_id='call_DymVmpw1GN1w4gvOLU93NB1B'), AIMessage(content="It seems there was an issue retrieving the current weather information for San Francisco. You might want to check a reliable weather service like Weather.com, AccuWeather, or a similar platform for real-time updates. Alternatively, I can try searching again if you'd like.", response_metadata={'token_usage': {'completion_tokens': 53, 'prompt_tokens': 206, 'total_tokens': 259}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-480cf4e1-eae8-4d33-aeb7-0c662f441e69-0', usage_metadata={'input_tokens': 206, 'output_tokens': 53, 'total_tokens': 259}), HumanMessage(content='What about in 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_YGg74jViWh6jr0L8cOyxe225', 'function': {'arguments': '{"query":"current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]} response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 271, 'total_tokens': 293}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-fd07dbe8-e079-4044-ac7b-c9c0aa185333-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}] usage_metadata={'input_tokens': 271, 'output_tokens': 22, 'total_tokens': 293}
INFO:__main__:exists_action result: content='' additional_kwargs={'tool_calls': [{'id': 'call_YGg74jViWh6jr0L8cOyxe225', 'function': {'arguments': '{"query":"current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]} response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 271, 'total_tokens': 293}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-fd07dbe8-e079-4044-ac7b-c9c0aa185333-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}] usage_metadata={'input_tokens': 271, 'output_tokens': 22, 'total_tokens': 293}
INFO:__main__:Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}


{'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_YGg74jViWh6jr0L8cOyxe225', 'function': {'arguments': '{"query":"current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 271, 'total_tokens': 293}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-fd07dbe8-e079-4044-ac7b-c9c0aa185333-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}], usage_metadata={'input_tokens': 271, 'output_tokens': 22, 'total_tokens': 293})]}
take_action called in thread: ThreadPoolExecutor-1_1
take_action called with tool_calls: [{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}]
Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}


INFO:__main__:action tavily_search_results_json, result: [{'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': 1720593698, 'localtime': '2024-07-09 23:41'}, 'current': {'last_updated_epoch': 1720593000, 'last_updated': '2024-07-09 23:30', '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.4, 'windchill_f': 76.0, 'heatindex_c': 25.6, 'heatindex_f': 78.0, 'dewpoint_c': 14.4, 'dewpoint_f': 58.0, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 8.3, 'gust_kph': 13.3}}"}, {'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'}]
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in sf?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_DymVmpw1GN1w4gvOLU93NB1B', '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': 151, 'total_tokens': 173}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-a3434171-5959-4b14-ae38-2b41105ef13a-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}], usage_metadata={'input_tokens': 151, 'output_tokens': 22, 'total_tokens': 173}), ToolMessage(content="HTTPError('502 Server Error: Bad Gateway for url: https://api.tavily.com/search')", name='tavily_search_results_json', tool_call_id='call_DymVmpw1GN1w4gvOLU93NB1B'), AIMessage(content="It seems there was an issue retrieving the current weather information for San Francisco. You might want to check a reliable weather service like Weather.com, AccuWeather, or a similar platform for real-time updates. Alternatively, I can try searching again if you'd like.", response_metadata={'token_usage': {'completion_tokens': 53, 'prompt_tokens': 206, 'total_tokens': 259}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-480cf4e1-eae8-4d33-aeb7-0c662f441e69-0', usage_metadata={'input_tokens': 206, 'output_tokens': 53, 'total_tokens': 259}), HumanMessage(content='What about in la?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_YGg74jViWh6jr0L8cOyxe225', 'function': {'arguments': '{"query":"current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 271, 'total_tokens': 293}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-fd07dbe8-e079-4044-ac7b-c9c0aa185333-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}], usage_metadata={'input_tokens': 271, 'output_tokens': 22, 'total_tokens': 293}), ToolMessage(content='[{\'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\': 1720593698, \'localtime\': \'2024-07-09 23:41\'}, \'current\': {\'last_updated_epoch\': 1720593000, \'last_updated\': \'2024-07-09 23:30\', \'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.4, \'windchill_f\': 76.0, \'heatindex_c\': 25.6, \'heatindex_f\': 78.0, \'dewpoint_c\': 14.4, \'dewpoint_f\': 58.0, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 8.3, \'gust_kph\': 13.3}}"}, {\'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\'}]', name='tavily_search_results_json', tool_call_id='call_YGg74jViWh6jr0L8cOyxe225')]}


action tavily_search_results_json, result: [{'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': 1720593698, 'localtime': '2024-07-09 23:41'}, 'current': {'last_updated_epoch': 1720593000, 'last_updated': '2024-07-09 23:30', '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.4, 'windchill_f': 76.0, 'heatindex_c': 25.6, 'heatindex_f': 78.0, 'dewpoint_c': 14.4, 'dewpoint_f': 58.0, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 8.3, 'gust_kph': 13.3}}"}, {'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'}]
Back to the model!
{'messages': [ToolMessage(content='[{\'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\': 1720593698, \'localtime\': \'2024-07-09 23:41\'}, \'current\': {\'last_updated_epoch\': 1720593000, \'last_updated\': \'2024-07-09 23:30\', \'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.4, \'windchill_f\': 76.0, \'heatindex_c\': 25.6, \'heatindex_f\': 78.0, \'dewpoint_c\': 14.4, \'dewpoint_f\': 58.0, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 8.3, \'gust_kph\': 13.3}}"}, {\'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\'}]', name='tavily_search_results_json', tool_call_id='call_YGg74jViWh6jr0L8cOyxe225')]}


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 Los Angeles is as follows:\n\n- **Temperature:** 18.3°C (64.9°F)\n- **Condition:** Partly cloudy\n- **Wind:** 3.8 mph (6.1 kph) from the WNW\n- **Humidity:** 84%\n- **Pressure:** 1010.0 mb\n- **Visibility:** 16 km (9 miles)\n- **UV Index:** 1 (low)\n\nFor more detailed or updated information, you can visit weather websites like [WeatherAPI](https://www.weatherapi.com/) or [Weather Underground](https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10).' response_metadata={'token_usage': {'completion_tokens': 151, 'prompt_tokens': 788, 'total_tokens': 939}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None} id='run-f4cb2c85-20f0-4af7-9375-aa4a379ed77c-0' usage_metadata={'input_tokens': 788, 'output_tokens': 151, 'total_tokens': 939}
INFO:__main__:exists_action result: content='The current weather in Los Angeles is as follows:\n\n- **Temperature:** 18.3°C (64.9°F)\n- **Condition:** Partly cloudy\n- **Wind:** 3.8 mph (6.1 kph) from the WNW\n- **Humidity:** 84%\n- **Pressure:** 1010.0 mb\n- **Visibility:** 16 km (9 miles)\n- **UV Index:** 1 (low)\n\nFor more detailed or updated information, you can visit weather websites like [WeatherAPI](https://www.weatherapi.com/) or [Weather Underground](https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10).' response_metadata={'token_usage': {'completion_tokens': 151, 'prompt_tokens': 788, 'total_tokens': 939}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None} id='run-f4cb2c85-20f0-4af7-9375-aa4a379ed77c-0' usage_metadata={'input_tokens': 788, 'output_tokens': 151, 'total_tokens': 939}


{'messages': [AIMessage(content='The current weather in Los Angeles is as follows:\n\n- **Temperature:** 18.3°C (64.9°F)\n- **Condition:** Partly cloudy\n- **Wind:** 3.8 mph (6.1 kph) from the WNW\n- **Humidity:** 84%\n- **Pressure:** 1010.0 mb\n- **Visibility:** 16 km (9 miles)\n- **UV Index:** 1 (low)\n\nFor more detailed or updated information, you can visit weather websites like [WeatherAPI](https://www.weatherapi.com/) or [Weather Underground](https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10).', response_metadata={'token_usage': {'completion_tokens': 151, 'prompt_tokens': 788, 'total_tokens': 939}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-f4cb2c85-20f0-4af7-9375-aa4a379ed77c-0', usage_metadata={'input_tokens': 788, 'output_tokens': 151, 'total_tokens': 939})]}
messages = [HumanMessage(content="Which one is warmer?")]
thread = {"configurable": {"thread_id": "1"}}
for event in abot.graph.stream({"messages": messages}, thread):
    for v in event.values():
        print(v)
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in sf?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_DymVmpw1GN1w4gvOLU93NB1B', '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': 151, 'total_tokens': 173}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-a3434171-5959-4b14-ae38-2b41105ef13a-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}], usage_metadata={'input_tokens': 151, 'output_tokens': 22, 'total_tokens': 173}), ToolMessage(content="HTTPError('502 Server Error: Bad Gateway for url: https://api.tavily.com/search')", name='tavily_search_results_json', tool_call_id='call_DymVmpw1GN1w4gvOLU93NB1B'), AIMessage(content="It seems there was an issue retrieving the current weather information for San Francisco. You might want to check a reliable weather service like Weather.com, AccuWeather, or a similar platform for real-time updates. Alternatively, I can try searching again if you'd like.", response_metadata={'token_usage': {'completion_tokens': 53, 'prompt_tokens': 206, 'total_tokens': 259}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-480cf4e1-eae8-4d33-aeb7-0c662f441e69-0', usage_metadata={'input_tokens': 206, 'output_tokens': 53, 'total_tokens': 259}), HumanMessage(content='What about in la?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_YGg74jViWh6jr0L8cOyxe225', 'function': {'arguments': '{"query":"current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 271, 'total_tokens': 293}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-fd07dbe8-e079-4044-ac7b-c9c0aa185333-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}], usage_metadata={'input_tokens': 271, 'output_tokens': 22, 'total_tokens': 293}), ToolMessage(content='[{\'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\': 1720593698, \'localtime\': \'2024-07-09 23:41\'}, \'current\': {\'last_updated_epoch\': 1720593000, \'last_updated\': \'2024-07-09 23:30\', \'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.4, \'windchill_f\': 76.0, \'heatindex_c\': 25.6, \'heatindex_f\': 78.0, \'dewpoint_c\': 14.4, \'dewpoint_f\': 58.0, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 8.3, \'gust_kph\': 13.3}}"}, {\'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\'}]', name='tavily_search_results_json', tool_call_id='call_YGg74jViWh6jr0L8cOyxe225'), AIMessage(content='The current weather in Los Angeles is as follows:\n\n- **Temperature:** 18.3°C (64.9°F)\n- **Condition:** Partly cloudy\n- **Wind:** 3.8 mph (6.1 kph) from the WNW\n- **Humidity:** 84%\n- **Pressure:** 1010.0 mb\n- **Visibility:** 16 km (9 miles)\n- **UV Index:** 1 (low)\n\nFor more detailed or updated information, you can visit weather websites like [WeatherAPI](https://www.weatherapi.com/) or [Weather Underground](https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10).', response_metadata={'token_usage': {'completion_tokens': 151, 'prompt_tokens': 788, 'total_tokens': 939}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-f4cb2c85-20f0-4af7-9375-aa4a379ed77c-0', usage_metadata={'input_tokens': 788, 'output_tokens': 151, 'total_tokens': 939}), HumanMessage(content='Which one is warmer?')]}
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_QWrXRdAk2G9gJjU8wjQ85lVD', 'function': {'arguments': '{"query": "current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}, {'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8', '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': 951, 'total_tokens': 1011}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-792c6640-bcb9-48f7-8939-d87445d97469-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD'}, {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8'}] usage_metadata={'input_tokens': 951, 'output_tokens': 60, 'total_tokens': 1011}
INFO:__main__:exists_action result: content='' additional_kwargs={'tool_calls': [{'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD', 'function': {'arguments': '{"query": "current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}, {'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8', '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': 951, 'total_tokens': 1011}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'tool_calls', 'logprobs': None} id='run-792c6640-bcb9-48f7-8939-d87445d97469-0' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD'}, {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8'}] usage_metadata={'input_tokens': 951, 'output_tokens': 60, 'total_tokens': 1011}
INFO:__main__:Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD'}


{'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD', 'function': {'arguments': '{"query": "current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}, {'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8', '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': 951, 'total_tokens': 1011}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-792c6640-bcb9-48f7-8939-d87445d97469-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD'}, {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8'}], usage_metadata={'input_tokens': 951, 'output_tokens': 60, 'total_tokens': 1011})]}
take_action called in thread: ThreadPoolExecutor-2_1
take_action called with tool_calls: [{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD'}, {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8'}]
Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD'}


INFO:__main__:action tavily_search_results_json, result: [{'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': 1720593705, 'localtime': '2024-07-09 23:41'}, 'current': {'last_updated_epoch': 1720593000, 'last_updated': '2024-07-09 23:30', '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': 14.1, 'windchill_f': 57.5, 'heatindex_c': 14.8, 'heatindex_f': 58.6, 'dewpoint_c': 12.8, 'dewpoint_f': 55.0, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 11.7, 'gust_kph': 18.9}}"}, {'url': 'https://forecast.weather.gov/MapClick.php?textField1=37.76&textField2=-122.44', 'content': 'Current conditions at SAN FRANCISCO DOWNTOWN (SFOC1) Lat: 37.77056°NLon: 122.42694°WElev: 150.0ft. NA. 64°F. 18°C. ... 2024-6pm PDT Jul 10, 2024 . Forecast Discussion . Additional Resources. Radar & Satellite Image. ... National Weather Service; San Francisco Bay Area, CA; 21 Grace Hopper Ave, Stop 5; Monterey, CA 93943-5505; Comments ...'}]
INFO:__main__:Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8'}


action tavily_search_results_json, result: [{'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': 1720593705, 'localtime': '2024-07-09 23:41'}, 'current': {'last_updated_epoch': 1720593000, 'last_updated': '2024-07-09 23:30', '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': 14.1, 'windchill_f': 57.5, 'heatindex_c': 14.8, 'heatindex_f': 58.6, 'dewpoint_c': 12.8, 'dewpoint_f': 55.0, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 11.7, 'gust_kph': 18.9}}"}, {'url': 'https://forecast.weather.gov/MapClick.php?textField1=37.76&textField2=-122.44', 'content': 'Current conditions at SAN FRANCISCO DOWNTOWN (SFOC1) Lat: 37.77056°NLon: 122.42694°WElev: 150.0ft. NA. 64°F. 18°C. ... 2024-6pm PDT Jul 10, 2024 . Forecast Discussion . Additional Resources. Radar & Satellite Image. ... National Weather Service; San Francisco Bay Area, CA; 21 Grace Hopper Ave, Stop 5; Monterey, CA 93943-5505; Comments ...'}]
Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8'}


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://forecast.weather.gov/zipcity.php?inputstring=Los+Angeles,CA', 'content': 'Los Angeles CA 34.05°N 118.25°W (Elev. 377 ft) Last Update: 4:00 am PDT Jul 6, 2024. Forecast Valid: 4am PDT Jul 6, 2024-6pm PDT Jul 12, 2024 . Forecast Discussion . Additional Resources. Radar & Satellite Image. Hourly Weather Forecast. ... Severe Weather ; Current Outlook Maps ; Drought ; Fire Weather ; Fronts/Precipitation Maps ; Current ...'}]
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in sf?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_DymVmpw1GN1w4gvOLU93NB1B', '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': 151, 'total_tokens': 173}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-a3434171-5959-4b14-ae38-2b41105ef13a-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_DymVmpw1GN1w4gvOLU93NB1B'}], usage_metadata={'input_tokens': 151, 'output_tokens': 22, 'total_tokens': 173}), ToolMessage(content="HTTPError('502 Server Error: Bad Gateway for url: https://api.tavily.com/search')", name='tavily_search_results_json', tool_call_id='call_DymVmpw1GN1w4gvOLU93NB1B'), AIMessage(content="It seems there was an issue retrieving the current weather information for San Francisco. You might want to check a reliable weather service like Weather.com, AccuWeather, or a similar platform for real-time updates. Alternatively, I can try searching again if you'd like.", response_metadata={'token_usage': {'completion_tokens': 53, 'prompt_tokens': 206, 'total_tokens': 259}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-480cf4e1-eae8-4d33-aeb7-0c662f441e69-0', usage_metadata={'input_tokens': 206, 'output_tokens': 53, 'total_tokens': 259}), HumanMessage(content='What about in la?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_YGg74jViWh6jr0L8cOyxe225', 'function': {'arguments': '{"query":"current weather in Los Angeles"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}]}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 271, 'total_tokens': 293}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-fd07dbe8-e079-4044-ac7b-c9c0aa185333-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_YGg74jViWh6jr0L8cOyxe225'}], usage_metadata={'input_tokens': 271, 'output_tokens': 22, 'total_tokens': 293}), ToolMessage(content='[{\'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\': 1720593698, \'localtime\': \'2024-07-09 23:41\'}, \'current\': {\'last_updated_epoch\': 1720593000, \'last_updated\': \'2024-07-09 23:30\', \'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.4, \'windchill_f\': 76.0, \'heatindex_c\': 25.6, \'heatindex_f\': 78.0, \'dewpoint_c\': 14.4, \'dewpoint_f\': 58.0, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 8.3, \'gust_kph\': 13.3}}"}, {\'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\'}]', name='tavily_search_results_json', tool_call_id='call_YGg74jViWh6jr0L8cOyxe225'), AIMessage(content='The current weather in Los Angeles is as follows:\n\n- **Temperature:** 18.3°C (64.9°F)\n- **Condition:** Partly cloudy\n- **Wind:** 3.8 mph (6.1 kph) from the WNW\n- **Humidity:** 84%\n- **Pressure:** 1010.0 mb\n- **Visibility:** 16 km (9 miles)\n- **UV Index:** 1 (low)\n\nFor more detailed or updated information, you can visit weather websites like [WeatherAPI](https://www.weatherapi.com/) or [Weather Underground](https://www.wunderground.com/hourly/us/ca/los-angeles/90026/date/2024-07-10).', response_metadata={'token_usage': {'completion_tokens': 151, 'prompt_tokens': 788, 'total_tokens': 939}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-f4cb2c85-20f0-4af7-9375-aa4a379ed77c-0', usage_metadata={'input_tokens': 788, 'output_tokens': 151, 'total_tokens': 939}), HumanMessage(content='Which one is warmer?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD', 'function': {'arguments': '{"query": "current weather in San Francisco"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}, {'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8', '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': 951, 'total_tokens': 1011}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d33f7b429e', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-792c6640-bcb9-48f7-8939-d87445d97469-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_QWrXRdAk2G9gJjU8wjQ85lVD'}, {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in Los Angeles'}, 'id': 'call_ihCOlJ1Lv1SvjkYdp6FnFhF8'}], usage_metadata={'input_tokens': 951, 'output_tokens': 60, 'total_tokens': 1011}), 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\': 1720593705, \'localtime\': \'2024-07-09 23:41\'}, \'current\': {\'last_updated_epoch\': 1720593000, \'last_updated\': \'2024-07-09 23:30\', \'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\': 14.1, \'windchill_f\': 57.5, \'heatindex_c\': 14.8, \'heatindex_f\': 58.6, \'dewpoint_c\': 12.8, \'dewpoint_f\': 55.0, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 11.7, \'gust_kph\': 18.9}}"}, {\'url\': \'https://forecast.weather.gov/MapClick.php?textField1=37.76&textField2=-122.44\', \'content\': \'Current conditions at SAN FRANCISCO DOWNTOWN (SFOC1) Lat: 37.77056°NLon: 122.42694°WElev: 150.0ft. NA. 64°F. 18°C. ... 2024-6pm PDT Jul 10, 2024 . Forecast Discussion . Additional Resources. Radar & Satellite Image. ... National Weather Service; San Francisco Bay Area, CA; 21 Grace Hopper Ave, Stop 5; Monterey, CA 93943-5505; Comments ...\'}]', name='tavily_search_results_json', tool_call_id='call_QWrXRdAk2G9gJjU8wjQ85lVD'), 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://forecast.weather.gov/zipcity.php?inputstring=Los+Angeles,CA', 'content': 'Los Angeles CA 34.05°N 118.25°W (Elev. 377 ft) Last Update: 4:00 am PDT Jul 6, 2024. Forecast Valid: 4am PDT Jul 6, 2024-6pm PDT Jul 12, 2024 . Forecast Discussion . Additional Resources. Radar & Satellite Image. Hourly Weather Forecast. ... Severe Weather ; Current Outlook Maps ; Drought ; Fire Weather ; Fronts/Precipitation Maps ; Current ...'}]", name='tavily_search_results_json', tool_call_id='call_ihCOlJ1Lv1SvjkYdp6FnFhF8')]}


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://forecast.weather.gov/zipcity.php?inputstring=Los+Angeles,CA', 'content': 'Los Angeles CA 34.05°N 118.25°W (Elev. 377 ft) Last Update: 4:00 am PDT Jul 6, 2024. Forecast Valid: 4am PDT Jul 6, 2024-6pm PDT Jul 12, 2024 . Forecast Discussion . Additional Resources. Radar & Satellite Image. Hourly Weather Forecast. ... Severe Weather ; Current Outlook Maps ; Drought ; Fire Weather ; Fronts/Precipitation Maps ; Current ...'}]
Back to the model!
{'messages': [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\': 1720593705, \'localtime\': \'2024-07-09 23:41\'}, \'current\': {\'last_updated_epoch\': 1720593000, \'last_updated\': \'2024-07-09 23:30\', \'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\': 14.1, \'windchill_f\': 57.5, \'heatindex_c\': 14.8, \'heatindex_f\': 58.6, \'dewpoint_c\': 12.8, \'dewpoint_f\': 55.0, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 11.7, \'gust_kph\': 18.9}}"}, {\'url\': \'https://forecast.weather.gov/MapClick.php?textField1=37.76&textField2=-122.44\', \'content\': \'Current conditions at SAN FRANCISCO DOWNTOWN (SFOC1) Lat: 37.77056°NLon: 122.42694°WElev: 150.0ft. NA. 64°F. 18°C. ... 2024-6pm PDT Jul 10, 2024 . Forecast Discussion . Additional Resources. Radar & Satellite Image. ... National Weather Service; San Francisco Bay Area, CA; 21 Grace Hopper Ave, Stop 5; Monterey, CA 93943-5505; Comments ...\'}]', name='tavily_search_results_json', tool_call_id='call_QWrXRdAk2G9gJjU8wjQ85lVD'), 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://forecast.weather.gov/zipcity.php?inputstring=Los+Angeles,CA', 'content': 'Los Angeles CA 34.05°N 118.25°W (Elev. 377 ft) Last Update: 4:00 am PDT Jul 6, 2024. Forecast Valid: 4am PDT Jul 6, 2024-6pm PDT Jul 12, 2024 . Forecast Discussion . Additional Resources. Radar & Satellite Image. Hourly Weather Forecast. ... Severe Weather ; Current Outlook Maps ; Drought ; Fire Weather ; Fronts/Precipitation Maps ; Current ...'}]", name='tavily_search_results_json', tool_call_id='call_ihCOlJ1Lv1SvjkYdp6FnFhF8')]}


INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content='Based on the current weather information:\n\n- **San Francisco:** 16.1°C (61.0°F)\n- **Los Angeles:** 18.3°C (64.9°F)\n\nLos Angeles is currently warmer than San Francisco.' response_metadata={'token_usage': {'completion_tokens': 49, 'prompt_tokens': 1811, 'total_tokens': 1860}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None} id='run-f27878a2-44cc-4679-a650-239c2f257023-0' usage_metadata={'input_tokens': 1811, 'output_tokens': 49, 'total_tokens': 1860}
INFO:__main__:exists_action result: content='Based on the current weather information:\n\n- **San Francisco:** 16.1°C (61.0°F)\n- **Los Angeles:** 18.3°C (64.9°F)\n\nLos Angeles is currently warmer than San Francisco.' response_metadata={'token_usage': {'completion_tokens': 49, 'prompt_tokens': 1811, 'total_tokens': 1860}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None} id='run-f27878a2-44cc-4679-a650-239c2f257023-0' usage_metadata={'input_tokens': 1811, 'output_tokens': 49, 'total_tokens': 1860}


{'messages': [AIMessage(content='Based on the current weather information:\n\n- **San Francisco:** 16.1°C (61.0°F)\n- **Los Angeles:** 18.3°C (64.9°F)\n\nLos Angeles is currently warmer than San Francisco.', response_metadata={'token_usage': {'completion_tokens': 49, 'prompt_tokens': 1811, 'total_tokens': 1860}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90', 'finish_reason': 'stop', 'logprobs': None}, id='run-f27878a2-44cc-4679-a650-239c2f257023-0', usage_metadata={'input_tokens': 1811, 'output_tokens': 49, 'total_tokens': 1860})]}
# 改变线程id,没有持久性的检查点了
messages = [HumanMessage(content="Which one is warmer?")]
thread = {"configurable": {"thread_id": "2"}}
for event in abot.graph.stream({"messages": messages}, thread):
    for v in event.values():
        print(v)
INFO:__main__:state: {'messages': [HumanMessage(content='Which one is warmer?')]}
INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"
INFO:__main__:LLM message: content='Could you please clarify the two items or places you are comparing in terms of warmth? This will help me provide you with accurate information.' response_metadata={'token_usage': {'completion_tokens': 28, 'prompt_tokens': 149, 'total_tokens': 177}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_ce0793330f', 'finish_reason': 'stop', 'logprobs': None} id='run-95f88168-c060-46db-8430-83ea9a39c477-0' usage_metadata={'input_tokens': 149, 'output_tokens': 28, 'total_tokens': 177}
INFO:__main__:exists_action result: content='Could you please clarify the two items or places you are comparing in terms of warmth? This will help me provide you with accurate information.' response_metadata={'token_usage': {'completion_tokens': 28, 'prompt_tokens': 149, 'total_tokens': 177}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_ce0793330f', 'finish_reason': 'stop', 'logprobs': None} id='run-95f88168-c060-46db-8430-83ea9a39c477-0' usage_metadata={'input_tokens': 149, 'output_tokens': 28, 'total_tokens': 177}


{'messages': [AIMessage(content='Could you please clarify the two items or places you are comparing in terms of warmth? This will help me provide you with accurate information.', response_metadata={'token_usage': {'completion_tokens': 28, 'prompt_tokens': 149, 'total_tokens': 177}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_ce0793330f', 'finish_reason': 'stop', 'logprobs': None}, id='run-95f88168-c060-46db-8430-83ea9a39c477-0', usage_metadata={'input_tokens': 149, 'output_tokens': 28, 'total_tokens': 177})]}

流式处理token本身

from langgraph.checkpoint.aiosqlite import AsyncSqliteSaver

memory = AsyncSqliteSaver.from_conn_string(":memory:")
abot = Agent(model, [tool], system=prompt, checkpointer=memory)
INFO:__main__:model: bound=ChatOpenAI(client=<openai.resources.chat.completions.Completions object at 0x000002A44F2D6CC0>, async_client=<openai.resources.chat.completions.AsyncCompletions object at 0x000002A44AEE7920>, 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']}}}]}
messages = [HumanMessage(content="What is the weather in SF?")]
thread = {"configurable": {"thread_id": "4"}}
async for event in abot.graph.astream_events({"messages": messages}, thread, version="v1"):
    kind = event["event"]
    if kind == "on_chat_model_stream":
        content = event["data"]["chunk"].content
        if content:
            # Empty content in the context of OpenAI means
            # that the model is asking for a tool to be invoked.
            # So we only print non-empty content
            print(content, end="|")
D:\wuzhongyanqiu\envs\pytorch\Lib\site-packages\langchain_core\_api\beta_decorator.py:87: LangChainBetaWarning: This API is in beta and may change in the future.
  warn_beta(
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': [{'index': 0, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx', 'function': {'arguments': '{\n  "query": "current weather in San Francisco"\n}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]} response_metadata={'finish_reason': 'tool_calls', 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90'} id='run-6e01e885-9c34-416d-a9e8-2f36db6b3e30' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx'}]
INFO:__main__:exists_action result: content='' additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx', 'function': {'arguments': '{\n  "query": "current weather in San Francisco"\n}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]} response_metadata={'finish_reason': 'tool_calls', 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90'} id='run-6e01e885-9c34-416d-a9e8-2f36db6b3e30' tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx'}]
INFO:__main__:Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx'}


take_action called in thread: asyncio_1
take_action called with tool_calls: [{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx'}]
Calling: {'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx'}


INFO:__main__:action tavily_search_results_json, result: [{'url': 'https://www.wunderground.com/history/daily/us/ca/san-francisco/KCASANFR2043/date/2024-7-10', 'content': 'Current Weather for Popular Cities . San Francisco, CA 61 ° F Partly Cloudy; Manhattan, NY warning 84 ° F Fair; Schiller Park, IL (60176) warning 71 ° F Rain; Boston, MA warning 80 ° F Showers ...'}, {'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': 1720593705, 'localtime': '2024-07-09 23:41'}, 'current': {'last_updated_epoch': 1720593000, 'last_updated': '2024-07-09 23:30', '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': 14.1, 'windchill_f': 57.5, 'heatindex_c': 14.8, 'heatindex_f': 58.6, 'dewpoint_c': 12.8, 'dewpoint_f': 55.0, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 11.7, 'gust_kph': 18.9}}"}]
INFO:__main__:state: {'messages': [HumanMessage(content='What is the weather in SF?'), AIMessage(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx', 'function': {'arguments': '{\n  "query": "current weather in San Francisco"\n}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_calls', 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90'}, id='run-6e01e885-9c34-416d-a9e8-2f36db6b3e30', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'current weather in San Francisco'}, 'id': 'call_zeYLxGgOxQSZtujg7rNsJ6Gx'}]), ToolMessage(content='[{\'url\': \'https://www.wunderground.com/history/daily/us/ca/san-francisco/KCASANFR2043/date/2024-7-10\', \'content\': \'Current Weather for Popular Cities . San Francisco, CA 61 ° F Partly Cloudy; Manhattan, NY warning 84 ° F Fair; Schiller Park, IL (60176) warning 71 ° F Rain; Boston, MA warning 80 ° F Showers ...\'}, {\'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\': 1720593705, \'localtime\': \'2024-07-09 23:41\'}, \'current\': {\'last_updated_epoch\': 1720593000, \'last_updated\': \'2024-07-09 23:30\', \'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\': 14.1, \'windchill_f\': 57.5, \'heatindex_c\': 14.8, \'heatindex_f\': 58.6, \'dewpoint_c\': 12.8, \'dewpoint_f\': 55.0, \'vis_km\': 16.0, \'vis_miles\': 9.0, \'uv\': 1.0, \'gust_mph\': 11.7, \'gust_kph\': 18.9}}"}]', name='tavily_search_results_json', tool_call_id='call_zeYLxGgOxQSZtujg7rNsJ6Gx')]}


action tavily_search_results_json, result: [{'url': 'https://www.wunderground.com/history/daily/us/ca/san-francisco/KCASANFR2043/date/2024-7-10', 'content': 'Current Weather for Popular Cities . San Francisco, CA 61 ° F Partly Cloudy; Manhattan, NY warning 84 ° F Fair; Schiller Park, IL (60176) warning 71 ° F Rain; Boston, MA warning 80 ° F Showers ...'}, {'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': 1720593705, 'localtime': '2024-07-09 23:41'}, 'current': {'last_updated_epoch': 1720593000, 'last_updated': '2024-07-09 23:30', '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': 14.1, 'windchill_f': 57.5, 'heatindex_c': 14.8, 'heatindex_f': 58.6, 'dewpoint_c': 12.8, 'dewpoint_f': 55.0, 'vis_km': 16.0, 'vis_miles': 9.0, 'uv': 1.0, 'gust_mph': 11.7, 'gust_kph': 18.9}}"}]
Back to the model!


INFO:httpx:HTTP Request: POST https://api.chatanywhere.tech/v1/chat/completions "HTTP/1.1 200 OK"


The| current| weather| in| San| Francisco|,| CA| is| |61|°F| (|16|.|1|°C|)| and| partly| cloudy|.| The| wind| is| blowing| from| the| west|-n|orth|west| at| |9|.|4| mph| (|15|.|1| k|ph|),| and| the| humidity| is| at| |90|%.| The| visibility| is| |16| km| (|9| miles|),| and| the|

INFO:__main__:LLM message: content='The current weather in San Francisco, CA is 61°F (16.1°C) and partly cloudy. The wind is blowing from the west-northwest at 9.4 mph (15.1 kph), and the humidity is at 90%. The visibility is 16 km (9 miles), and the UV index is 1.' response_metadata={'finish_reason': 'stop', 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90'} id='run-96dbd0cb-1f75-46c8-97df-2f64d201c26f'
INFO:__main__:exists_action result: content='The current weather in San Francisco, CA is 61°F (16.1°C) and partly cloudy. The wind is blowing from the west-northwest at 9.4 mph (15.1 kph), and the humidity is at 90%. The visibility is 16 km (9 miles), and the UV index is 1.' response_metadata={'finish_reason': 'stop', 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_d576307f90'} id='run-96dbd0cb-1f75-46c8-97df-2f64d201c26f'


 UV| index| is| |1|.|

相关推荐

  1. STM32<span style='color:red;'>L</span><span style='color:red;'>4</span>

    STM32L4

    2024-07-11 11:54:05      52 阅读
  2. V4L2驱动

    2024-07-11 11:54:05       25 阅读
  3. L4 Persistence and Streaming

    2024-07-11 11:54:05       18 阅读
  4. dctcp 和 l4s tcp prague

    2024-07-11 11:54:05       58 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 11:54:05       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 11:54:05       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 11:54:05       57 阅读
  4. Python语言-面向对象

    2024-07-11 11:54:05       68 阅读

热门阅读

  1. DDOS 攻击原理

    2024-07-11 11:54:05       19 阅读
  2. .net 8 使用 quic 协议通讯

    2024-07-11 11:54:05       22 阅读
  3. jvm 06 补充 OOM 和具体工具使用

    2024-07-11 11:54:05       24 阅读
  4. Chameleon:动态UI框架使用详解

    2024-07-11 11:54:05       24 阅读
  5. C# 8.0 新语法的学习和使用

    2024-07-11 11:54:05       23 阅读
  6. 字符串匹配

    2024-07-11 11:54:05       23 阅读
  7. 升序到降序的类型变化

    2024-07-11 11:54:05       21 阅读
  8. 编程入门题:画矩形(C语言版)

    2024-07-11 11:54:05       21 阅读
  9. k8s 部署RuoYi-Vue-Plus之nginx部署

    2024-07-11 11:54:05       23 阅读
  10. js 日期比较大小

    2024-07-11 11:54:05       18 阅读
  11. 定个小目标之刷LeetCode热题(43)

    2024-07-11 11:54:05       19 阅读
  12. SLAM中的块矩阵与schur补

    2024-07-11 11:54:05       23 阅读