Semantic Kernel

Register SerpApi search as a Semantic Kernel function.

Call a search constructor, register the resulting kernel_function as a plugin function, and let your kernel or agent invoke it.

Install

pip install "serpapi-search-tools[semantic-kernel]"

If Semantic Kernel is already installed in your project, use pip install serpapi-search-tools instead.

This direct function example only needs a SerpApi key:

export SERPAPI_API_KEY="your-serpapi-key"

Run it

import asyncio

from semantic_kernel import Kernel
from serpapi_search_tools import web_search


async def main():
    kernel = Kernel()
    kernel.add_function(
        plugin_name="search",
        function=web_search(
            allowed_engines=["google", "bing", "duckduckgo"],
        ),
    )
    result = await kernel.invoke(
        plugin_name="search",
        function_name="web_search",
        query="recent Python packaging releases",
        engine="google",
    )
    print(result)


asyncio.run(main())

Add the same search plugin to your Semantic Kernel agent when you want the model to choose the function.

Try it

Invoke the function with recent Python packaging releases and inspect the first three Google results.