LangGraph

Add SerpApi search to a LangGraph ReAct agent.

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-openai

If 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.”