feat(autogen-ext): add Perplexity model client + search tool#7643
feat(autogen-ext): add Perplexity model client + search tool#7643jliounis wants to merge 2 commits into
Conversation
Adds two new components to autogen-ext, mirroring the OpenAI / Anthropic / HTTP-tool patterns already in the package: - autogen_ext.models.perplexity.PerplexityChatCompletionClient: a thin wrapper around OpenAIChatCompletionClient targeting Perplexity's OpenAI-compatible endpoint (https://api.perplexity.ai). Reads PERPLEXITY_API_KEY (or PPLX_API_KEY) from the environment. - autogen_ext.tools.perplexity.PerplexitySearchTool: a BaseTool that calls POST /search and returns ranked web results (title, URL, snippet, optional date). Supports max_results, search_domain_filter (allow- or deny-list, prefix '-' to exclude), and search_recency_filter. Adds the [perplexity] extra to autogen-ext, a tutorial markdown page, and 13 mocked unit tests across both components. References: - Agent API: https://docs.perplexity.ai/docs/agent/quickstart - Search API: https://docs.perplexity.ai/docs/search/quickstart
@microsoft-github-policy-service agree |
|
@microsoft-github-policy-service agree company="Perplexity AI" |
1 similar comment
|
@microsoft-github-policy-service agree company="Perplexity AI" |
|
Added the Perplexity attribution header ( Validation: Noted that the PR is still waiting on Microsoft CLA; I did not block on that. 🤖 Comment from PSI |
Summary
Adds two new Perplexity components to
autogen-ext, mirroring the existing OpenAI / Anthropic / HTTP-tool patterns:1.
autogen_ext.models.perplexity.PerplexityChatCompletionClientA thin wrapper around
OpenAIChatCompletionClienttargeting Perplexity's OpenAI-compatible chat completions endpoint athttps://api.perplexity.ai. ReadsPERPLEXITY_API_KEY(or thePPLX_API_KEYalias) from the environment when noapi_keyis passed. Ships a sensible defaultmodel_infoblock (function_calling,json_output,structured_outputenabled;visiondisabled) so users can wire the client up without supplying their own.Pattern mirrors
autogen_ext/models/openai/_openai_client.py's gemini/claude/llama base-URL shortcuts.2.
autogen_ext.tools.perplexity.PerplexitySearchToolA
BaseToolthat callsPOST https://api.perplexity.ai/searchand returns structured ranked web results (title,url,snippet, optionaldate). Implements the standard AutoGenComponent[...]round-trip viaPerplexitySearchToolConfig(mirroringHttpTool).Args (
PerplexitySearchToolArgs):query: strmax_results: int(default 5, capped at 20)search_domain_filter: list[str] | None— allow- or deny-list; prefix a domain with-to exclude. Do not mix allow and deny in a single call.search_recency_filter: Literal["hour","day","week","month","year"] | NoneTool description deliberately does not reference Sonar models — surfaces the Search API as the product, per the linked Perplexity docs.
Other changes
[perplexity]extra inpython/packages/autogen-ext/pyproject.toml. Install withpip install -U "autogen-ext[perplexity]".python/docs/src/user-guide/agentchat-user-guide/tutorial/perplexity.md(registered intutorial/index.mdand the parent toctree).Testing
13 mocked unit tests, no live HTTP:
tests/models/test_perplexity_model_client.py(6 tests): missing-key error, env-var pickup,PPLX_API_KEYalias fallback, explicit-key precedence, custom base URL, defaultmodel_infoshape.tests/tools/test_perplexity_search_tool.py(7 tests): missing-key error, structured-result parsing, request-payload assertions (URL, headers, body), env-var alias, HTTP error propagation, tool metadata (no Sonar mention),dump_component/load_componentround-trip.Run them with:
uv run --no-sync ruff checkanduv run --no-sync mypyare clean on the new files.References