Skip to main content
Install Caesar with the LlamaIndex package set you already use:
pip install caesar-search llama-index

Function tools

from caesar_search import Caesar
from llama_index.core.tools import FunctionTool

client = Caesar()  # reads CAESAR_API_KEY; anonymous works without a key


def caesar_search(query: str, max_results: int = 5) -> str:
    """Search the web with Caesar and return compact JSON."""
    response = client.search(query, max_results=max_results, verbosity="compact")
    return response.model_dump_json()


def caesar_read(target: str, query: str | None = None, max_chars: int = 12000) -> str:
    """Read a Caesar doc_id or URL as markdown plus metadata."""
    response = client.read(target, query=query, max_chars=max_chars)
    return response.model_dump_json()


caesar_search_tool = FunctionTool.from_defaults(
    fn=caesar_search,
    name="caesar_search",
    description="Search the web with Caesar. Returns ranked results with doc_id handles.",
)

caesar_read_tool = FunctionTool.from_defaults(
    fn=caesar_read,
    name="caesar_read",
    description="Read a Caesar doc_id or URL as clean markdown.",
)

tools = [caesar_search_tool, caesar_read_tool]
Pass tools into your agent workflow. Keep the JSON response intact unless you have a reason to trim it; the doc_id, search_id, and provenance fields are the useful part of the result.

Search, then read

The strongest pattern is a two-step loop:
  1. caesar_search(query, max_results=5) to find candidates.
  2. Pick the most relevant doc_id.
  3. caesar_read(doc_id, query="what the agent needs") to fetch clean markdown.
  4. Send feedback through the SDK if a result helped.
results = client.search("postgres 17 logical replication failover", max_results=5)
doc_id = results.results[0].doc_id
doc = client.read(doc_id, query="failover behavior")
client.feedback("result_helpful", search_id=results.search_id, doc_id=doc_id)

For agents

  • Return JSON from the tool when possible. It preserves snake_case fields and prevents accidental loss of doc_id.
  • Prefer verbosity="compact" for the search tool. Read the selected document for longer evidence.
  • On truncated reads, continue with the returned start_char value instead of asking for a larger max_chars.
  • If your LlamaIndex runtime can consume MCP tools directly, use the remote MCP server and skip custom wrappers.