LangChain is the most widely used Python framework for building LLM-powered applications. Adding real-time web search to a LangChain application transforms it from relying on a static training cutoff to accessing live information. The langchain-scavio package provides a plug-and-play ScavioSearch tool compatible with LangChain's tool interface, LCEL chains, and agent executors. This tutorial covers installation, configuration, and three common integration patterns: standalone tool call, LCEL chain, and ReAct agent.
Prerequisites
- Python 3.10 or higher
- pip install langchain langchain-scavio langchain-openai
- A Scavio API key
- A LangChain-compatible LLM API key
Walkthrough
Step 1: Install langchain-scavio
Install the integration package. It provides ScavioSearch as a BaseTool subclass with configurable platform, country, and result count.
pip install langchain langchain-scavio langchain-openaiStep 2: Use ScavioSearch as a standalone tool
Invoke ScavioSearch directly without an agent to verify the integration and inspect the returned data.
from langchain_scavio import ScavioSearch
tool = ScavioSearch(api_key="your_scavio_api_key", platform="google", country_code="us")
result = tool.invoke("latest LLM releases 2026")
print(result[:500]) # Returns formatted string of top resultsStep 3: Add to an LCEL chain
Bind ScavioSearch as a context retriever in an LCEL chain that fetches search results before generating an answer.
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
llm = ChatOpenAI(model="gpt-4o")
prompt = ChatPromptTemplate.from_template("Answer using this context:\n{context}\n\nQuestion: {question}")
chain = ({"context": tool, "question": lambda x: x}) | prompt | llm | StrOutputParser()
result = chain.invoke("What are the best Python AI libraries in 2026?")Step 4: Bind to a tool-calling agent
Register ScavioSearch with a tool-calling agent so the LLM can decide when to search.
llm_with_tools = ChatOpenAI(model="gpt-4o").bind_tools([tool])
response = llm_with_tools.invoke("What is the current price of gold?")
print(response.tool_calls)Python Example
import os
from langchain_scavio import ScavioSearch
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
os.environ["OPENAI_API_KEY"] = "your_openai_key"
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 = ChatPromptTemplate.from_template(
"Use the following search results to answer the question.\nResults: {context}\nQuestion: {question}"
)
chain = ({"context": tool, "question": lambda x: x}) | prompt | llm | StrOutputParser()
if __name__ == "__main__":
answer = chain.invoke("What are the top Python libraries for building AI agents in 2026?")
print(answer)JavaScript Example
const { ChatOpenAI } = require("@langchain/openai");
const { DynamicTool } = require("@langchain/core/tools");
const API_KEY = process.env.SCAVIO_API_KEY;
// langchain-scavio is Python-only; use DynamicTool in JS
const scavioTool = new DynamicTool({
name: "scavio_google_search",
description: "Search Google for current information. Returns top organic results.",
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 (data.organic_results || []).slice(0, 5)
.map(r => `${r.title}: ${r.snippet || ""}`).join("\n");
}
});
async function main() {
const result = await scavioTool.invoke("best Python AI libraries 2026");
console.log(result);
}
main().catch(console.error);Expected Output
Answer: Based on 2026 search results, the top Python AI libraries include:
1. LangChain — agent orchestration and LLM chains
2. LlamaIndex — data framework for LLM apps
3. CrewAI — multi-agent coordination
4. Haystack — production RAG pipelines
5. Pydantic AI — structured output agents