Research agents combine web search, Wikipedia, and academic APIs to autonomously investigate topics.
Autonomous Research Agents
from langchain_community.tools import DuckDuckGoSearchRun, WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
from langchain_core.tools import tool
search = DuckDuckGoSearchRun()
wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())
@tool
def scholarly_search(query: str) -> str:
"""Search for academic papers via Semantic Scholar API."""
import httpx
resp = httpx.get(f"https://api.semanticscholar.org/graph/v1/paper/search",
params={"query":query,"limit":5,"fields":"title,abstract,year"})
papers = resp.json().get("data",[])
return "
".join(f"[{p.get('year')}] {p.get('title')}: {p.get('abstract','')[:200]}" for p in papers)
@tool
def summarise_url(url: str) -> str:
"""Fetch and summarise a web page."""
import httpx
resp = httpx.get(url, timeout=10, follow_redirects=True)
content = resp.text[:8000]
return llm.invoke(f"Summarise this page in 200 words: {content}").content
research_tools = [search, wikipedia, scholarly_search, summarise_url]
research_agent = create_tool_calling_agent(llm, research_tools, research_prompt)
executor = AgentExecutor(agent=research_agent, tools=research_tools, max_iterations=15)