You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Tutorial: Build an agentic web app in Azure App Service with Microsoft Semantic Kernel or Azure AI Foundry Agent Service (.NET)
16
16
17
-
This tutorial demonstrates how to add agentic capability to an existing data-driven CRUD application. It does this using two different approaches: Microsoft Semantic Kernel and Azure AI Foundry Agent Service.
17
+
This tutorial demonstrates how to add agentic capability to an existing data-driven ASP.NET Core CRUD application. It does this using two different approaches: Microsoft Semantic Kernel and Azure AI Foundry Agent Service.
18
18
19
19
If your web application already has useful features, like shopping, hotel booking, or data management, it's relatively straightforward to add agent functionality to your web application by wrapping those functionalities in a plugin (for Semantic Kernel) or as an OpenAPI endpoint (for AI Foundry Agent Service). In this tutorial, you start with a simple to-do list app. By the end, you'll be able to create, update, and manage tasks with an agent in an App Service app.
Copy file name to clipboardExpand all lines: articles/app-service/tutorial-ai-agent-web-app-semantic-kernel-java.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,9 @@ ms.custom:
12
12
ms.collection: ce-skilling-ai-copilot
13
13
---
14
14
15
-
# Tutorial: Build an agentic web app in Azure App Service with Microsoft Semantic Kernel (Java)
15
+
# Tutorial: Build an agentic web app in Azure App Service with Microsoft Semantic Kernel (Spring Boot)
16
16
17
-
This tutorial demonstrates how to add agentic capability to an existing data-driven CRUD application. It does this using Microsoft Semantic Kernel.
17
+
This tutorial demonstrates how to add agentic capability to an existing data-driven Spring Boot WebFlux CRUD application. It does this using Microsoft Semantic Kernel.
18
18
19
19
If your web application already has useful features, like shopping, hotel booking, or data management, it's relatively straightforward to add agent functionality to your web application by wrapping those functionalities in a plugin (for Semantic Kernel). In this tutorial, you start with a simple to-do list app. By the end, you'll be able to create, update, and manage tasks with an agent in an App Service app.
20
20
@@ -28,7 +28,7 @@ In this tutorial, you learn how to:
28
28
> [!div class="checklist"]
29
29
> * Convert existing app functionality into a plugin for Semantic Kernel.
30
30
> * Add the plugin to a Semantic Kernel agent and use it in a web app.
31
-
- Assign the required permissions for managed identity connectivity.
31
+
> * Assign the required permissions for managed identity connectivity.
32
32
33
33
## Prerequisites
34
34
@@ -39,6 +39,8 @@ In this tutorial, you learn how to:
39
39
40
40
The easiest way to get started is by using GitHub Codespaces, which provides a complete development environment with all required tools preinstalled.
41
41
42
+
[](https://codespaces.new/Azure-Samples/app-service-agentic-semantic-kernel-java)
43
+
42
44
1. Navigate to the GitHub repository at [https://github.com/Azure-Samples/app-service-agentic-semantic-kernel-java](https://github.com/Azure-Samples/app-service-agentic-semantic-kernel-java).
43
45
44
46
2. Select the **Code** button, select the **Codespaces** tab, and click **Create codespace on main**.
@@ -55,9 +57,9 @@ The easiest way to get started is by using GitHub Codespaces, which provides a c
55
57
56
58
## Review the agent code
57
59
58
-
The Semantic Kernel agent is initialized in [src/main/java/com/example/crudtaskswithagent/controller/AgentController.java](), when the user enters the first prompt in a new browser session.
60
+
The Semantic Kernel agent is initialized in [src/main/java/com/example/crudtaskswithagent/controller/AgentController.java](https://github.com/Azure-Samples/app-service-agentic-semantic-kernel-java/blob/main/src/main/java/com/example/crudtaskswithagent/controller/AgentController.java), when the user enters the first prompt in a new browser session.
59
61
60
-
You can find the initialization code in the `SemanticKernelAgentService` contructor (in [src/main/java/com/example/crudtaskswithagent/service/SemanticKernelAgentService.java]()). The initialization code does the following:
62
+
You can find the initialization code in the `SemanticKernelAgentService` contructor (in [src/main/java/com/example/crudtaskswithagent/service/SemanticKernelAgentService.java](https://github.com/Azure-Samples/app-service-agentic-semantic-kernel-java/blob/main/src/main/java/com/example/crudtaskswithagent/service/SemanticKernelAgentService.java)). The initialization code does the following:
61
63
62
64
- Creates a kernel with chat completion.
63
65
- Adds a kernel plugin that encapsulates the functionality of the CRUD application (in *src/main/java/com/example/crudtaskswithagent/plugin/TaskCrudPlugin.java*). The interesting parts of the plugin are the `DefineKernelFunction` annotations on the method declarations and the `description` and `returnType` parameters that help the kernel call the plugin intelligently.
@@ -66,7 +68,7 @@ You can find the initialization code in the `SemanticKernelAgentService` contruc
Each time the prompt is received, the server code uses ChatCompletionAgent.invokeAsync()invoke the agent with the user prompt.
71
+
Each time the prompt is received, the server code uses `ChatCompletionAgent.invokeAsync()` to invoke the agent with the user prompt and the agent thread. the agent thread keeps track of the chat history.
# Add an App Service app as a tool in Azure AI Foundry Agent Service (.NET)
14
14
15
-
In this tutorial, you'll learn how to expose your app's functionality through OpenAPI, add it as a tool to Azure AI Foundry Agent Service, and interact with your app using natural language in the agents playground.
15
+
In this tutorial, you'll learn how to expose an ASP.NET Core app's functionality through OpenAPI, add it as a tool to Azure AI Foundry Agent Service, and interact with your app using natural language in the agents playground.
16
16
17
17
If your web application already has useful features, like shopping, hotel booking, or data management, it's easy to make those capabilities available to an AI agent in Azure AI Foundry Agent Service. By simply adding an OpenAPI schema to your app, you enable the agent to understand and use your app's capabilities when it responds to users' prompts. This means anything your app can do, your AI agent can do too, with minimal effort beyond creating an OpenAPI endpoint for your app. In this tutorial, you start with a simple to-do list app. By the end, you'll be able to create, update, and manage tasks with an agent through conversational AI.
18
18
@@ -163,15 +163,15 @@ At a minimum, open the [sample application](https://github.com/Azure-Samples/msd
163
163
164
164
1. Navigate to the Swagger UI by adding `/swagger/index.html` to the URL.
165
165
166
-
1. Confirm that the API operations work by trying them out. in the Swagger UI.
166
+
1. Confirm that the API operations work by trying them out in the Swagger UI.
167
167
168
168
1. Back in the codespace terminal, deploy your changes by committing your changes (GitHub Actions method) or run `azd up` (Azure Developer CLI method).
169
169
170
170
1. Once your changes are deployed, navigate to `https://<your-app's-url>/swagger/v1/swagger.json` and copy the schema for later.
171
171
172
172
## Create an agent in Azure AI Foundry
173
173
174
-
1. Create an agent in the Azure AI Foundry portal by following the steps at:[Quickstart: Create a new agent](/azure/ai-services/agents/quickstart?pivots=ai-foundry-portal).
174
+
1. Create an agent in the Azure AI Foundry portal by following the steps at:[Quickstart: Create a new agent](/azure/ai-services/agents/quickstart?pivots=ai-foundry-portal).
175
175
176
176
Note the [models you can use and the available regions](/azure/ai-services/agents/concepts/model-region-support#azure-openai-models).
177
177
@@ -193,6 +193,23 @@ At a minimum, open the [sample application](https://github.com/Azure-Samples/msd
193
193
194
194
:::image type="content" source="media/tutorial-ai-integrate-azure-ai-agent-dotnet/agents-playground.png" alt-text="Screenshot showing the agents playground in the middle of a conversation that takes actions by using the OpenAPI tool.":::
195
195
196
+
## Security best practices
197
+
198
+
When exposing APIs via OpenAPI in Azure App Service, follow these security best practices:
199
+
200
+
- **Authentication and Authorization**: Protect your OpenAPI endpoints in App Service behind [Azure API Management with Microsoft Entra ID](/azure/api-management/api-management-howto-protect-backend-with-aad) and ensure only authorized users or agents can access the tools.
201
+
- **Validate input data:** The sample code checks `ModelState.IsValid` in the `CreateTodo` method, which ensures that the incoming data matches the model's validation attributes. For more information, see [Model validation in ASP.NET Core](https://learn.microsoft.com/aspnet/core/mvc/models/validation).
202
+
- **Use HTTPS:** The sample relies on Azure App Service, which enforces HTTPS by default and provides free TLS/SSL certificates to encrypt data in transit.
203
+
- **Limit CORS:** Restrict Cross-Origin Resource Sharing (CORS) to trusted domains only. For more information, see [Enable CORS](app-service-web-tutorial-rest-api.md#enable-cors).
204
+
- **Apply rate limiting:** Use [API Management](/azure/api-management/api-management-sample-flexible-throttling) or custom middleware to prevent abuse and denial-of-service attacks.
205
+
- **Hide sensitive endpoints:** Avoid exposing internal or admin APIs in your OpenAPI schema.
206
+
- **Review OpenAPI schema:** Ensure your OpenAPI schema doesn't leak sensitive information (such as internal URLs, secrets, or implementation details).
207
+
- **Keep dependencies updated:** Regularly update NuGet packages and monitor for security advisories.
208
+
- **Monitor and log activity:** Enable logging and monitor access to detect suspicious activity.
209
+
- **Use managed identities:** When calling other Azure services, use managed identities instead of hardcoded credentials.
210
+
211
+
For more guidance, see [Secure your App Service app](https://learn.microsoft.com/azure/app-service/security-overview) and [Best practices for REST API security](https://learn.microsoft.com/azure/architecture/best-practices/api-design#security).
212
+
196
213
## Next step
197
214
198
215
You've now enabled your App Service app to be used as a tool by Azure AI Foundry Agent Service and interact with your app's APIs through natural language in the agents playground. From here, you can continue add features to your agent in the Foundry portal, integrate it into your own applications using the Azure AI Foundry SDK or REST API, or deploy it as part of a larger solution. Agents created in Azure AI Foundry can be run in the cloud, integrated into chatbots, or embedded in web and mobile apps.
Copy file name to clipboardExpand all lines: articles/app-service/tutorial-ai-integrate-azure-ai-agent-java.md
+23-6Lines changed: 23 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,9 +10,9 @@ ms.custom:
10
10
ms.collection: ce-skilling-ai-copilot
11
11
---
12
12
13
-
# Add an App Service app as a tool in Azure AI Foundry Agent Service (Java)
13
+
# Add an App Service app as a tool in Azure AI Foundry Agent Service (Spring Boot)
14
14
15
-
In this tutorial, you'll learn how to expose your app's functionality through OpenAPI, add it as a tool to Azure AI Foundry Agent Service, and interact with your app using natural language in the agents playground.
15
+
In this tutorial, you'll learn how to expose a Spring Boot web app's functionality through OpenAPI, add it as a tool to Azure AI Foundry Agent Service, and interact with your app using natural language in the agents playground.
16
16
17
17
If your web application already has useful features, like shopping, hotel booking, or data management, it's easy to make those capabilities available to an AI agent in Azure AI Foundry Agent Service. By simply adding an OpenAPI schema to your app, you enable the agent to understand and use your app's capabilities when it responds to users' prompts. This means anything your app can do, your AI agent can do too, with minimal effort beyond creating an OpenAPI endpoint for your app. In this tutorial, you start with a simple to-do list app. By the end, you'll be able to create, update, and manage tasks with an agent through conversational AI.
18
18
@@ -26,7 +26,7 @@ If your web application already has useful features, like shopping, hotel bookin
26
26
27
27
## Prerequisites
28
28
29
-
This tutorial assumes you're working with the sample used in[Tutorial: Build a Java Spring Boot web app with Azure App Service on Linux and Azure Cosmos DB](tutorial-java-spring-cosmosdb.md).
29
+
This tutorial assumes you're working with the sample used in[Tutorial: Build a Java Spring Boot web app with Azure App Service on Linux and Azure Cosmos DB](tutorial-java-spring-cosmosdb.md).
30
30
31
31
At a minimum, open the [sample application](https://github.com/Azure-Samples/msdocs-spring-boot-mongodb-sample-app) in GitHub Codespaces and deploy the app by running `azd up`.
32
32
@@ -35,7 +35,7 @@ At a minimum, open the [sample application](https://github.com/Azure-Samples/msd
35
35
> [!TIP]
36
36
> You can make all the following changes by telling GitHub Copilot in Agent mode:
37
37
>
38
-
> `I'd generate OpenAPI functionality using Spring Boot OpenAPI. Please also generate the server URL and operation ID in the schema.`
38
+
> `I'd like to generate OpenAPI functionality using Spring Boot OpenAPI. Please also generate the server URL and operation ID in the schema.`
39
39
40
40
1. In the codespace, open *pom.xml* and add the following dependency:
41
41
@@ -115,15 +115,15 @@ At a minimum, open the [sample application](https://github.com/Azure-Samples/msd
115
115
116
116
1. Navigate to the Swagger UI by adding `/swagger-ui.html` to the URL.
117
117
118
-
1. Confirm that the API operations work by trying them out. in the Swagger UI.
118
+
1. Confirm that the API operations work by trying them out in the Swagger UI.
119
119
120
120
1. Back in the codespace terminal, deploy your changes by committing your changes (GitHub Actions method) or run `azd up` (Azure Developer CLI method).
121
121
122
122
1. Once your changes are deployed, navigate to `https://<your-app's-url>/v3/api-docs` and copy the schema for later.
123
123
124
124
## Create an agent in Azure AI Foundry
125
125
126
-
1. Create an agent in the Azure AI Foundry portal by following the steps at:[Quickstart: Create a new agent](/azure/ai-services/agents/quickstart?pivots=ai-foundry-portal).
126
+
1. Create an agent in the Azure AI Foundry portal by following the steps at:[Quickstart: Create a new agent](/azure/ai-services/agents/quickstart?pivots=ai-foundry-portal).
127
127
128
128
Note the [models you can use and the available regions](/azure/ai-services/agents/concepts/model-region-support#azure-openai-models).
129
129
@@ -145,6 +145,23 @@ At a minimum, open the [sample application](https://github.com/Azure-Samples/msd
145
145
146
146
:::image type="content"source="media/tutorial-ai-integrate-azure-ai-agent-dotnet/agents-playground.png"alt-text="Screenshot showing the agents playground in the middle of a conversation that takes actions by using the OpenAPI tool.":::
147
147
148
+
## Security best practices
149
+
150
+
When exposing APIs via OpenAPI in Azure App Service, follow these security best practices:
151
+
152
+
- **Authentication and Authorization**: Protect your OpenAPI endpoints in App Service behind [Azure API Management with Microsoft Entra ID](/azure/api-management/api-management-howto-protect-backend-with-aad) and ensure only authorized users or agents can access the tools.
153
+
- **Validate and sanitize input data:** The example code in this tutorial omits input validation and sanitization for simplicity and clarity. In production scenarios, always implement proper validation and sanitization to protect your application. For Spring, see [Spring: Validating Form Input](https://spring.io/guides/gs/validating-form-input).
154
+
- **Use HTTPS:** The sample relies on Azure App Service, which enforces HTTPS by default and provides free TLS/SSL certificates to encrypt data in transit.
155
+
- **Limit CORS:** Restrict Cross-Origin Resource Sharing (CORS) to trusted domains only. For more information, see [Enable CORS](app-service-web-tutorial-rest-api.md#enable-cors).
156
+
- **Apply rate limiting:** Use [API Management](/azure/api-management/api-management-sample-flexible-throttling) or custom middleware to prevent abuse and denial-of-service attacks.
157
+
- **Hide sensitive endpoints:** Avoid exposing internal or admin APIs in your OpenAPI schema.
158
+
- **Review OpenAPI schema:** Ensure your OpenAPI schema doesn't leak sensitive information (such as internal URLs, secrets, or implementation details).
159
+
- **Keep dependencies updated:** Regularly update NuGet packages and monitor for security advisories.
160
+
- **Monitor and log activity:** Enable logging and monitor access to detect suspicious activity.
161
+
- **Use managed identities:** When calling other Azure services, use managed identities instead of hardcoded credentials.
162
+
163
+
For more guidance, see [Secure your App Service app](https://learn.microsoft.com/azure/app-service/security-overview) and [Best practices for REST API security](https://learn.microsoft.com/azure/architecture/best-practices/api-design#security).
164
+
148
165
## Next step
149
166
150
167
You've now enabled your App Service app to be used as a tool by Azure AI Foundry Agent Service and interact with your app's APIs through natural language in the agents playground. From here, you can continue add features to your agent in the Foundry portal, integrate it into your own applications using the Azure AI Foundry SDK or REST API, or deploy it as part of a larger solution. Agents created in Azure AI Foundry can be run in the cloud, integrated into chatbots, or embedded in web and mobile apps.
0 commit comments