# LangChain

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


# Install

``` bash
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.

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


# Run it

``` python
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."


# Customize the search

``` python
local_search = maps_search(
    default_params={"hl": "en", "gl": "us"},
    include_examples=False,
)
```

Use this version for local recommendations such as coffee shops or repair services.
