You can add Scavio as a LangChain tool by wrapping the search API in a Tool object and passing it to an agent. The agent calls the tool when it needs current information, retrieves the results, and uses them in its final answer.
Prerequisites
- Python 3.9+
- langchain, langchain-anthropic packages
- Scavio API key
- Anthropic API key
Walkthrough
Step 1: Install dependencies
Install LangChain and the Anthropic integration.
pip install langchain langchain-anthropic requestsStep 2: Define the Scavio search tool
Wrap the search API call as a LangChain Tool with a clear description.
import requests
from langchain.tools import Tool
SCAVIO_KEY = "your-scavio-api-key"
def scavio_search(query: str) -> str:
r = requests.post(
"https://api.scavio.dev/api/v1/search",
json={"query": query, "num_results": 5},
headers={"x-api-key": SCAVIO_KEY},
timeout=15
)
r.raise_for_status()
results = r.json().get("organic_results", [])
return "\n\n".join(
f"{r['title']}\n{r.get('snippet','')}\n{r['link']}"
for r in results[:5]
) or "No results found."
search_tool = Tool(
name="web_search",
func=scavio_search,
description="Search the web for current information. Input is a search query string."
)Step 3: Create the agent with the tool
Use LangChain's create_react_agent or initialize_agent with the search tool.
from langchain_anthropic import ChatAnthropic
from langchain.agents import create_react_agent, AgentExecutor
from langchain.prompts import PromptTemplate
ANTHROPIC_KEY = "your-anthropic-key"
llm = ChatAnthropic(
model="claude-sonnet-4-6",
anthropic_api_key=ANTHROPIC_KEY
)
tools = [search_tool]
prompt = PromptTemplate.from_template("""
You are a research assistant. Use the web_search tool to find current information.
Tools: {tools}
Tool names: {tool_names}
Question: {input}
Thought: {agent_scratchpad}
""")
agent = create_react_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True, max_iterations=3)
result = executor.invoke({"input": "What is the current price of Anthropic Claude API?"})
print(result["output"])Python Example
import requests
from langchain.tools import Tool
from langchain_anthropic import ChatAnthropic
from langchain.agents import create_react_agent, AgentExecutor
from langchain.prompts import PromptTemplate
SCAVIO_KEY = "your-scavio-api-key"
ANTHROPIC_KEY = "your-anthropic-key"
def scavio_search(query: str) -> str:
r = requests.post(
"https://api.scavio.dev/api/v1/search",
json={"query": query, "num_results": 5},
headers={"x-api-key": SCAVIO_KEY}, timeout=15
)
r.raise_for_status()
items = r.json().get("organic_results", [])
return "\n\n".join(f"{i['title']}\n{i.get('snippet','')}\n{i['link']}" for i in items[:5]) or "No results."
search_tool = Tool(name="web_search", func=scavio_search,
description="Search the web for current information. Input: search query string.")
llm = ChatAnthropic(model="claude-sonnet-4-6", anthropic_api_key=ANTHROPIC_KEY)
prompt = PromptTemplate.from_template("""
Answer questions using the web_search tool for current information.
Tools: {tools}
Tool names: {tool_names}
Question: {input}
{agent_scratchpad}
""")
agent = create_react_agent(llm, [search_tool], prompt)
executor = AgentExecutor(agent=agent, tools=[search_tool], verbose=False, max_iterations=3)
if __name__ == "__main__":
questions = [
"What AI models did Anthropic release in 2026?",
"What is the price of Firecrawl per month?"
]
for q in questions:
result = executor.invoke({"input": q})
print(f"Q: {q}")
print(f"A: {result['output']}\n")JavaScript Example
// LangChain JS equivalent
import { DynamicTool } from '@langchain/core/tools';
import { ChatAnthropic } from '@langchain/anthropic';
import { AgentExecutor, createReactAgent } from 'langchain/agents';
import { pull } from 'langchain/hub';
const SCAVIO_KEY = 'your-scavio-api-key';
const searchTool = new DynamicTool({
name: 'web_search',
description: 'Search the web for current information. Input: search query string.',
func: async (query) => {
const res = await fetch('https://api.scavio.dev/api/v1/search', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'x-api-key': SCAVIO_KEY },
body: JSON.stringify({ query, num_results: 5 })
});
const data = await res.json();
return (data.organic_results ?? [])
.map(r => `${r.title}\n${r.snippet ?? ''}\n${r.link}`).join('\n\n') || 'No results.';
}
});
const llm = new ChatAnthropic({ model: 'claude-sonnet-4-6', apiKey: 'your-anthropic-key' });
const prompt = await pull('hwchase17/react');
const agent = await createReactAgent({ llm, tools: [searchTool], prompt });
const executor = new AgentExecutor({ agent, tools: [searchTool], maxIterations: 3 });
const result = await executor.invoke({ input: 'What is the current Anthropic Claude API pricing?' });
console.log(result.output);Expected Output
Q: What AI models did Anthropic release in 2026?
A: Based on current search results, Anthropic released Claude 3.7 Sonnet and Claude 4 Opus in 2026. Claude 3.7 Sonnet introduced extended thinking mode with a 200K context window.
Q: What is the price of Firecrawl per month?
A: Firecrawl offers a free tier with 1,000 credits, a Starter plan at $16/month for 5,000 credits, and a Scale plan at $83/month for 100,000 credits (annual billing).