Skip to main content
The Perplexity AI search integration allows users to perform real-time web searches within the AG2 framework. Follow these steps to integrate PerplexitySearchTool with AG2 Agents.

Configuring Your Perplexity API Key

  1. Create a Perplexity Account:
    • Visit Perplexity AI
    • Click Sign Up and create an account
    • Select Free Tier during registration
  2. Get API Key:
    • Navigate to API Settings
    • Add payment method (required)
    • Generate API key under API Keys
  3. Set Environment Variable:

Package Installation

To get started with the Perplexity Search integration in AG2, follow these steps: Install AG2 with openai since we use OpenAI’s LLMs in our example:
Note: If you have been using autogen or ag2, all you need to do is upgrade it using:
or
as autogen and ag2 are aliases for the same PyPI package.
You’re all set! Now you can start using Perplexity AI Search with AG2.

Implementation

Imports

Agent Configuration

Configure an assistant agent and user proxy to be used for LLM recommendation and execution respectively.

Tool Setup

Usage Example

With the setup complete, you can now use the assistant to fetch live web search results.

Output

Key Considerations

Cost Management

Free Tier Limits:

Performance Optimizations

Best Practices:
  • Start with smaller response lengths by setting the max_tokens parameter.
  • Filter search domains with search_domain_filter parameter to restrict the search results to specific domains.
Note: The search_domain_filter parameter is an advanced feature available exclusively to Pro Tier or higher subscribers of the Perplexity API; please consult Perplexity’s usage tiers documentation for further details.