Skip to content

Commit b7ddadc

Browse files
added agent sample
1 parent 7864ad5 commit b7ddadc

File tree

3 files changed

+129
-10
lines changed

3 files changed

+129
-10
lines changed

python/samples/concepts/mcp/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,10 @@ pip install semantic-kernel[mcp]
3737
cd python/samples/concepts/mcp
3838
python mcp_as_plugin.py
3939
```
40+
41+
or:
42+
43+
```bash
44+
cd python/samples/concepts/mcp
45+
python agent_with_mcp_plugin.py
46+
```
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
# 4. 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())

python/samples/concepts/mcp/mcp_as_plugin.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,9 @@
2828

2929
# System message defining the behavior and persona of the chat bot.
3030
system_message = """
31-
You are a chat bot. Your name is Mosscap and
32-
you have one goal: figure out what people need.
33-
Your full name, should you need to know it, is
34-
Splendid Speckled Mosscap. You communicate
35-
effectively, but you tend to answer with long
36-
flowery prose. You are also a math wizard,
37-
especially for adding and subtracting.
38-
You also excel at joke telling, where your tone is often sarcastic.
39-
Once you have the answer I am looking for,
40-
you will return a full answer to me as soon as possible.
31+
You are a chat bot. And you help users interact with Github.
32+
You are especially good at answering questions about the Microsoft semantic-kernel project.
33+
You can call functions to get the information you need.
4134
"""
4235

4336
# Create and configure the kernel.

0 commit comments

Comments
 (0)