ScavioScavio
ProductPricingDocs
Sign InGet Started
  1. Home
  2. Tutorials
  3. How to Add Live Search to a Support Agent
Tutorial

How to Add Live Search to a Support Agent

Give your customer support AI agent live web search so it can answer questions about current docs, outages, and product updates. Python and JS code.

Get Free API KeyAPI Docs

Add live search to a customer support agent by integrating a search API call that triggers when the agent's internal knowledge base has no relevant answer. This prevents the agent from hallucinating about product features, pricing, or outage status when the KB is stale. Scavio's API returns current Google results that the agent can use as grounding context before generating a response. This tutorial builds a support agent middleware that decides when to search and how to inject results into the agent's context.

Prerequisites

  • Python 3.8+ or Node.js 18+ installed
  • requests library (Python) or built-in fetch (JS)
  • A Scavio API key from scavio.dev
  • An existing support agent or chatbot framework

Walkthrough

Step 1: Define the search trigger logic

Build a classifier that decides whether a support query needs live search or can be answered from the internal KB alone.

Python
import os, requests

API_KEY = os.environ['SCAVIO_API_KEY']

SEARCH_TRIGGERS = ['current', 'latest', 'today', 'outage', 'status', 'pricing', 'update', 'new feature', 'changelog', 'release']

def needs_live_search(query: str) -> bool:
    query_lower = query.lower()
    return any(trigger in query_lower for trigger in SEARCH_TRIGGERS)

Step 2: Fetch live context from search

When search is triggered, query Scavio with the customer's question scoped to your product's domain for the most relevant results.

Python
def fetch_support_context(query: str, product_domain: str = '') -> str:
    search_query = f'{query} site:{product_domain}' if product_domain else query
    resp = requests.post('https://api.scavio.dev/api/v1/search',
        headers={'x-api-key': API_KEY},
        json={'platform': 'google', 'query': search_query}, timeout=10)
    results = resp.json().get('organic_results', [])
    context_parts = []
    for r in results[:3]:
        context_parts.append(f"Title: {r.get('title', '')}\nURL: {r.get('link', '')}\nSnippet: {r.get('snippet', '')}")
    return '\n\n'.join(context_parts)

Step 3: Inject context into the agent prompt

Prepend the live search results to the agent's system prompt so it uses current information when answering.

Python
def build_support_prompt(user_query: str, kb_answer: str, product_domain: str) -> str:
    prompt = f'Customer question: {user_query}\n\n'
    prompt += f'Knowledge base answer: {kb_answer}\n\n'
    if needs_live_search(user_query):
        live_context = fetch_support_context(user_query, product_domain)
        prompt += f'Live web context (use if KB answer is outdated):\n{live_context}\n\n'
    prompt += 'Respond helpfully. Prefer live data over KB if there is a conflict. Cite URLs when using web results.'
    return prompt

result = build_support_prompt(
    'Is there a current outage?',
    'No known outages.',
    'status.example.com'
)
print(result)

Step 4: Handle fallback when search has no results

Gracefully degrade when the search API returns no results or times out, falling back to the KB answer only.

Python
def safe_support_search(query: str, product_domain: str = '') -> str:
    try:
        context = fetch_support_context(query, product_domain)
        if context.strip():
            return context
    except Exception as e:
        print(f'Search fallback: {e}')
    return ''

def answer_support_query(user_query: str, kb_answer: str, product_domain: str) -> dict:
    live_context = safe_support_search(user_query, product_domain) if needs_live_search(user_query) else ''
    return {
        'query': user_query,
        'kb_answer': kb_answer,
        'live_context': live_context,
        'used_search': bool(live_context),
    }

Python Example

Python
import requests, os
H = {'x-api-key': os.environ['SCAVIO_API_KEY']}

def support_search(query, domain=''):
    q = f'{query} site:{domain}' if domain else query
    data = requests.post('https://api.scavio.dev/api/v1/search', headers=H,
        json={'platform': 'google', 'query': q}, timeout=10).json()
    return [{'title': r['title'], 'url': r['link'], 'snippet': r.get('snippet', '')}
        for r in data.get('organic_results', [])[:3]]

print(support_search('current outage status', 'status.example.com'))

JavaScript Example

JavaScript
const H = {'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'};
async function supportSearch(query, domain = '') {
  const q = domain ? `${query} site:${domain}` : query;
  const r = await fetch('https://api.scavio.dev/api/v1/search', {
    method: 'POST', headers: H, body: JSON.stringify({platform: 'google', query: q})
  });
  const results = (await r.json()).organic_results || [];
  return results.slice(0, 3).map(r => ({title: r.title, url: r.link, snippet: r.snippet}));
}
supportSearch('current outage status', 'status.example.com').then(console.log);

Expected Output

JSON
A support agent middleware that triggers live web search for time-sensitive queries and injects fresh context into the agent's response pipeline.

Related Tutorials

  • How to Ground a Support Bot with Live Search
  • How to Add Live Data to AI Automation Systems

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.8+ or Node.js 18+ installed. requests library (Python) or built-in fetch (JS). A Scavio API key from scavio.dev. An existing support agent or chatbot framework. A Scavio API key gives you 50 free credits on signup.

Yes. The free tier includes 50 credits on signup, 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.

Related Resources

Best Of

Best Search API for Customer Support Bots in 2026

Read more
Use Case

Ground Cursor Agent with Live Web Search

Read more
Solution

Ground Customer Support Agents with Live Search

Read more
Best Of

Best Pi Coding Agent Search Extensions (May 2026)

Read more
Use Case

Customer Support Agent Grounded in Search

Read more
Workflow

Feed Live Data from 6 Platforms to AI Agent

Read more

Start Building

Give your customer support AI agent live web search so it can answer questions about current docs, outages, and product updates. Python and JS code.

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