Skip to main content
Enable agents to search the web for current information.

Quick Start

1

Create Agent with Web Search Tool

use praisonai::{Agent, tool};

// Define web search tool
#[tool(description = "Search the web for current information")]
async fn web_search(query: String) -> String {
    // Use your preferred search API
    search_api::search(&query).await
}

// Create agent with web search capability
let agent = Agent::new()
    .name("Researcher")
    .instructions("Search the web when asked about current events or news")
    .tool(web_search)
    .build()?;

let response = agent.chat("What are today's top tech news?").await?;
// Agent uses web_search tool and responds with current info
2

Using Multiple Search Tools

use praisonai::{Agent, tool};

#[tool(description = "Search news articles")]
async fn news_search(query: String) -> String {
    news_api::search(&query).await
}

#[tool(description = "Search general web")]
async fn general_search(query: String) -> String {
    google_api::search(&query).await
}

let agent = Agent::new()
    .name("Researcher")
    .instructions("Use news_search for news, general_search for other queries")
    .tool(news_search)
    .tool(general_search)
    .build()?;

How It Works


Configuration

OptionTypeDefaultDescription
web_searchboolfalseEnable web search
max_resultsusize5Results to fetch