Skip to content

feat: Add Python Semantic Kernel sample agent#280

Open
Yogeshp-MSFT wants to merge 1 commit intomicrosoft:mainfrom
Yogeshp-MSFT:SemanticKernel-Python-Sample
Open

feat: Add Python Semantic Kernel sample agent#280
Yogeshp-MSFT wants to merge 1 commit intomicrosoft:mainfrom
Yogeshp-MSFT:SemanticKernel-Python-Sample

Conversation

@Yogeshp-MSFT
Copy link
Copy Markdown

Adds a new Python sample demonstrating how to build a production-ready Microsoft 365 agent using Semantic Kernel with the Microsoft Agent 365 SDK. This is the Python counterpart to the existing .NET Semantic Kernel sample (dotnet/semantic-kernel/).

What's included

New directory: python/semantic-kernel/sample-agent/

File Purpose
agent.py Core agent implementation using ChatCompletionAgent with FunctionChoiceBehavior.Auto()
host_agent_server.py Generic aiohttp hosting server following the shared A365 host pattern
start_with_generic_host.py Entry point
agent_interface.py Abstract base class for agent implementations
mcp_tool_registration_service.py MCP server discovery and Semantic Kernel plugin registration
observability_config.py A365 observability initialization with token resolver
turn_context_utils.py TurnContext extraction and BaggageBuilder utilities
token_cache.py In-memory token caching for auth flows
local_authentication_options.py Environment-based auth configuration
ToolingManifest.json MCP server manifest (fallback for SDK discovery)
.env.template Environment variable reference
pyproject.toml Project configuration with all dependencies
README.md Full documentation with Quick Start, architecture, troubleshooting

Features

  • Dual LLM support — Azure OpenAI or OpenAI via API key, configurable via USE_AZURE_OPENAI env var
  • MCP tool integration — Auto-discovered tools via SDK with ToolingManifest.json fallback; connection caching across turns
  • Agentic authentication — Token exchange for Graph API, MCP servers, and observability; Playground mode with AUTH_HANDLER_NAME= (empty)
  • Full observability — Nested InvokeAgentScopeInferenceScopeExecuteToolScope with BaggageBuilder context propagation
  • Notification handling — Email and Word comment notification processing
  • Conversation continuity — Per-conversation ChatHistory maintained across turns
  • Multiple messages + typing indicators — Immediate acknowledgment, background typing loop, final response
  • Generic host pattern — Reusable GenericAgentHost compatible with Agents Playground, matching the pattern used by other Python samples
  • Proper resource cleanup — Graceful shutdown via app.on_shutdown, MCP plugin close, AI service client close, token cache clear

Dependencies

  • semantic-kernel>=1.15.0
  • microsoft-agents-hosting-aiohttp>=0.7.0
  • microsoft-agents-a365-tooling>=0.1.0
  • microsoft-agents-a365-observability-core>=0.1.0
  • microsoft-agents-a365-notifications>=0.1.0
  • microsoft-agents-a365-runtime>=0.1.0

Full list in pyproject.toml.

Testing

  • Verified with Agents Playground (Playground mode, AUTH_HANDLER_NAME= empty)
  • Tested MCP tool invocation (mail send via mcp_MailTools)
  • Tested both OpenAI and Azure OpenAI LLM paths
  • Observability spans visible in console output

Related samples

This follows the same architecture and conventions as:

  • python/claude/sample-agent/
  • python/openai/sample-agent/
  • dotnet/semantic-kernel/sample-agent/ (the .NET equivalent)

Copilot AI review requested due to automatic review settings April 22, 2026 10:39
@Yogeshp-MSFT Yogeshp-MSFT requested a review from a team as a code owner April 22, 2026 10:39
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

Adds a new Python Semantic Kernel sample agent under python/semantic-kernel/sample-agent/, intended to mirror the existing .NET SK sample and follow the shared Agent 365 “generic host” pattern (MCP tooling, notifications, and observability).

Changes:

  • Introduces a Semantic Kernel-based agent (ChatCompletionAgent) with MCP tool discovery/registration and notification handling.
  • Adds a reusable aiohttp generic host server with optional JWT auth and notification wiring.
  • Provides sample packaging/config/docs (pyproject.toml, .env.template, ToolingManifest.json, README.md) for running in Playground and production modes.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
python/semantic-kernel/sample-agent/agent.py Implements the Semantic Kernel agent (LLM config, MCP tools, observability scopes, notifications, cleanup).
python/semantic-kernel/sample-agent/agent_interface.py Defines the async interface required by the generic host.
python/semantic-kernel/sample-agent/host_agent_server.py Generic aiohttp host wiring: auth, message handling, typing indicators, notifications, shutdown cleanup.
python/semantic-kernel/sample-agent/mcp_tool_registration_service.py MCP server discovery via SDK and SK plugin registration, with a manual MCP JSON-RPC fallback.
python/semantic-kernel/sample-agent/observability_config.py Module-level one-time initialization of the A365 observability SDK.
python/semantic-kernel/sample-agent/turn_context_utils.py Helpers to extract TurnContext details and build baggage for observability.
python/semantic-kernel/sample-agent/token_cache.py In-memory cache for agentic tokens used by the observability exporter.
python/semantic-kernel/sample-agent/local_authentication_options.py Loads local auth-related settings from environment variables.
python/semantic-kernel/sample-agent/start_with_generic_host.py CLI entrypoint to run the agent with the generic host.
python/semantic-kernel/sample-agent/pyproject.toml Declares dependencies and build config for the sample.
python/semantic-kernel/sample-agent/ToolingManifest.json MCP server fallback manifest for tool discovery.
python/semantic-kernel/sample-agent/.env.template Environment variable template for LLM/auth/tooling/observability configuration.
python/semantic-kernel/sample-agent/README.md End-to-end sample documentation (setup, architecture, troubleshooting).

Comment thread python/semantic-kernel/sample-agent/agent.py
Comment thread python/semantic-kernel/sample-agent/agent.py
Comment thread python/semantic-kernel/sample-agent/README.md
@Yogeshp-MSFT
Copy link
Copy Markdown
Author

Hi @biswapm can you review this pr?

@Yogeshp-MSFT Yogeshp-MSFT force-pushed the SemanticKernel-Python-Sample branch from 56f69ec to 8ce3c8e Compare April 29, 2026 10:41
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