ScavioScavio
FeaturesPricingDocs
Sign InGet Started
  1. Home
  2. Tutorials
  3. How to Build a RAG Agent with LangChain and Scavio
Tutorial

How to Build a RAG Agent with LangChain and Scavio

Connect LangChain to real-time web search using Scavio and langchain-scavio. Build a RAG agent that retrieves live data before answering questions.

Get Free API KeyAPI Docs

Retrieval-Augmented Generation (RAG) agents improve answer quality by grounding LLM responses in retrieved documents. Most RAG pipelines use static vector stores that go stale. By plugging Scavio into a LangChain agent as a retrieval tool, the agent can fetch live Google search results, YouTube transcripts, or Amazon product data on demand. This tutorial installs langchain-scavio, wires it into a LangChain ReAct agent, and runs a question that requires live retrieval to answer accurately.

Prerequisites

  • Python 3.10 or higher
  • pip install langchain langchain-scavio langchain-openai
  • A Scavio API key
  • An OpenAI API key (or substitute any LangChain-compatible LLM)

Walkthrough

Step 1: Install dependencies

Install LangChain, the Scavio integration package, and an LLM provider. The langchain-scavio package exposes ScavioSearch as a LangChain Tool.

Bash
pip install langchain langchain-scavio langchain-openai

Step 2: Import and configure ScavioSearch

ScavioSearch wraps the Scavio API as a LangChain BaseTool. Pass your API key and optionally restrict to a specific platform.

Python
from langchain_scavio import ScavioSearch

search_tool = ScavioSearch(
    api_key="your_scavio_api_key",
    platform="google",
    country_code="us",
    max_results=5
)

Step 3: Create the ReAct agent

Bind the search tool to a LangChain agent with an OpenAI LLM. The agent will decide when to call the search tool.

Python
from langchain.agents import create_react_agent, AgentExecutor
from langchain_openai import ChatOpenAI
from langchain import hub

llm = ChatOpenAI(model="gpt-4o", temperature=0)
prompt = hub.pull("hwchase17/react")
agent = create_react_agent(llm, [search_tool], prompt)
executor = AgentExecutor(agent=agent, tools=[search_tool], verbose=True)

Step 4: Run the agent

Invoke the agent with a question that requires live information. It will call Scavio, retrieve results, and synthesize an answer.

Python
result = executor.invoke({"input": "What are the latest Python web frameworks released in 2026?"})
print(result["output"])

Python Example

Python
import os
from langchain_scavio import ScavioSearch
from langchain.agents import create_react_agent, AgentExecutor
from langchain_openai import ChatOpenAI
from langchain import hub

os.environ["OPENAI_API_KEY"] = "your_openai_key"
os.environ["SCAVIO_API_KEY"] = "your_scavio_api_key"

search_tool = ScavioSearch(
    api_key=os.environ["SCAVIO_API_KEY"],
    platform="google",
    country_code="us",
    max_results=5
)

llm = ChatOpenAI(model="gpt-4o", temperature=0)
prompt = hub.pull("hwchase17/react")
agent = create_react_agent(llm, [search_tool], prompt)
executor = AgentExecutor(agent=agent, tools=[search_tool], verbose=True)

if __name__ == "__main__":
    result = executor.invoke({"input": "What are the latest AI frameworks released in 2026?"})
    print(result["output"])

JavaScript Example

JavaScript
// LangChain.js integration with Scavio via HTTP tool
const { ChatOpenAI } = require("@langchain/openai");
const { DynamicTool } = require("@langchain/core/tools");
const { AgentExecutor, createReactAgent } = require("langchain/agents");
const { pull } = require("langchain/hub");

const API_KEY = process.env.SCAVIO_API_KEY;

const searchTool = new DynamicTool({
  name: "scavio_search",
  description: "Search the web for current information",
  func: async (query) => {
    const res = await fetch("https://api.scavio.dev/api/v1/search", {
      method: "POST",
      headers: { "x-api-key": API_KEY, "Content-Type": "application/json" },
      body: JSON.stringify({ query, country_code: "us" })
    });
    const data = await res.json();
    return JSON.stringify(data.organic_results?.slice(0, 3) || []);
  }
});

async function main() {
  const llm = new ChatOpenAI({ model: "gpt-4o" });
  const prompt = await pull("hwchase17/react");
  const agent = await createReactAgent({ llm, tools: [searchTool], prompt });
  const executor = new AgentExecutor({ agent, tools: [searchTool] });
  const result = await executor.invoke({ input: "Latest AI news in 2026?" });
  console.log(result.output);
}
main().catch(console.error);

Expected Output

JSON
{
  "input": "What are the latest AI frameworks released in 2026?",
  "output": "Based on search results, several AI frameworks launched in 2026 including...",
  "intermediate_steps": [
    {
      "action": "scavio_search",
      "action_input": "AI frameworks released 2026",
      "observation": "[{\"title\": \"Top AI Frameworks 2026\", ..."}]
    }
  ]
}

Related Tutorials

  • How to Add Real-Time Search to LangChain with langchain-scavio
  • How to Build an Autonomous Research Agent with 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 or higher. pip install langchain langchain-scavio langchain-openai. A Scavio API key. An OpenAI API key (or substitute any LangChain-compatible LLM). A Scavio API key gives you 250 free credits per month.

Yes. The free tier includes 250 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.

Related Resources

Use Case

LangChain RAG with Search API Grounding

Read more
Use Case

Pi Coding Agent Web Search Integration

Read more
Best Of

Best Search APIs for LangChain RAG Pipelines in May 2026

Read more
Best Of

Best Real Time Search API in 2026

Read more
Solution

Boost RAG Accuracy with Hybrid Web Search

Read more
Solution

Coding Agent Search Tool Debugging

Read more

Start Building

Connect LangChain to real-time web search using Scavio and langchain-scavio. Build a RAG agent that retrieves live data before answering questions.

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