Skip to content

Commit 8405014

Browse files
authored
Merge branch 'Azure-Samples:main' into main
2 parents 7e19ef6 + 1c1175d commit 8405014

File tree

71 files changed

+10484
-68
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+10484
-68
lines changed

.github/CODEOWNERS

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,20 @@
44

55
# Default owner for everything, unless overridden by a more specific rule.
66
* @Azure-Samples/azure-ai-samples-maintainers
7+
8+
9+
#### files referenced in docs (DO NOT EDIT, except for Docs team!!!) ###################
10+
/scenarios/projects/basic/chat-simple.py @azure-samples/AI-Platform-Docs
11+
/scenarios/projects/basic/chat-template.py @azure-samples/AI-Platform-Docs
12+
/scenarios/rag/custom-rag-app/assets/chat_eval_data.jsonl @azure-samples/AI-Platform-Docs
13+
/scenarios/rag/custom-rag-app/assets/grounded_chat.prompty @azure-samples/AI-Platform-Docs
14+
/scenarios/rag/custom-rag-app/assets/intent_mapping.prompty @azure-samples/AI-Platform-Docs
15+
/scenarios/rag/custom-rag-app/assets/products.csv @azure-samples/AI-Platform-Docs
16+
/scenarios/rag/custom-rag-app/chat_with_products.py @azure-samples/AI-Platform-Docs
17+
/scenarios/rag/custom-rag-app/config.py @azure-samples/AI-Platform-Docs
18+
/scenarios/rag/custom-rag-app/create_search_index.py @azure-samples/AI-Platform-Docs
19+
/scenarios/rag/custom-rag-app/evaluate.py @azure-samples/AI-Platform-Docs
20+
/scenarios/rag/custom-rag-app/get_product_documents.py @azure-samples/AI-Platform-Docs
21+
/scenarios/rag/custom-rag-app/requirements.txt @azure-samples/AI-Platform-Docs
22+
/scenarios/langchain/getting-started-with-langchain-chat-models.ipynb @azure-samples/AI-Platform-Docs
23+
/scenarios/langchain/getting-started-with-langchain-embeddings.ipynb @azure-samples/AI-Platform-Docs

.github/scripts/build_agent_setup_bicep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def run_az_command(*args: Union[str, Path]) -> None:
1616
sys.exit(exit_code)
1717

1818

19-
def get_main_bicep_files(modified_files: List[str]) -> List[Path]:
19+
def get_main_bicep_files(modified_files: List[Path]) -> List[Path]:
2020
"""Finds unique folders with modified files and ensures 'main.bicep' exists in each."""
2121
modified_folders = {Path(f).parent for f in modified_files}
2222
return [folder / "main.bicep" for folder in modified_folders if (folder / "main.bicep").exists()]

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repos:
1515
language: system
1616
types_or: [jupyter]
1717
minimum_pre_commit_version: 2.9.2
18-
args: ["-m", "tox", "-qqq", "run", "-e", "nb-clean", "--", "clean", "--preserve-cell-metadata", "tags", "--"]
18+
args: ["-m", "tox", "-qqq", "run", "-e", "nb-clean", "--", "clean", "--preserve-cell-metadata", "tags", "name", "--"]
1919
- id: ruff
2020
name: ruff
2121
description: "Run 'ruff' for extremely fast Python linting"

scenarios/Agents/README.md

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
AZURE_AI_AGENT_PROJECT_CONNECTION_STRING=...
2+
AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME=...
3+
GITHUB_PERSONAL_ACCESS_TOKEN=...
4+
MCP_SERVER_URL=...
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Using MCP Servers with Azure AI Foundry Agent service and Semantic Kernel
2+
3+
Semantic Kernel has been deeply integrated with the agent service and allows you to easily add additional tools to your Agent.
4+
The Model Context Protocol (MCP) is a protocol for exposing tools and other context to models. Semantic Kernel has built-in support for all types of MCP Servers and after reading the definition, it exposes the tools and prompts of the MCP server to the agent that consumes them.
5+
6+
## Setup
7+
8+
1. Install [uv](https://docs.astral.sh/uv/getting-started/installation/) and optionally [docker](https://www.docker.com/products/docker-desktop/)
9+
1. Ensure you have your Azure AI Foundry Hub and Agent setup done, see [here](../README.md), and add the project connection string and model deployment name to a .env file (or copy the .env.example), with the following names:
10+
- AZURE_AI_AGENT_PROJECT_CONNECTION_STRING
11+
- AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME
12+
1. If you want to run the Stdio Server sample: Create a Personal Access Token for Github that has read access to the repositories that you want to interact with, see [the documentation](https://github.com/modelcontextprotocol/servers/tree/main/src/github) on how to create one.
13+
1. If you want to run the Sse Server sample: add the URL of the MCP server to the .env file, under the `MCP_SERVER_URL` variable.
14+
1. Navigate into this folder and call `uv run agent_with_stdio_server.py` or `uv run agent_with_sse_server.py` this will automatically create a venv with the required packages installed.
15+
16+
> You can also run the samples with python, just make sure to check the required dependencies in the pyproject.toml file.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Copyright (c) Microsoft. All rights reserved.
2+
3+
import asyncio
4+
import os
5+
from dotenv import load_dotenv
6+
7+
from azure.identity.aio import DefaultAzureCredential
8+
9+
from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings, AzureAIAgentThread
10+
from semantic_kernel.connectors.mcp import MCPSsePlugin
11+
12+
"""
13+
The following sample demonstrates how to create a AzureAIAgent that
14+
uses a SSE based MCP server to add context to the Agent.
15+
16+
It uses the Azure AI Foundry Agent service to create a agent, so make sure to
17+
set the required environment variables for the Azure AI Foundry service:
18+
- AZURE_AI_AGENT_PROJECT_CONNECTION_STRING
19+
- AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME
20+
"""
21+
22+
load_dotenv()
23+
24+
25+
async def main() -> None:
26+
"""Main function that creates the plugin, the agent and starts the conversation loop."""
27+
async with (
28+
# 1. Login to Azure and create a Azure AI Project Client
29+
DefaultAzureCredential() as creds,
30+
AzureAIAgent.create_client(credential=creds) as client,
31+
# 2. Create the MCP plugin
32+
MCPSsePlugin(
33+
name="mcp",
34+
description="MCP Plugin",
35+
url=os.getenv("MCP_SERVER_URL"),
36+
) as plugin,
37+
):
38+
# 3. Create the agent, with the MCP plugin and the thread
39+
agent = AzureAIAgent(
40+
client=client,
41+
definition=await client.agents.create_agent(
42+
model=AzureAIAgentSettings.create().model_deployment_name,
43+
name="GithubAgent",
44+
instructions="You are a microsoft/semantic-kernel Issue Triage Agent. "
45+
"You look at all issues that have the tag: 'triage' and 'python'."
46+
"When you find one that is untriaged, you will suggest a new assignee "
47+
"based on the issue description, look at recent closed PR's for issues in the same area. "
48+
"You will also suggest additional context if needed, like related issues or a bug fix. ",
49+
),
50+
plugins=[plugin], # add the sample plugin to the agent
51+
)
52+
thread: AzureAIAgentThread | None = None
53+
# 4. Print instructions and set the initial user input
54+
print("Starting Azure AI Agent with MCP Plugin sample...")
55+
print("Once the first prompt is answered, you can further ask questions, use `exit` to exit.")
56+
user_input = input("# User: ")
57+
try:
58+
while user_input.lower() != "exit":
59+
# 5. Invoke the agent for a response
60+
response = await agent.get_response(messages=user_input, thread=thread)
61+
print(f"# {response.name}: {response} ")
62+
thread = response.thread
63+
# 6. Get a new user input
64+
user_input = input("# User: ")
65+
finally:
66+
# 7. Cleanup: Clear the thread
67+
await thread.delete() if thread else None
68+
await client.agents.delete_agent(agent.definition.id)
69+
70+
71+
if __name__ == "__main__":
72+
asyncio.run(main())
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Copyright (c) Microsoft. All rights reserved.
2+
3+
import asyncio
4+
import os
5+
from dotenv import load_dotenv
6+
7+
from azure.identity.aio import DefaultAzureCredential
8+
9+
from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings, AzureAIAgentThread
10+
from semantic_kernel.connectors.mcp import MCPStdioPlugin
11+
12+
"""
13+
The following sample demonstrates how to create a AzureAIAgent that
14+
answers questions about Github using a Semantic Kernel Plugin from a MCP server.
15+
16+
It uses the Azure AI Foundry Agent service to create a agent, so make sure to
17+
set the required environment variables for the Azure AI Foundry service:
18+
- AZURE_AI_AGENT_PROJECT_CONNECTION_STRING
19+
- AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME
20+
"""
21+
22+
load_dotenv()
23+
24+
25+
async def main() -> None:
26+
"""Main function that creates the plugin, the agent and starts the conversation loop."""
27+
async with (
28+
# 1. Login to Azure and create a Azure AI Project Client
29+
DefaultAzureCredential() as creds,
30+
AzureAIAgent.create_client(credential=creds) as client,
31+
# 2. Create the MCP plugin
32+
MCPStdioPlugin(
33+
name="github",
34+
description="Github Plugin",
35+
command="docker",
36+
args=["run", "-i", "--rm", "-e", "GITHUB_PERSONAL_ACCESS_TOKEN", "ghcr.io/github/github-mcp-server"],
37+
env={"GITHUB_PERSONAL_ACCESS_TOKEN": os.getenv("GITHUB_PERSONAL_ACCESS_TOKEN")},
38+
) as github_plugin,
39+
):
40+
# 3. Create the agent, with the MCP plugin and the thread
41+
agent = AzureAIAgent(
42+
client=client,
43+
definition=await client.agents.create_agent(
44+
model=AzureAIAgentSettings.create().model_deployment_name,
45+
name="GithubAgent",
46+
instructions="You are a microsoft/semantic-kernel Issue Triage Agent. "
47+
"You look at all issues that have the tag: 'triage' and 'python'."
48+
"When you find one that is untriaged, you will suggest a new assignee "
49+
"based on the issue description, look at recent closed PR's for issues in the same area. "
50+
"You will also suggest additional context if needed, like related issues or a bug fix. ",
51+
),
52+
plugins=[github_plugin], # add the sample plugin to the agent
53+
)
54+
thread: AzureAIAgentThread | None = None
55+
# 4. Print instructions and set the initial user input
56+
print("Starting Azure AI Agent with MCP Plugin sample...")
57+
print("Once the first prompt is answered, you can further ask questions, use `exit` to exit.")
58+
user_input = "Find the latest untriaged, unassigned issues and suggest new assignees."
59+
print(f"# User: {user_input}")
60+
try:
61+
while user_input.lower() != "exit":
62+
# 5. Invoke the agent for a response
63+
response = await agent.get_response(messages=user_input, thread=thread)
64+
print(f"# {response.name}: {response} ")
65+
thread = response.thread
66+
# 6. Get a new user input
67+
user_input = input("# User: ")
68+
finally:
69+
# 7. Cleanup: Clear the thread
70+
await thread.delete() if thread else None
71+
await client.agents.delete_agent(agent.definition.id)
72+
73+
"""
74+
Sample output:
75+
GitHub MCP Server running on stdio
76+
Starting Azure AI Agent with MCP Plugin sample...
77+
Once the first prompt is answered, you can further ask questions, use `exit` to exit.
78+
# User: Find the latest untriaged, unassigned issues and suggest new assignees.
79+
# GithubAgent: Here are the latest untriaged and unassigned issues that are tagged with Python:
80+
81+
1. **[Issue #11459](https://github.com/microsoft/semantic-kernel/issues/11459)**
82+
- **Title:** Python: Bug: The provided example is incorrect
83+
- **Description:** There are apparent mistakes in the provided Python examples concerning shared and
84+
non-shared stateful configurations.
85+
- **Assignee Suggestion:** Assign to **eavanvalkenburg** based on prior involvement with Python-related code and
86+
recent PRs focusing on bug fixes.
87+
88+
2. **[Issue #11465](https://github.com/microsoft/semantic-kernel/issues/11465)**
89+
- **Title:** Python: sample using GitHub MCP Server and Azure AI Agent
90+
- **Description:** This adds a sample demonstrating how to use MCP tools with the Azure AI Agent.
91+
- **Assignee Suggestion:** Assign to **eavanvalkenburg** who is associated with the issue.
92+
93+
### Summary of Suggested Assignees:
94+
- **Issue #11459**: **eavanvalkenburg**
95+
- **Issue #11465**: **eavanvalkenburg**
96+
97+
It seems that I cannot update the assignees directly due to authentication issues. You can use this information
98+
as you see fit to assign these issues. If you need further assistance or specific context for each issue,
99+
please let me know!
100+
"""
101+
102+
103+
if __name__ == "__main__":
104+
asyncio.run(main())
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[project]
2+
name = "semantic-kernel-mcp"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.12"
7+
dependencies = [
8+
"semantic-kernel[azure,mcp]>=1.28.0",
9+
]
10+
11+
[tool.uv]
12+
prerelease = "allow"

scenarios/Agents/setup/basic-agent-identity/azuredeploy.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"_generator": {
66
"name": "bicep",
77
"version": "0.33.93.31351",
8-
"templateHash": "9343374115382580767"
8+
"templateHash": "3556712594165874979"
99
}
1010
},
1111
"parameters": {
@@ -204,7 +204,7 @@
204204
"_generator": {
205205
"name": "bicep",
206206
"version": "0.33.93.31351",
207-
"templateHash": "13463183484961318850"
207+
"templateHash": "10842040050834008228"
208208
}
209209
},
210210
"parameters": {
@@ -308,9 +308,6 @@
308308
},
309309
"properties": {
310310
"customSubDomainName": "[toLower(format('{0}', toLower(parameters('aiServicesName'))))]",
311-
"apiProperties": {
312-
"statisticsEnabled": false
313-
},
314311
"publicNetworkAccess": "Enabled"
315312
}
316313
},

0 commit comments

Comments
 (0)