Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.perplexity.ai/llms.txt

Use this file to discover all available pages before exploring further.

Overview

AG2 ships a PerplexitySearchToolkit that wraps the Perplexity Search API as a native AG2 tool. The tool returns ranked web results — title, URL, snippet, and date — without generating an LLM answer, which keeps token usage minimal and lets the calling agent decide how to consume them.
AG2 (formerly AutoGen) is an open-source framework for building multi-agent conversational AI systems. Learn more at ag2.ai.

Installation

pip install "ag2[perplexity]"

API Key Setup

Set your Perplexity API key as an environment variable, or pass it to the toolkit constructor:
export PERPLEXITY_API_KEY="your_api_key_here"

Get API Key

Generate your API key from the Perplexity dashboard.

Quick Start

Register PerplexitySearchToolkit with an AG2 Agent:
from autogen.beta import Agent
from autogen.beta.tools.search import PerplexitySearchToolkit

toolkit = PerplexitySearchToolkit()
search = toolkit.search()

agent = Agent(
    "researcher",
    prompt="Answer using fresh information from the web.",
    tools=[search],
)

await agent.ask("What were the top tech announcements this week?")
The tool calls the Perplexity Search API under the hood and returns structured PerplexitySearchResult objects.

Configuration

All search parameters are passed to toolkit.search() and forwarded to the Search API:
from autogen.beta.tools.search import PerplexitySearchToolkit

toolkit = PerplexitySearchToolkit()
search = toolkit.search(
    max_results=5,
    max_tokens_per_page=512,
    search_domain_filter=["arxiv.org", "-medium.com"],  # prefix with '-' to exclude
    search_recency_filter="week",                         # hour | day | week | month | year
    search_after_date_filter="1/1/2025",
    search_before_date_filter="12/31/2025",
)
You can also pass any parameter as an AG2 Variable so it can be resolved from the conversation context at runtime:
from autogen.beta import Variable
from autogen.beta.tools.search import PerplexitySearchToolkit

toolkit = PerplexitySearchToolkit()
search = toolkit.search(
    max_results=Variable("user_max"),
    search_recency_filter=Variable(),  # resolved from the variable named after the parameter
)

Response Shape

Each call returns a PerplexitySearchResponse with the original query and a list of PerplexitySearchResult items:
@dataclass(slots=True)
class PerplexitySearchResult:
    title: str
    url: str
    snippet: str | None = None
    date: str | None = None

@dataclass(slots=True)
class PerplexitySearchResponse:
    query: str
    results: list[PerplexitySearchResult]
    content: str | None = None
    citations: list[str]
    images: list[PerplexityImageMeta]

AG2 Docs

Build multi-agent systems with AG2.

Tool Source

PerplexitySearchToolkit implementation.

Search API Quickstart

Learn more about the underlying Perplexity Search API.

Common Toolkits

Browse all built-in AG2 tools.

Support

Need help with the integration?