Tutorial

How to Add Web Search to a DeerFlow Agent

Add live web search to a DeerFlow research agent using the Scavio API. Python example with tool registration, search node, and result parsing.

Adding web search to a DeerFlow agent gives it access to live data for research tasks instead of relying on static training knowledge. DeerFlow is a deep research framework that orchestrates multi-step investigation workflows, but out of the box it needs a search tool to gather external evidence. This tutorial registers a Scavio search tool in a DeerFlow agent, wires it into the research flow, and parses structured SERP data into the agent's context format.

Prerequisites

  • Python 3.10+
  • DeerFlow installed (pip install deerflow)
  • Scavio API key from scavio.dev
  • Basic understanding of agent tool registration

Walkthrough

Step 1: Create the search tool function

Define a search function that calls the Scavio API and returns results in the format DeerFlow expects.

Python
import os, requests

H = {'x-api-key': os.environ['SCAVIO_API_KEY'], 'Content-Type': 'application/json'}

def web_search(query: str, num_results: int = 5) -> list[dict]:
    '''Search the web and return structured results.'''
    data = requests.post('https://api.scavio.dev/api/v1/search',
        headers=H, json={'query': query, 'country_code': 'us'}).json()
    results = []
    for r in data.get('organic_results', [])[:num_results]:
        results.append({
            'title': r.get('title', ''),
            'url': r.get('link', ''),
            'content': r.get('snippet', ''),
        })
    return results

Step 2: Register the tool with DeerFlow

Register the search function as a tool in the DeerFlow agent configuration so it can be called during research flows.

Python
from deerflow import DeerFlowAgent, Tool

search_tool = Tool(
    name='web_search',
    description='Search the web for current information. Use for fact-checking, finding recent data, and research.',
    function=web_search,
    parameters={
        'query': {'type': 'string', 'description': 'The search query', 'required': True},
        'num_results': {'type': 'integer', 'description': 'Number of results to return', 'default': 5},
    }
)

agent = DeerFlowAgent(
    name='research_agent',
    tools=[search_tool],
    model='gpt-4o',
    system_prompt='You are a research agent. Use web_search to find current information before answering.',
)

Step 3: Add multi-platform search capability

Extend the tool to search across Google, Reddit, and YouTube for comprehensive research coverage.

Python
def multi_search(query: str, platforms: list[str] = None) -> dict:
    '''Search across multiple platforms for comprehensive research.'''
    if platforms is None:
        platforms = ['google', 'reddit']
    all_results = {}
    for platform in platforms:
        params = {'query': query, 'country_code': 'us'}
        if platform != 'google':
            params['platform'] = platform
        data = requests.post('https://api.scavio.dev/api/v1/search',
            headers=H, json=params).json()
        all_results[platform] = [{
            'title': r.get('title', ''),
            'url': r.get('link', ''),
            'content': r.get('snippet', ''),
        } for r in data.get('organic_results', [])[:3]]
    return all_results

multi_search_tool = Tool(
    name='multi_search',
    description='Search multiple platforms (google, reddit, youtube) for research.',
    function=multi_search,
    parameters={
        'query': {'type': 'string', 'required': True},
        'platforms': {'type': 'array', 'items': {'type': 'string'}, 'default': ['google', 'reddit']},
    }
)

Step 4: Run a research task

Execute a research query and observe the agent using search tools to gather evidence before synthesizing an answer.

Python
async def run_research():
    agent = DeerFlowAgent(
        name='research_agent',
        tools=[search_tool, multi_search_tool],
        model='gpt-4o',
        system_prompt='You are a research agent. Always search before answering. Cite sources.',
    )
    result = await agent.run(
        'What are the top 3 LLM agent frameworks in 2026 and how do they compare?'
    )
    print(result.answer)
    print(f'\nTools called: {len(result.tool_calls)}')
    for call in result.tool_calls:
        print(f'  - {call.tool_name}({call.arguments.get("query", "")})')

import asyncio
asyncio.run(run_research())

Python Example

Python
import os, requests, asyncio
from deerflow import DeerFlowAgent, Tool

H = {'x-api-key': os.environ['SCAVIO_API_KEY'], 'Content-Type': 'application/json'}

def web_search(query: str, num_results: int = 5) -> list[dict]:
    data = requests.post('https://api.scavio.dev/api/v1/search',
        headers=H, json={'query': query, 'country_code': 'us'}).json()
    return [{'title': r.get('title', ''), 'url': r.get('link', ''),
             'content': r.get('snippet', '')}
            for r in data.get('organic_results', [])[:num_results]]

def multi_search(query: str, platforms: list[str] = None) -> dict:
    platforms = platforms or ['google', 'reddit']
    results = {}
    for p in platforms:
        params = {'query': query, 'country_code': 'us'}
        if p != 'google': params['platform'] = p
        data = requests.post('https://api.scavio.dev/api/v1/search',
            headers=H, json=params).json()
        results[p] = [{'title': r.get('title',''), 'url': r.get('link',''),
            'content': r.get('snippet','')} for r in data.get('organic_results',[])[:3]]
    return results

async def main():
    agent = DeerFlowAgent(
        name='researcher',
        tools=[
            Tool(name='web_search', description='Search the web', function=web_search,
                 parameters={'query': {'type':'string','required':True}}),
            Tool(name='multi_search', description='Multi-platform search', function=multi_search,
                 parameters={'query': {'type':'string','required':True},
                             'platforms': {'type':'array','default':['google','reddit']}}),
        ],
        model='gpt-4o',
        system_prompt='Research agent. Search before answering. Cite sources.',
    )
    result = await agent.run('Compare LangGraph vs CrewAI vs AutoGen in 2026')
    print(result.answer)

asyncio.run(main())

JavaScript Example

JavaScript
const H = {'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'};

async function webSearch(query, numResults = 5) {
  const data = await fetch('https://api.scavio.dev/api/v1/search', {
    method: 'POST', headers: H,
    body: JSON.stringify({query, country_code: 'us'})
  }).then(r => r.json());
  return (data.organic_results || []).slice(0, numResults).map(r => ({
    title: r.title || '', url: r.link || '', content: r.snippet || ''
  }));
}

async function multiSearch(query, platforms = ['google', 'reddit']) {
  const results = {};
  for (const p of platforms) {
    const params = {query, country_code: 'us'};
    if (p !== 'google') params.platform = p;
    const data = await fetch('https://api.scavio.dev/api/v1/search', {
      method: 'POST', headers: H, body: JSON.stringify(params)
    }).then(r => r.json());
    results[p] = (data.organic_results || []).slice(0, 3).map(r => ({
      title: r.title, url: r.link, content: r.snippet
    }));
  }
  return results;
}

// Register with DeerFlow (JS SDK)
// const agent = new DeerFlowAgent({tools: [{name: 'web_search', fn: webSearch}]});
console.log('DeerFlow search tools ready');
webSearch('LangGraph vs CrewAI 2026').then(r => console.log(\`\${r.length} results\`));

Expected Output

JSON
Research agent output:
- LangGraph: Best for stateful, cyclic agent workflows. Most GitHub stars in 2026.
- CrewAI: Best for multi-agent orchestration with role-based agents.
- AutoGen: Best for conversational multi-agent patterns.

Tools called: 3
  - web_search(LLM agent frameworks comparison 2026)
  - multi_search(LangGraph vs CrewAI vs AutoGen)
  - web_search(agent framework github stars 2026)

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.10+. DeerFlow installed (pip install deerflow). Scavio API key from scavio.dev. Basic understanding of agent tool registration. 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 the raw REST API, but you can adapt to your framework of choice.

Start Building

Add live web search to a DeerFlow research agent using the Scavio API. Python example with tool registration, search node, and result parsing.