LangGraph
LangGraph’s ToolNode accepts the tools returned by these search constructors. If you restrict the available web or shopping engines, the agent is offered only those choices.
Install
pip install "serpapi-search-tools[langgraph]" langchain-openaiIf LangGraph is already installed in your project, use pip install serpapi-search-tools instead.
The SerpApi extra installs the LangGraph and LangChain tool interfaces, while langchain-openai is the model backend selected by this example. Replace it when your graph uses another model provider.
export SERPAPI_API_KEY="your-serpapi-key"
export OPENAI_API_KEY="your-openai-key"Run it
from langchain_openai import ChatOpenAI
from langgraph.graph import MessagesState, START, StateGraph
from langgraph.prebuilt import ToolNode, tools_condition
from serpapi_search_tools import web_search
search_tool = web_search()
model = ChatOpenAI(model="gpt-5.4-mini", temperature=0).bind_tools([search_tool])
def call_model(state: MessagesState):
return {"messages": [model.invoke(state["messages"])]}
builder = StateGraph(MessagesState)
builder.add_node("model", call_model)
builder.add_node("tools", ToolNode([search_tool]))
builder.add_edge(START, "model")
builder.add_conditional_edges("model", tools_condition)
builder.add_edge("tools", "model")
agent = builder.compile()
result = agent.invoke(
{"messages": [{"role": "user", "content": "Find recent Python packaging guidance."}]}
)
print(result)Try it
Ask: “Find recent Python packaging guidance and turn it into a five-item checklist.”
Customize the search
multi_source_search = web_search(
allowed_engines=["google", "bing", "duckduckgo"],
default_engine="google",
default_params={"num": 5, "hl": "en"},
)The langgraph extra installs LangGraph 1.x and the LangChain tool interface used above. The OpenAI integration remains an application choice. Install the SDK extra separately from the Google ADK extra; their supported transitive dependency branches are incompatible.