Skip to content
Pydantic AI

Research Agent with Pydantic AI

Build an autonomous research agent that searches the web, synthesizes findings, and produces structured reports — powered by Pydantic AI.

researchweb searchreportsautomation

Working Code

Pydantic AI
from pydantic_ai import Agent, RunContext
agent = Agent(
"openai:gpt-4o",
system_prompt="You are a research assistant. Search the web to gather information, then synthesize findings into a structured report with citations.",
)
@agent.tool
async def web_search(ctx: RunContext, query: str, max_results: int = 3) -> str:
"""Search the web for current information."""
from tavily import TavilyClient
client = TavilyClient()
results = client.search(query, max_results=max_results)
return "\n\n".join(
f"**{r['title']}**\n{r['content']}" for r in results["results"]
)
result = await agent.run("Compare the latest developments in AI agent frameworks in 2025")
print(result.output)

Step by Step

1

Install dependencies

Install Pydantic AI and the required tools for this use case.

2

Define your tools

Create the domain-specific tool functions your agent will use to interact with external services.

3

Create the agent and run

Initialize the Pydantic AI agent with your tools, set the system prompt, and execute a query.

Ready to build with Pydantic AI?

Generate a production-ready project with Pydantic AI pre-configured — FastAPI + Next.js, auth, streaming, and more.

Get Started

Ready to build your first production AI agent?

Open-source tools, battle-tested patterns, zero boilerplate. Configure your stack and ship in minutes — not months.