LangChain

Add a SerpApi structured tool to a LangChain agent.

Call a search constructor and pass the resulting StructuredTool to create_agent.

Install

pip install "serpapi-search-tools[langchain]" langchain-openai

If LangChain is already installed in your project, use pip install serpapi-search-tools instead.

The SerpApi extra installs the LangChain tool interface, while langchain-openai is the model backend selected by this example. Replace that second package when your application uses another LangChain model provider.

export SERPAPI_API_KEY="your-serpapi-key"
export OPENAI_API_KEY="your-openai-key"

Run it

from langchain.agents import create_agent
from langchain_openai import ChatOpenAI
from serpapi_search_tools import maps_search, news_search, web_search

agent = create_agent(
    model=ChatOpenAI(model="gpt-5.4-mini", temperature=0),
    tools=[
        web_search(),
        news_search(),
    ],
)

result = agent.invoke(
    {"messages": [{"role": "user", "content": "Find today's Python release news."}]}
)
print(result)

Try it

Ask: “Find today’s Python release news and give me three changes worth knowing.”