Tavily Search Error with async/await in LangGraph #469

Closed
opened 2026-02-20 17:40:17 -05:00 by yindo · 3 comments
Owner

Originally created by @kissycn on GitHub (Feb 22, 2025).

Checked other resources

  • This is a bug, not a usage question. For questions, please use GitHub Discussions.
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

import os
import asyncio
from typing import Annotated
from typing_extensions import TypedDict
from langchain_anthropic import ChatAnthropic
from langchain_core.messages import HumanMessage, SystemMessage, AnyMessage
from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages
from langgraph.prebuilt import ToolNode, tools_condition
from langchain_community.tools import SearchAPIResults
from langchain_community.tools import TavilySearchResults
from langchain_openai import ChatOpenAI

os.environ['TAVILY_API_KEY'] = 'tvly-xxx'


class State(TypedDict):
    messages: Annotated[list, add_messages]

llm = ChatOpenAI(model="gpt-4o-mini")
tool = TavilySearchResults(max_results=1, include_answer=False, include_raw_content=False)
#tool = SearchAPIResults(engine="google")
tools = [tool]

# 系统提示词
system_prompt = """You are a helpful assistant."""
#system_prompt = "你是小明。如果有用户问你是谁就回答:小明"
llm_with_tools = llm.bind_tools(tools)

async def chatbot(state: State):
    response = await llm_with_tools.ainvoke(state["messages"])
    return {"messages": [response]}

graph_builder = StateGraph(State)
graph_builder.add_node("chatbot", chatbot)
tool_node = ToolNode(tools=[tool])
graph_builder.add_node("tools", tool_node)
graph_builder.add_conditional_edges(
    "chatbot",
    tools_condition,
)
graph_builder.add_edge("tools", "chatbot")
graph_builder.add_edge(START, "chatbot")

searchbot_graph = graph_builder.compile()

user_input = "what is langgraph"

# 创建初始消息列表,包含系统提示和用户输入
initial_messages = [
    SystemMessage(content=system_prompt),
    HumanMessage(content=user_input)
]

async def main():
    # 使用包含系统提示的消息列表
    async for chunk in searchbot_graph.astream(
        input={"messages": initial_messages},
        stream_mode="messages"
    ):
        print(chunk)
        print("\n\n")

if __name__ == "__main__":
    asyncio.run(main())

Error Message and Stack Trace (if applicable)

(ToolMessage(content="ClientConnectorCertificateError(ConnectionKey(host='api.tavily.com', port=443, is_ssl=True, ssl=True, proxy=None, proxy_auth=None, proxy_headers_hash=None), SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)'))", name='tavily_search_results_json', id='e76f58ec-4299-4adb-9488-c6e03804fe59', tool_call_id='call_Mqle439YOLwiLT3i9TzwQhy8', artifact={}), {'langgraph_step': 2, 'langgraph_node': 'tools', 'langgraph_triggers': ['branch:chatbot:tools_condition:tools'], 'langgraph_path': ('__pregel_pull', 'tools'), 'langgraph_checkpoint_ns': 'tools:2743d809-8b93-3c97-bdb2-11d04607977d'})

Description

When using LangGraph with async/await pattern and Tavily Search tool, the code fails with an SSL certificate verification error. However, the same code works fine when not using async implementation.

System Info

Langgraph Version:0.2.69
langchain-community:0.3.17

Originally created by @kissycn on GitHub (Feb 22, 2025). ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use GitHub Discussions. - [x] I added a clear and detailed title that summarizes the issue. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue. ### Example Code ```python import os import asyncio from typing import Annotated from typing_extensions import TypedDict from langchain_anthropic import ChatAnthropic from langchain_core.messages import HumanMessage, SystemMessage, AnyMessage from langgraph.graph import StateGraph, START, END from langgraph.graph.message import add_messages from langgraph.prebuilt import ToolNode, tools_condition from langchain_community.tools import SearchAPIResults from langchain_community.tools import TavilySearchResults from langchain_openai import ChatOpenAI os.environ['TAVILY_API_KEY'] = 'tvly-xxx' class State(TypedDict): messages: Annotated[list, add_messages] llm = ChatOpenAI(model="gpt-4o-mini") tool = TavilySearchResults(max_results=1, include_answer=False, include_raw_content=False) #tool = SearchAPIResults(engine="google") tools = [tool] # 系统提示词 system_prompt = """You are a helpful assistant.""" #system_prompt = "你是小明。如果有用户问你是谁就回答:小明" llm_with_tools = llm.bind_tools(tools) async def chatbot(state: State): response = await llm_with_tools.ainvoke(state["messages"]) return {"messages": [response]} graph_builder = StateGraph(State) graph_builder.add_node("chatbot", chatbot) tool_node = ToolNode(tools=[tool]) graph_builder.add_node("tools", tool_node) graph_builder.add_conditional_edges( "chatbot", tools_condition, ) graph_builder.add_edge("tools", "chatbot") graph_builder.add_edge(START, "chatbot") searchbot_graph = graph_builder.compile() user_input = "what is langgraph" # 创建初始消息列表,包含系统提示和用户输入 initial_messages = [ SystemMessage(content=system_prompt), HumanMessage(content=user_input) ] async def main(): # 使用包含系统提示的消息列表 async for chunk in searchbot_graph.astream( input={"messages": initial_messages}, stream_mode="messages" ): print(chunk) print("\n\n") if __name__ == "__main__": asyncio.run(main()) ``` ### Error Message and Stack Trace (if applicable) ```shell (ToolMessage(content="ClientConnectorCertificateError(ConnectionKey(host='api.tavily.com', port=443, is_ssl=True, ssl=True, proxy=None, proxy_auth=None, proxy_headers_hash=None), SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)'))", name='tavily_search_results_json', id='e76f58ec-4299-4adb-9488-c6e03804fe59', tool_call_id='call_Mqle439YOLwiLT3i9TzwQhy8', artifact={}), {'langgraph_step': 2, 'langgraph_node': 'tools', 'langgraph_triggers': ['branch:chatbot:tools_condition:tools'], 'langgraph_path': ('__pregel_pull', 'tools'), 'langgraph_checkpoint_ns': 'tools:2743d809-8b93-3c97-bdb2-11d04607977d'}) ``` ### Description When using LangGraph with async/await pattern and Tavily Search tool, the code fails with an SSL certificate verification error. However, the same code works fine when not using async implementation. ### System Info Langgraph Version:0.2.69 langchain-community:0.3.17
yindo closed this issue 2026-02-20 17:40:17 -05:00
Author
Owner

@kissycn commented on GitHub (Feb 23, 2025):

This should be my local environment problem. Sorry to bother.

@kissycn commented on GitHub (Feb 23, 2025): This should be my local environment problem. Sorry to bother.
Author
Owner

@gsagrawal-binocs commented on GitHub (Aug 11, 2025):

This should be my local environment problem. Sorry to bother.

i am also facing the same error. how did you fix it ?

@gsagrawal-binocs commented on GitHub (Aug 11, 2025): > This should be my local environment problem. Sorry to bother. i am also facing the same error. how did you fix it ?
Author
Owner

@dark2momo commented on GitHub (Dec 2, 2025):

Also facing the same error. Using plan-and-execute.ipynb in the demo folder can reproduce the problem.

@dark2momo commented on GitHub (Dec 2, 2025): Also facing the same error. Using plan-and-execute.ipynb in the demo folder can reproduce the problem.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#469