Pydantic AI
Add live SerpApi search to a Pydantic AI agent.
Pydantic AI accepts the returned search function directly in its tools list.
Install
pip install "serpapi-search-tools[pydantic-ai]"If Pydantic AI is already installed in your project, use pip install serpapi-search-tools instead.
export SERPAPI_API_KEY="your-serpapi-key"
export OPENAI_API_KEY="your-openai-key"Run it
from pydantic_ai import Agent
from serpapi_search_tools import images_search, web_search
agent = Agent(
"openai:gpt-5.4-mini",
instructions="Use live search when current information helps.",
tools=[
web_search(),
images_search(),
],
)
result = agent.run_sync("Find current visual trends in minimal desk setups.")
print(result.output)Try it
Ask: “Search Google Images for minimal desk setups and summarize three visual themes.”
Customize the search
image_search = images_search(
default_params={"num": 5, "hl": "en", "gl": "us"},
include_examples=False,
)Use images_search when you want the agent to look specifically for images rather than general web pages.