Skip to content

serpapi_search_tool

langroid/agent/tools/serpapi_search_tool.py

A tool that searches Google's organic results through SerpApi.

Set SERPAPI_API_KEY in the environment before using this tool.

SerpApiSearchTool

Bases: ToolMessage

handle()

Run the search and format its results for the agent.

Source code in langroid/agent/tools/serpapi_search_tool.py
def handle(self) -> str:
    """Run the search and format its results for the agent."""
    search_results = serpapi_search(self.query, self.num_results)
    results_str = "\n\n".join(str(result) for result in search_results)
    return f"""
    BELOW ARE THE RESULTS FROM THE WEB SEARCH. USE THESE TO COMPOSE YOUR RESPONSE:
    {results_str}
    """