|
| 1 | +# Copyright (c) Microsoft. All rights reserved. |
| 2 | + |
| 3 | +import asyncio |
| 4 | + |
| 5 | +from semantic_kernel.agents import ChatCompletionAgent, ChatHistoryAgentThread |
| 6 | +from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion |
| 7 | +from semantic_kernel.connectors.mcp import MCPStdioPlugin |
| 8 | + |
| 9 | +""" |
| 10 | +The following sample demonstrates how to create a chat completion agent that |
| 11 | +answers questions about Github using a Semantic Kernel Plugin from a MCP server. |
| 12 | +The Chat Completion Service is passed directly via the ChatCompletionAgent constructor. |
| 13 | +Additionally, the plugin is supplied via the constructor. |
| 14 | +""" |
| 15 | + |
| 16 | + |
| 17 | +# Simulate a conversation with the agent |
| 18 | +USER_INPUTS = [ |
| 19 | + "What are the latest 5 python issues in Microsoft/semantic-kernel?", |
| 20 | + "Are there any untriaged python issues?", |
| 21 | + "What is the status of issue #10785?", |
| 22 | +] |
| 23 | + |
| 24 | + |
| 25 | +async def main(): |
| 26 | + # 1. Create the agent |
| 27 | + async with MCPStdioPlugin( |
| 28 | + name="Github", |
| 29 | + description="Github Plugin", |
| 30 | + command="npx", |
| 31 | + args=["-y", "@modelcontextprotocol/server-github"], |
| 32 | + ) as github_plugin: |
| 33 | + agent = ChatCompletionAgent( |
| 34 | + service=AzureChatCompletion(), |
| 35 | + name="IssueAgent", |
| 36 | + instructions="Answer questions about the Microsoft semantic-kernel github project.", |
| 37 | + plugins=[github_plugin], |
| 38 | + ) |
| 39 | + |
| 40 | + for user_input in USER_INPUTS: |
| 41 | + # 2. Create a thread to hold the conversation |
| 42 | + # If no thread is provided, a new thread will be |
| 43 | + # created and returned with the initial response |
| 44 | + thread: ChatHistoryAgentThread = None |
| 45 | + |
| 46 | + print(f"# User: {user_input}") |
| 47 | + # 3. Invoke the agent for a response |
| 48 | + response = await agent.get_response(messages=user_input, thread=thread) |
| 49 | + print(f"# {response.name}: {response} ") |
| 50 | + thread = response.thread |
| 51 | + |
| 52 | + # 4. Cleanup: Clear the thread |
| 53 | + await thread.delete() if thread else None |
| 54 | + |
| 55 | + """ |
| 56 | + Sample output: |
| 57 | +GitHub MCP Server running on stdio |
| 58 | +# User: What are the latest 5 python issues in Microsoft/semantic-kernel? |
| 59 | +# IssueAgent: Here are the latest 5 Python issues in the |
| 60 | +[Microsoft/semantic-kernel](https://github.com/microsoft/semantic-kernel) repository: |
| 61 | +
|
| 62 | +1. **[Issue #11358](https://github.com/microsoft/semantic-kernel/pull/11358)** |
| 63 | + **Title:** Python: Bump Python version to 1.27.0 for a release. |
| 64 | + **Created by:** [moonbox3](https://github.com/moonbox3) |
| 65 | + **Created at:** April 3, 2025 |
| 66 | + **State:** Open |
| 67 | + **Comments:** 1 |
| 68 | + **Description:** Bump Python version to 1.27.0 for a release. |
| 69 | +
|
| 70 | +2. **[Issue #11357](https://github.com/microsoft/semantic-kernel/pull/11357)** |
| 71 | + **Title:** .Net: Version 1.45.0 |
| 72 | + **Created by:** [markwallace-microsoft](https://github.com/markwallace-microsoft) |
| 73 | + **Created at:** April 3, 2025 |
| 74 | + **State:** Open |
| 75 | + **Comments:** 0 |
| 76 | + **Description:** Version bump for release 1.45.0. |
| 77 | +
|
| 78 | +3. **[Issue #11356](https://github.com/microsoft/semantic-kernel/pull/11356)** |
| 79 | + **Title:** .Net: Fix bug in sqlite filter logic |
| 80 | + **Created by:** [westey-m](https://github.com/westey-m) |
| 81 | + **Created at:** April 3, 2025 |
| 82 | + **State:** Open |
| 83 | + **Comments:** 0 |
| 84 | + **Description:** Fix bug in sqlite filter logic. |
| 85 | +
|
| 86 | +4. **[Issue #11355](https://github.com/microsoft/semantic-kernel/issues/11355)** |
| 87 | + **Title:** .Net: [MEVD] Validate that the collection generic key parameter corresponds to the model |
| 88 | + **Created by:** [roji](https://github.com/roji) |
| 89 | + **Created at:** April 3, 2025 |
| 90 | + **State:** Open |
| 91 | + **Comments:** 0 |
| 92 | + **Description:** We currently have validation for the TKey generic type parameter passed to the collection type, |
| 93 | + and we have validation for the key property type on the model. |
| 94 | +
|
| 95 | +5. **[Issue #11354](https://github.com/microsoft/semantic-kernel/issues/11354)** |
| 96 | + **Title:** .Net: How to add custom JsonSerializer on a builder level |
| 97 | + **Created by:** [PawelStadnicki](https://github.com/PawelStadnicki) |
| 98 | + **Created at:** April 3, 2025 |
| 99 | + **State:** Open |
| 100 | + **Comments:** 0 |
| 101 | + **Description:** Inquiry about adding a custom JsonSerializer for handling F# types within the SDK. |
| 102 | +
|
| 103 | +If you need more details about a specific issue, let me know! |
| 104 | +# User: Are there any untriaged python issues? |
| 105 | +# IssueAgent: There are no untriaged Python issues in the Microsoft semantic-kernel repository. |
| 106 | +# User: What is the status of issue #10785? |
| 107 | +# IssueAgent: The status of issue #10785 in the Microsoft Semantic Kernel repository is **open**. |
| 108 | +
|
| 109 | +- **Title**: Port dotnet feature: Create MCP Sample |
| 110 | +- **Created at**: March 4, 2025 |
| 111 | +- **Comments**: 0 |
| 112 | +- **Labels**: python |
| 113 | +
|
| 114 | +You can view the issue [here](https://github.com/microsoft/semantic-kernel/issues/10785). |
| 115 | + """ |
| 116 | + |
| 117 | + |
| 118 | +if __name__ == "__main__": |
| 119 | + asyncio.run(main()) |
0 commit comments