ScavioScavio
ProduitTarifsDocumentation
ConnexionCommencer
  1. Accueil
  2. Tutoriels
  3. Comment connecter Scavio à LangChain RAG
Tutoriel

Comment connecter Scavio à LangChain RAG

Ajoutez Scavio comme outil LangChain dans un agent RAG. Configurez l'outil, connectez-le à une chaîne d'agents, et montrez le flux de récupération et de génération avec des exemples de code.

Obtenez une clé API gratuiteDocumentation API

Vous pouvez ajouter Scavio comme outil LangChain en encapsulant l'API de recherche dans un objet Tool et en le passant à un agent. L'agent appelle l'outil lorsqu'il a besoin d'informations actuelles, récupère les résultats et les utilise dans sa réponse finale.

Prérequis

  • Python 3.9+
  • paquets langchain, langchain-anthropic
  • Clé API Scavio
  • Clé API Anthropic

Parcours

Étape 1: Installer les dépendances

Installer LangChain et l'intégration Anthropic.

Bash
pip install langchain langchain-anthropic requests

Étape 2: Définir l'outil de recherche Scavio

Encapsuler l'appel API de recherche comme un outil LangChain avec une description claire.

Python
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."
)

Étape 3: Créer l'agent avec l'outil

Utiliser create_react_agent ou initialize_agent de LangChain avec l'outil de recherche.

Python
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"])

Exemple Python

Python
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")

Exemple JavaScript

JavaScript
// 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);

Sortie attendue

JSON
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).

Tutoriels associés

  • Comment intégrer une API de recherche avec CrewAI
  • Comment configurer le RAG avec la recherche au lieu des vecteurs
  • Comment construire un agent de recherche multi-source

Questions fréquentes

La plupart des développeurs terminent ce tutoriel en 15 à 30 minutes. Vous aurez besoin d'une clé API Scavio (l'offre gratuite suffit) et d'un environnement Python ou JavaScript fonctionnel.

Python 3.9+. paquets langchain, langchain-anthropic. Clé API Scavio. Clé API Anthropic. Une clé API Scavio vous donne 50 crédits gratuits à l'inscription.

Oui. L'offre gratuite comprend 50 crédits à l'inscription, ce qui est largement suffisant pour terminer ce tutoriel et prototyper une solution fonctionnelle.

Scavio dispose d'un package natif LangChain (langchain-scavio), d'un serveur MCP et d'une API REST simple qui fonctionne avec tout client HTTP. Ce tutoriel utilise LangChain, mais vous pouvez l'adapter à votre framework de prédilection.

Ressources connexes

Best Of

Meilleures API de recherche pour pipelines RAG LangChain en mai 2026

Read more
Use Case

Intégration de la recherche web pour Pi Coding Agent

Read more
Best Of

Meilleure API de recherche pour LangChain en 2026

Read more
Use Case

Fiabilité de l'API Hermes Agent Search

Read more
Solution

Un outil de recherche pour tout framework d'agent IA

Read more
Solution

RAG local avec repli sur l'API de recherche

Read more

Commencer

Ajoutez Scavio comme outil LangChain dans un agent RAG. Configurez l'outil, connectez-le à une chaîne d'agents, et montrez le flux de récupération et de génération avec des exemples de code.

Obtenez une clé API gratuiteLire la documentation
ScavioScavio

API de recherche en temps réel pour agents IA. Recherchez sur toutes les plateformes, pas seulement Google.

Produit

  • Fonctionnalités
  • Tarifs
  • Tableau de bord
  • Affiliés

Développeurs

  • Documentation
  • Référence API
  • Démarrage rapide
  • Intégration MCP
  • SDK Python

Alternatives

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

Outils

  • Formateur JSON
  • cURL vers code
  • Compteur de jetons
  • Tous les outils

© 2026 Scavio. Tous droits réservés.

Featured on TAAFT
Conditions d'utilisationPolitique de confidentialité