Enable agents to search the web and access real-time information from the internet
Web Search empowers agents to find current information on the internet, access news, research topics, and retrieve up-to-date data beyond their training cutoff.
The Web Search primitive gives agents the ability to search the internet in real-time, enabling them to access current information, news, facts, and data that may not be in their training data or your internal knowledge bases. This bridges the gap between static knowledge and dynamic, ever-changing web content.Web Search is essential for:
Current Events: Access latest news and developments
Real-Time Data: Get current prices, weather, sports scores, etc.
Research: Find information on any topic from the web
Fact-Checking: Verify information against multiple sources
Market Intelligence: Research competitors, trends, and market data
Comprehensive Answers: Combine internal knowledge with web content
Real-Time Access
Search current web content, not limited to training data cutoff
Multiple Sources
Aggregate information from multiple search results automatically
Safe Search
Built-in content filtering and safe search capabilities
import { Agentbase } from '@agentbase/sdk';const agentbase = new Agentbase({ apiKey: process.env.AGENTBASE_API_KEY});// Enable web searchconst result = await agentbase.runAgent({ message: "What are the latest developments in quantum computing?", webSearch: { enabled: true }});console.log('Answer:', result.message);console.log('Sources:', result.sources);// Sources include URLs from web search
// Use both internal docs and web searchconst result = await agentbase.runAgent({ message: "How does our product compare to the latest market alternatives?", datastores: [ { id: productDocs, name: "Product Documentation" } ], webSearch: { enabled: true, filters: { timeRange: "past_month" } }, system: `You are a product analyst. Combine: - Internal product documentation (via RAG) - Latest market information (via web search) Provide comprehensive competitive analysis.`});// Agent uses both internal knowledge and web research
const marketResearch = await agentbase.runAgent({ message: "What are the top CRM platforms for small businesses in 2024?", webSearch: { enabled: true, filters: { timeRange: "past_3_months" } }, system: `You are a market research analyst. Research and provide: - Top platforms and their features - Pricing comparison - User reviews and ratings - Market share insights - Cite sources for all data`});
const realTimeAgent = await agentbase.runAgent({ message: "What's the current weather in Tokyo and the USD to JPY exchange rate?", webSearch: { enabled: true, depth: "quick" // Fast lookup }, system: `Provide current, accurate information. Always cite the source and timestamp.`});
const shoppingAgent = await agentbase.runAgent({ message: "Best noise-canceling headphones under $300 for travel", webSearch: { enabled: true, filters: { timeRange: "past_6_months" // Recent reviews } }, system: `You are a product research assistant. Research and provide: - Top recommended products - Pros and cons of each - Price comparison - User ratings and reviews - Where to buy - Cite review sources`});
const troubleshootAgent = await agentbase.runAgent({ message: "How to fix CORS errors in Next.js API routes", webSearch: { enabled: true, domains: [ "stackoverflow.com", "github.com", "nextjs.org" ] }, system: `You are a technical support assistant. Find and provide: - Clear explanation of the issue - Step-by-step solutions - Code examples - Common pitfalls - Links to documentation and discussions`});
const travelAgent = await agentbase.runAgent({ message: "Plan a 5-day trip to Barcelona - best attractions, hotels, and restaurants", webSearch: { enabled: true, filters: { timeRange: "past_year", // Current travel info language: "en" } }, system: `You are a travel planning assistant. Research and create itinerary with: - Top attractions and activities - Hotel recommendations by area - Restaurant suggestions - Transportation tips - Estimated costs - Cite travel guides and review sites`});
Let Agent Formulate Queries: The agent will automatically formulate effective search queries. Your prompt should focus on what information you need, not how to search for it.
Good Search Prompts
Copy
// Good: Clear information need"What are the latest features in Python 3.12?""Compare pricing of top 5 project management tools""Recent developments in renewable energy technology"// Avoid: Trying to write search queries"Search for 'Python 3.12 new features'""Google 'project management tools pricing'"
Specify Time Sensitivity
Copy
// Good: Specify recency when needed{ message: "Latest iPhone release details", webSearch: { enabled: true, filters: { timeRange: "past_week" // Recent info } }}// For evergreen topics, recency less important{ message: "How does photosynthesis work?", webSearch: { enabled: true // No time filter needed }}
Verify Critical Information: Web search returns information from the internet, which may not always be accurate. Always verify critical information from authoritative sources.
Copy
const result = await agentbase.runAgent({ message: "What are the tax implications of cryptocurrency trading?", webSearch: { enabled: true, domains: [ "irs.gov", // Official sources "tax.gov" ] }, system: `You are a tax information assistant. Important: - Only cite official government sources for tax information - Clearly state this is not professional tax advice - Recommend consulting a tax professional - Indicate if information may be outdated`, rules: [ "Only use official government sources for tax information", "Clearly state this is general information, not professional advice", "Recommend consulting a tax professional for specific situations" ]});
const result = await agentbase.runAgent({ message: "How does our product stack up against recent competitor releases?", datastores: [{ id: productDocs }], // Internal docs webSearch: { enabled: true }, // Web research system: `Compare our product features (from internal docs) with competitor information (from web search). Provide: - Feature comparison table - Competitive advantages - Areas for improvement`});
const result = await agentbase.runAgent({ message: "Find more articles on topics we discussed before", memory: { namespace: `user_${userId}`, enabled: true }, webSearch: { enabled: true }});// Agent recalls previous research topics from memory// and searches for related content
const result = await agentbase.runAgent({ message: "Research both electric vehicle market trends AND battery technology advances", webSearch: { enabled: true, multiQuery: true // Performs separate searches and synthesizes }, system: `Research both topics thoroughly and show how they relate.`});
const result = await agentbase.runAgent({ message: "What are different perspectives on remote work?", webSearch: { enabled: true, diverseSources: true, // Get results from variety of sources maxResults: 10 }});
const result = await agentbase.runAgent({ message: "Is it true that coffee is good for your health?", webSearch: { enabled: true, verifyFacts: true, // Check multiple sources domains: [ "nih.gov", "mayoclinic.org", "health.harvard.edu" ] }, system: `Verify this claim against multiple authoritative sources. Indicate if sources disagree.`});
Remember: Web search provides access to current information but requires verification. Always cite sources and encourage users to verify critical information from authoritative sources.