- Add langchain-community dependency for GoogleSerperAPIWrapper - Add serper_api_key to config with default key - Create app/tools/serper.py with async serper_search tool - Register "serper" key in tools/__init__.py (independent from "search"/Jina MCP) - Add tool title and input/output summaries in chat.py - Set SERPER_API_KEY on Azure App Service (Operation resource group) Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
20 lines
656 B
Python
20 lines
656 B
Python
"""Google Serper search tool via LangChain integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from langchain_community.utilities import GoogleSerperAPIWrapper
|
|
from langchain_core.tools import tool
|
|
|
|
from app.config import settings
|
|
|
|
|
|
@tool
|
|
async def serper_search(query: str) -> str:
|
|
"""Search the web using Google Serper API. Returns Google search results including snippets, links, and answer boxes."""
|
|
try:
|
|
search = GoogleSerperAPIWrapper(serper_api_key=settings.serper_api_key)
|
|
result = await search.arun(query)
|
|
return result or "No results found."
|
|
except Exception as e:
|
|
return f"Serper search failed: {e}"
|