Skip to content

Add Perplexity sample agent (Python)#273

Open
Yogeshp-MSFT wants to merge 2 commits intomicrosoft:mainfrom
Yogeshp-MSFT:Perplexity-Python-Sample
Open

Add Perplexity sample agent (Python)#273
Yogeshp-MSFT wants to merge 2 commits intomicrosoft:mainfrom
Yogeshp-MSFT:Perplexity-Python-Sample

Conversation

@Yogeshp-MSFT
Copy link
Copy Markdown

Adds a Python sample agent using Perplexity AI (Agent API / Responses API) with the Microsoft Agent 365 SDK.

What's included

  • Full agent implementation using OpenAI SDK pointed at Perplexity's /v1/responses endpoint
  • MCP tool integration with Mail and Calendar servers
  • Multi-turn tool-call loop with automatic argument enrichment and auto-finalize for incomplete workflows
  • Retry with exponential backoff + jitter on transient MCP errors (502/503/504)
  • MCP session caching across turns with automatic cache invalidation on failures
  • Observability scopes (InvokeAgentScope + InferenceScope) and token caching
  • Email and Word comment notification handlers
  • Typing indicators, install/uninstall handling, per-turn client cleanup
  • Comprehensive README with Quick Start, Playground testing, deployment (Azure/GCP), and troubleshooting

Files

File Purpose
main.py Entry point, observability config, shutdown handler
hosting.py Message routing, typing indicators, notifications
agent.py Perplexity orchestration, MCP tool discovery, system prompt
perplexity_client.py Agent API wrapper, tool loop, enrichment, auto-finalize
mcp_tool_registration_service.py MCP JSON-RPC client, schema sanitization, retry logic
agent_interface.py Abstract base class
token_cache.py Observability token cache
ToolingManifest.json MCP server declarations (Mail, Calendar)
pyproject.toml Dependencies
.env.template Environment variable reference
README.md Full documentation

@Yogeshp-MSFT Yogeshp-MSFT requested a review from a team as a code owner April 14, 2026 11:38
Copilot AI review requested due to automatic review settings April 14, 2026 11:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a Python Perplexity-based sample agent using the Microsoft Agent 365 SDK, including MCP tool integration, observability, notifications, and end-to-end setup documentation.

Changes:

  • Introduces a Perplexity Responses API client with a multi-turn tool-call loop, argument enrichment, and auto-finalize behavior.
  • Adds MCP server discovery + lightweight JSON-RPC client with retry/backoff and session caching across turns.
  • Provides runnable aiohttp hosting, observability token caching, and comprehensive documentation + environment/dependency setup.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
python/perplexity/sample-agent/token_cache.py Adds a simple in-memory cache for observability exporter tokens.
python/perplexity/sample-agent/pyproject.toml Defines dependencies and uv configuration for the sample agent.
python/perplexity/sample-agent/perplexity_client.py Implements Perplexity Responses API wrapper and tool-call orchestration loop.
python/perplexity/sample-agent/mcp_tool_registration_service.py Implements MCP server discovery, schema sanitization, caching, and retrying tool executor.
python/perplexity/sample-agent/main.py Adds server entry point, auth middleware setup, health endpoints, and observability config.
python/perplexity/sample-agent/hosting.py Adds message routing, typing indicators, token exchange/caching, and notification handlers.
python/perplexity/sample-agent/agent_interface.py Defines the async agent interface used by the hosting layer.
python/perplexity/sample-agent/agent.py Orchestrates Perplexity calls, MCP tool wiring, and observability scopes.
python/perplexity/sample-agent/ToolingManifest.json Declares default MCP servers (Mail, Calendar).
python/perplexity/sample-agent/README.md Adds Quick Start, Playground testing, deployment, and troubleshooting docs.
python/perplexity/sample-agent/.gitignore Ignores local secrets, venv, and generated deployment artifacts.
python/perplexity/sample-agent/.env.template Documents required environment variables for local and production use.

Comment thread python/perplexity/sample-agent/mcp_tool_registration_service.py
Comment thread python/perplexity/sample-agent/mcp_tool_registration_service.py
Comment thread python/perplexity/sample-agent/perplexity_client.py Outdated
Comment thread python/perplexity/sample-agent/perplexity_client.py Outdated
Comment thread python/perplexity/sample-agent/hosting.py Outdated
Comment thread python/perplexity/sample-agent/agent_interface.py
Comment thread python/perplexity/sample-agent/pyproject.toml
@Yogeshp-MSFT Yogeshp-MSFT force-pushed the Perplexity-Python-Sample branch 2 times, most recently from 66e1b25 to 39db110 Compare April 20, 2026 05:20
@Yogeshp-MSFT
Copy link
Copy Markdown
Author

Hi @gwharris7 can you review this pr?

@Yogeshp-MSFT
Copy link
Copy Markdown
Author

HI @biswapm can you review this pr?

@Yogeshp-MSFT Yogeshp-MSFT force-pushed the Perplexity-Python-Sample branch from c5b19d0 to 3b2f429 Compare April 29, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants