Python · llama-index
LlamaIndex + SerpKite
Give a LlamaIndex agent Google search with FunctionTool, or pull search results and full pages into an index for RAG. Everything comes back as Markdown.
Overview
What LlamaIndex is, and where SerpKite fits
LlamaIndex is a framework for RAG and agents over your data. Plain Python functions become tools with FunctionTool.from_defaults, and FunctionAgent runs the tool-calling loop.
The official serpkite Python SDK gives the agent fresh web context: sk.search for results and sk.webpage to read a page as Markdown, which LlamaIndex can chunk and index like any other document.
Setup
Set it up in 4 steps
-
1
Get an API key
Sign up (no card), create a key in the dashboard and export it as
SERPKITE_API_KEY. New accounts get 2,500 free credits, then 1,000 every month.export SERPKITE_API_KEY=skt_live_… -
2
Install
The core package plus an LLM integration.
pip install -U serpkite llama-index llama-index-llms-openai -
3
Wrap the API as FunctionTools
One for search, one for reading pages.
-
4
Run the agent
FunctionAgent.runis async; useasyncio.runin a script.
Code
Complete example
from serpkite import SerpKite, SerpKiteError
sk = SerpKite() # reads SERPKITE_API_KEY
def serpkite_search(query: str, country: str = "us", num: int = 10) -> str:
"""Google search via SerpKite. Returns the results page as compact Markdown."""
try:
# format="markdown" returns a str: results, People Also Ask, related searches
return sk.search(query, country=country, num=num, format="markdown")
except SerpKiteError as e:
return f"Search failed: {e.message}"
import asyncio
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.core.tools import FunctionTool
from llama_index.llms.openai import OpenAI
def read_webpage(url: str) -> str:
"""Fetch a public web page and return its main content as Markdown."""
try:
return sk.webpage(url).markdown
except SerpKiteError:
return "Could not read the page."
tools = [
FunctionTool.from_defaults(fn=serpkite_search, name="google_search",
description="Search Google for current information. Returns the top results with links, People Also Ask and related searches as Markdown. Use for recent events, facts and anything after your training cutoff."),
FunctionTool.from_defaults(fn=read_webpage),
]
agent = FunctionAgent(
tools=tools,
llm=OpenAI(model="gpt-5-mini"),
system_prompt="Search the web before answering. Cite the URLs you used.",
)
async def main():
response = await agent.run("What are the main approaches to retrieval-augmented generation in 2026?")
print(response)
asyncio.run(main())RAG
Index search results and pages
For RAG, fetch the top results as Markdown and build an index. include_content=3 on /v1/search returns the top three pages' Markdown in results[].content, in the same call (+1 credit per page).
from llama_index.core import Document, VectorStoreIndex
from serpkite import SerpKite
sk = SerpKite()
serp = sk.search("retrieval augmented generation survey", include_content=3)
docs = [
Document(text=r.content, metadata={"url": r.link, "title": r.title})
for r in serp.results if r.content
]
index = VectorStoreIndex.from_documents(docs)
print(index.as_query_engine().query("What evaluation metrics are used for RAG?"))FAQ
LlamaIndex and SerpKite: common questions
Keep exploring
Related APIs and integrations
Start building
Give your LlamaIndex project Google search
2,500 free credits, then 1,000 every month. No credit card.