|
| 1 | +# Copyright (c) Microsoft. All rights reserved. |
| 2 | + |
| 3 | +import asyncio |
| 4 | +import logging |
| 5 | +import os |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | +from semantic_kernel.agents import ChatCompletionAgent |
| 9 | +from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion |
| 10 | +from semantic_kernel.connectors.mcp import MCPStdioPlugin |
| 11 | + |
| 12 | +# set this lower or higher depending on your needs |
| 13 | +logging.basicConfig(level=logging.INFO) |
| 14 | +logger = logging.getLogger(__name__) |
| 15 | + |
| 16 | +""" |
| 17 | +The following sample demonstrates how to use a MCP Server that requires sampling |
| 18 | +to generate release notes from a list of issues. |
| 19 | +
|
| 20 | +It uses the OpenAI service to create a agent, so make sure to |
| 21 | +set the required environment variables for the Azure AI Foundry service: |
| 22 | +- OPENAI_API_KEY |
| 23 | +- OPENAI_CHAT_MODEL_ID |
| 24 | +""" |
| 25 | + |
| 26 | +PR_MESSAGES = """* Python: Add ChatCompletionAgent integration tests by @moonbox3 in https://github.com/microsoft/semantic-kernel/pull/11430 |
| 27 | +* Python: Update Doc Gen demo based on latest agent invocation api pattern by @moonbox3 in https://github.com/microsoft/semantic-kernel/pull/11426 |
| 28 | +* Python: Update Python min version in README by @moonbox3 in https://github.com/microsoft/semantic-kernel/pull/11428 |
| 29 | +* Python: Fix `TypeError` when required is missing in MCP tool’s inputSchema by @KanchiShimono in https://github.com/microsoft/semantic-kernel/pull/11458 |
| 30 | +* Python: Update chromadb requirement from <0.7,>=0.5 to >=0.5,<1.1 in /python by @dependabot in https://github.com/microsoft/semantic-kernel/pull/11420 |
| 31 | +* Python: Bump google-cloud-aiplatform from 1.86.0 to 1.87.0 in /python by @dependabot in https://github.com/microsoft/semantic-kernel/pull/11423 |
| 32 | +* Python: Support Auto Function Invocation Filter for AzureAIAgent and OpenAIAssistantAgent by @moonbox3 in https://github.com/microsoft/semantic-kernel/pull/11460 |
| 33 | +* Python: Improve agent integration tests by @moonbox3 in https://github.com/microsoft/semantic-kernel/pull/11475 |
| 34 | +* Python: Allow Kernel Functions from Prompt for image and audio content by @eavanvalkenburg in https://github.com/microsoft/semantic-kernel/pull/11403 |
| 35 | +* Python: Introducing SK as a MCP Server by @eavanvalkenburg in https://github.com/microsoft/semantic-kernel/pull/11362 |
| 36 | +* Python: sample using GitHub MCP Server and Azure AI Agent by @eavanvalkenburg in https://github.com/microsoft/semantic-kernel/pull/11465 |
| 37 | +* Python: allow settings to be created directly by @eavanvalkenburg in https://github.com/microsoft/semantic-kernel/pull/11468 |
| 38 | +* Python: Bug fix for azure ai agent truncate strategy. Add sample. by @moonbox3 in https://github.com/microsoft/semantic-kernel/pull/11503 |
| 39 | +* Python: small code improvements in code of call automation sample by @eavanvalkenburg in https://github.com/microsoft/semantic-kernel/pull/11477 |
| 40 | +* Added missing import asyncio to agent with plugin python by @sphenry in https://github.com/microsoft/semantic-kernel/pull/11472 |
| 41 | +* Python: version updated to 1.28.0 by @eavanvalkenburg in https://github.com/microsoft/semantic-kernel/pull/11504""" |
| 42 | + |
| 43 | + |
| 44 | +async def main(): |
| 45 | + # 1. Create the agent |
| 46 | + async with MCPStdioPlugin( |
| 47 | + name="ReleaseNotes", |
| 48 | + description="SK Release Notes Plugin", |
| 49 | + command="uv", |
| 50 | + args=[ |
| 51 | + f"--directory={str(Path(os.path.dirname(__file__)).parent.parent.joinpath('demos', 'sk_mcp_server'))}", |
| 52 | + "run", |
| 53 | + "mcp_server_with_sampling.py", |
| 54 | + ], |
| 55 | + ) as plugin: |
| 56 | + agent = ChatCompletionAgent( |
| 57 | + service=OpenAIChatCompletion(), |
| 58 | + name="IssueAgent", |
| 59 | + instructions="For the messages supplied, call the release_notes_prompt function to get the broader " |
| 60 | + "prompt, then call the run_prompt function to get the final output, return that without any other text." |
| 61 | + "Do not add any other text to the output, or rewrite the output from run_prompt.", |
| 62 | + plugins=[plugin], |
| 63 | + ) |
| 64 | + |
| 65 | + print(f"# Task: {PR_MESSAGES}") |
| 66 | + # 3. Invoke the agent for a response |
| 67 | + response = await agent.get_response(messages=PR_MESSAGES) |
| 68 | + print(str(response)) |
| 69 | + |
| 70 | + # 4. Cleanup: Clear the thread |
| 71 | + await response.thread.delete() |
| 72 | + |
| 73 | + """ |
| 74 | +# Task: * Python: Add ChatCompletionAgent integration tests by @moonbox3 in https://github.com/microsoft/semantic-kernel/pull/11430 |
| 75 | +* Python: Update Doc Gen demo based on latest agent invocation api pattern by @moonbox3 in https://github.com/microsoft/semantic-kernel/pull/11426 |
| 76 | +* Python: Update Python min version in README by @moonbox3 in https://github.com/microsoft/semantic-kernel/pull/11428 |
| 77 | +* Python: Fix `TypeError` when required is missing in MCP tool’s inputSchema by @KanchiShimono in https://github.com/microsoft/semantic-kernel/pull/11458 |
| 78 | +* Python: Update chromadb requirement from <0.7,>=0.5 to >=0.5,<1.1 in /python by @dependabot in https://github.com/microsoft/semantic-kernel/pull/11420 |
| 79 | +* Python: Bump google-cloud-aiplatform from 1.86.0 to 1.87.0 in /python by @dependabot in https://github.com/microsoft/semantic-kernel/pull/11423 |
| 80 | +* Python: Support Auto Function Invocation Filter for AzureAIAgent and OpenAIAssistantAgent by @moonbox3 in https://github.com/microsoft/semantic-kernel/pull/11460 |
| 81 | +* Python: Improve agent integration tests by @moonbox3 in https://github.com/microsoft/semantic-kernel/pull/11475 |
| 82 | +* Python: Allow Kernel Functions from Prompt for image and audio content by @eavanvalkenburg in https://github.com/microsoft/semantic-kernel/pull/11403 |
| 83 | +* Python: Introducing SK as a MCP Server by @eavanvalkenburg in https://github.com/microsoft/semantic-kernel/pull/11362 |
| 84 | +* Python: sample using GitHub MCP Server and Azure AI Agent by @eavanvalkenburg in https://github.com/microsoft/semantic-kernel/pull/11465 |
| 85 | +* Python: allow settings to be created directly by @eavanvalkenburg in https://github.com/microsoft/semantic-kernel/pull/11468 |
| 86 | +* Python: Bug fix for azure ai agent truncate strategy. Add sample. by @moonbox3 in https://github.com/microsoft/semantic-kernel/pull/11503 |
| 87 | +* Python: small code improvements in code of call automation sample by @eavanvalkenburg in https://github.com/microsoft/semantic-kernel/pull/11477 |
| 88 | +* Added missing import asyncio to agent with plugin python by @sphenry in https://github.com/microsoft/semantic-kernel/pull/11472 |
| 89 | +* Python: version updated to 1.28.0 by @eavanvalkenburg in https://github.com/microsoft/semantic-kernel/pull/11504 |
| 90 | +
|
| 91 | +Here’s a summary of the recent changes and contributions made to the Microsoft Semantic Kernel repository: |
| 92 | +
|
| 93 | +1. **Integration Tests**: |
| 94 | + - Added integration tests for `ChatCompletionAgent` by @moonbox3 ([PR #11430](https://github.com/microsoft/semantic-kernel/pull/11430)). |
| 95 | + - Improved agent integration tests by @moonbox3 ([PR #11475](https://github.com/microsoft/semantic-kernel/pull/11475)). |
| 96 | +
|
| 97 | +2. **Documentation and Demos**: |
| 98 | + - Updated the Doc Gen demo to align with the latest agent invocation API pattern by @moonbox3 ([PR #11426](https://github.com/microsoft/semantic-kernel/pull/11426)). |
| 99 | + - Small code improvements made in the code of the call automation sample by @eavanvalkenburg ([PR #11477](https://github.com/microsoft/semantic-kernel/pull/11477)). |
| 100 | +
|
| 101 | +3. **Version Updates**: |
| 102 | + - Updated the minimum Python version in the README by @moonbox3 ([PR #11428](https://github.com/microsoft/semantic-kernel/pull/11428)). |
| 103 | + - Updated `chromadb` requirement to allow versions >=0.5 and <1.1 by @dependabot ([PR #11420](https://github.com/microsoft/semantic-kernel/pull/11420)). |
| 104 | + - Bumped `google-cloud-aiplatform` from 1.86.0 to 1.87.0 by @dependabot ([PR #11423](https://github.com/microsoft/semantic-kernel/pull/11423)). |
| 105 | + - Version updated to 1.28.0 by @eavanvalkenburg ([PR #11504](https://github.com/microsoft/semantic-kernel/pull/11504)). |
| 106 | +
|
| 107 | +4. **Bug Fixes**: |
| 108 | + - Fixed a `TypeError` in the MCP tool’s input schema when the required field is missing by @KanchiShimono ([PR #11458](https://github.com/microsoft/semantic-kernel/pull/11458)). |
| 109 | + - Bug fix for Azure AI agent truncate strategy with an added sample by @moonbox3 ([PR #11503](https://github.com/microsoft/semantic-kernel/pull/11503)). |
| 110 | + - Added a missing import for `asyncio` in the agent with plugin Python by @sphenry ([PR #11472](https://github.com/microsoft/semantic-kernel/pull/11472)). |
| 111 | + """ |
| 112 | + |
| 113 | + |
| 114 | +if __name__ == "__main__": |
| 115 | + asyncio.run(main()) |
0 commit comments