ScavioScavio
ProductPricingDocs
Sign InGet Started
  1. Home
  2. Tutorials
  3. How to Build a LangGraph Research Agent with Search
Tutorial

How to Build a LangGraph Research Agent with Search

Build a LangGraph agent with live web search grounding. Add a search tool node that returns structured SERP data for multi-step research tasks.

Get Free API KeyAPI Docs

LangGraph agents excel at multi-step reasoning but hallucinate when they lack access to current information. Adding a web search tool node gives the agent live data grounding so it can verify facts, find sources, and build research outputs from real search results. The Scavio API integrates as a tool node that returns structured JSON including organic results, AI Overviews, and People Also Ask data. This tutorial shows how to define a search tool, wire it into a LangGraph graph, and build a research agent that queries multiple keywords and synthesizes findings.

Prerequisites

  • Python 3.10+ installed
  • langgraph and langchain-core installed
  • A Scavio API key from scavio.dev
  • Basic familiarity with LangGraph graph definitions

Walkthrough

Step 1: Define the search tool

Create a tool function that calls the Scavio API and returns structured results for the agent.

Python
import os, requests
from langchain_core.tools import tool

API_KEY = os.environ["SCAVIO_API_KEY"]

@tool
def web_search(query: str) -> str:
    """Search the web and return top results."""
    resp = requests.post("https://api.scavio.dev/api/v1/search",
        headers={"x-api-key": API_KEY},
        json={"platform": "google", "query": query})
    results = resp.json().get("organic_results", [])[:5]
    return "\n".join(f"{r['title']}: {r.get('snippet','')}" for r in results)

Step 2: Build the graph

Create a LangGraph StateGraph with an agent node and a tool node for search.

Python
from langgraph.graph import StateGraph, MessagesState
from langgraph.prebuilt import ToolNode

tools = [web_search]
tool_node = ToolNode(tools)

def agent(state: MessagesState):
    # Your LLM call here with tools bound
    # Returns messages with potential tool calls
    pass

graph = StateGraph(MessagesState)
graph.add_node("agent", agent)
graph.add_node("tools", tool_node)
graph.add_edge("agent", "tools")
graph.add_edge("tools", "agent")
graph.set_entry_point("agent")

Step 3: Add research logic

Configure the agent to run multiple searches and synthesize findings.

Python
def research(topic, num_queries=3):
    app = graph.compile()
    initial = {"messages": [{
        "role": "user",
        "content": f"Research '{topic}'. Search {num_queries} related queries, then summarize findings with sources."
    }]}
    result = app.invoke(initial)
    return result["messages"][-1].content

findings = research("best vector databases 2026")
print(findings)

Step 4: Test the search tool independently

Verify the search tool returns good data before running the full graph.

Python
result = web_search.invoke("best vector databases 2026")
print(result[:500])

Python Example

Python
import os, requests
API_KEY = os.environ["SCAVIO_API_KEY"]
def search(query):
    resp = requests.post("https://api.scavio.dev/api/v1/search",
        headers={"x-api-key": API_KEY},
        json={"platform": "google", "query": query})
    return resp.json().get("organic_results", [])[:5]

for r in search("best vector databases 2026"):
    print(f"{r['title']}: {r.get('snippet','')[:80]}")

JavaScript Example

JavaScript
const H = {"x-api-key": process.env.SCAVIO_API_KEY, "Content-Type": "application/json"};
async function search(query) {
  const r = await fetch("https://api.scavio.dev/api/v1/search", {
    method: "POST", headers: H,
    body: JSON.stringify({platform: "google", query})
  });
  return (await r.json()).organic_results || [];
}
search("best vector databases 2026").then(rs =>
  rs.slice(0,5).forEach(r => console.log(r.title))
);

Expected Output

JSON
A LangGraph agent with a search tool node that queries live SERP data, runs multi-step research, and synthesizes findings with source citations.

Related Tutorials

  • How to Add Search to a LangGraph Agent
  • How to Add Real-Time Search to LangChain with langchain-scavio

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

Python 3.10+ installed. langgraph and langchain-core installed. A Scavio API key from scavio.dev. Basic familiarity with LangGraph graph definitions. A Scavio API key gives you 50 free credits on signup.

Yes. The free tier includes 50 credits on signup, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Related Resources

Best Of

Best Search API for LangGraph Agents in 2026

Read more
Best Of

Best AI Agent Web Search Tools in 2026

Read more
Use Case

Pi Coding Agent Web Search Integration

Read more
Solution

Coding Agent Search Tool Debugging

Read more
Use Case

LangGraph Research Agent Search Grounding

Read more
Solution

Add Unified Search to Multi-Agent Systems with Scavio

Read more

Start Building

Build a LangGraph agent with live web search grounding. Add a search tool node that returns structured SERP data for multi-step research tasks.

Get Free API KeyRead the Docs
ScavioScavio

Real-time search API for AI agents. Search every platform, not just Google.

Product

  • Features
  • Pricing
  • Dashboard
  • Affiliates

Developers

  • Documentation
  • API Reference
  • Quickstart
  • MCP Integration
  • Python SDK

Alternatives

  • Tavily Alternative
  • SerpAPI Alternative
  • Firecrawl Alternative
  • Exa Alternative

Tools

  • JSON Formatter
  • cURL to Code
  • Token Counter
  • All Tools

© 2026 Scavio. All rights reserved.

Featured on TAAFT
Terms of ServicePrivacy Policy