Tutorial

How to Build a LangChain Search Tool with Scavio

Learn how to create a custom LangChain tool that searches Google, Reddit, and YouTube via Scavio's API for use in agents and chains.

LangChain agents need search tools to access current information. This tutorial creates a custom LangChain tool using Scavio's API that supports multiple platforms (Google, Reddit, YouTube, Amazon, Walmart) through a single tool definition. The agent selects the platform based on query context, and the tool returns structured results ready for the LLM's context.

Prerequisites

  • Python 3.8+ installed
  • langchain and langchain-core packages installed
  • A Scavio API key from scavio.dev

Walkthrough

Step 1: Install LangChain dependencies

Add the required packages for building custom tools.

Bash
pip install langchain langchain-core requests

Step 2: Create the search tool

Define a LangChain tool that calls Scavio's API with platform routing.

Python
from langchain.tools import tool
import requests, os

@tool
def web_search(query: str, platform: str = 'google') -> str:
    """Search the web for current information. Use platform='google' for general queries,
    'reddit' for community discussions, 'youtube' for video content,
    'amazon' for products, 'walmart' for retail prices."""
    resp = requests.post('https://api.scavio.dev/api/v1/search',
        headers={'x-api-key': os.environ['SCAVIO_API_KEY']},
        json={'platform': platform, 'query': query}, timeout=10)
    results = resp.json().get('organic', [])[:5]
    return '\n'.join(f'[{i+1}] {r["title"]}: {r.get("snippet", "")} ({r.get("link", "")})'
                      for i, r in enumerate(results))

Step 3: Create an agent with the search tool

Build a LangChain agent that uses the search tool for answering questions.

Python
from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate

llm = ChatOpenAI(model='gpt-4o')
tools = [web_search]
prompt = ChatPromptTemplate.from_messages([
    ('system', 'You are a helpful research assistant. Use the web_search tool to find current information.'),
    ('human', '{input}'),
    ('placeholder', '{agent_scratchpad}'),
])
agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

Step 4: Test the agent

Run queries that should trigger different platform searches.

Python
# General web search (google)
result = executor.invoke({'input': 'What are the top CRM tools in 2026?'})
print(result['output'])

# Reddit discussions
result = executor.invoke({'input': 'What do people on Reddit think about Notion?'})
print(result['output'])

# Product search
result = executor.invoke({'input': 'Find the best-rated wireless earbuds on Amazon under $100'})
print(result['output'])

Python Example

Python
from langchain.tools import tool
import requests, os

@tool
def web_search(query: str, platform: str = 'google') -> str:
    """Search the web. Platforms: google, reddit, youtube, amazon, walmart."""
    resp = requests.post('https://api.scavio.dev/api/v1/search',
        headers={'x-api-key': os.environ['SCAVIO_API_KEY']},
        json={'platform': platform, 'query': query}, timeout=10)
    return '\n'.join(f'{r["title"]}: {r.get("snippet","")}' for r in resp.json().get('organic', [])[:5])

JavaScript Example

JavaScript
import { tool } from '@langchain/core/tools';
import { z } from 'zod';

const webSearch = tool(async ({ query, platform }) => {
  const resp = await fetch('https://api.scavio.dev/api/v1/search', {
    method: 'POST', headers: {'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'},
    body: JSON.stringify({platform: platform || 'google', query})
  });
  return (await resp.json()).organic?.slice(0, 5).map(r => `${r.title}: ${r.snippet}`).join('\n') || 'No results';
}, {
  name: 'web_search',
  description: 'Search the web. Platforms: google, reddit, youtube, amazon, walmart.',
  schema: z.object({ query: z.string(), platform: z.string().optional() })
});

Expected Output

JSON
A LangChain search tool with multi-platform support and an agent that routes queries to the right platform.

Related Tutorials

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.8+ installed. langchain and langchain-core packages installed. A Scavio API key from scavio.dev. A Scavio API key gives you 500 free credits per month.

Yes. The free tier includes 500 credits per month, 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 LangChain, but you can adapt to your framework of choice.

Start Building

Learn how to create a custom LangChain tool that searches Google, Reddit, and YouTube via Scavio's API for use in agents and chains.