Skip to content

Commit 86a8bf6

Browse files
committed
add java ai agent tutorials
1 parent eacc735 commit 86a8bf6

7 files changed

+562
-5
lines changed

.openpublishing.publish.config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,12 @@
626626
"branch": "main",
627627
"branch_mapping": {}
628628
},
629+
{
630+
"path_to_root": "app-service-agentic-semantic-kernel-java",
631+
"url": "https://github.com/Azure-Samples/app-service-agentic-semantic-kernel-java",
632+
"branch": "main",
633+
"branch_mapping": {}
634+
},
629635
{
630636
"path_to_root": "playwright-testing-service",
631637
"url": "https://github.com/microsoft/playwright-testing-service",
114 KB
Loading
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
---
2+
title: Agentic app with Semantic Kernel or Azure AI Foundry (.NET)
3+
description: Learn how to quickly deploy a production-ready, agentic web application using Java with Azure App Service and Microsoft Semantic Kernel.
4+
ms.service: azure-app-service
5+
author: cephalin
6+
ms.author: cephalin
7+
ms.devlang: csharp
8+
ms.topic: tutorial
9+
ms.date: 07/16/2025
10+
ms.custom:
11+
- devx-track-dotnet
12+
ms.collection: ce-skilling-ai-copilot
13+
---
14+
15+
# Tutorial: Build an agentic web app in Azure App Service with Microsoft Semantic Kernel (Java)
16+
17+
This tutorial demonstrates how to add agentic capability to an existing data-driven CRUD application. It does this using Microsoft Semantic Kernel.
18+
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+
21+
:::image type="content" source="media/tutorial-ai-agent-web-app-semantic-kernel-foundry-dotnet/semantic-kernel-agent.png" alt-text="Screenshot of a chat completion session with a semantic kernel agent.":::
22+
23+
> [!NOTE]
24+
> Azure AI Foundry Agent Service currently doesn't have a Java SDK, so isn't included in the scope of this article.
25+
26+
In this tutorial, you learn how to:
27+
28+
> [!div class="checklist"]
29+
> * Convert existing app functionality into a plugin for Semantic Kernel.
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.
32+
33+
## Prerequisites
34+
35+
- An Azure account with an active subscription - [Create an account for free](https://azure.microsoft.com/free/dotnet).
36+
- GitHub account to use GitHub Codespaces - [Learn more about GitHub Codespaces](https://docs.github.com/codespaces/overview).
37+
38+
## Open the sample with Codespaces
39+
40+
The easiest way to get started is by using GitHub Codespaces, which provides a complete development environment with all required tools preinstalled.
41+
42+
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+
44+
2. Select the **Code** button, select the **Codespaces** tab, and click **Create codespace on main**.
45+
46+
3. Wait a few moments for your Codespace to initialize. When ready, you'll see a fully configured VS Code environment in your browser.
47+
48+
4. Run the application locally:
49+
50+
```bash
51+
dotnet run
52+
```
53+
54+
5. When you see **Your application running on port 8080 is available**, select **Open in Browser** and add a few tasks.
55+
56+
## Review the agent code
57+
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.
59+
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:
61+
62+
- Creates a kernel with chat completion.
63+
- 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.
64+
- Creates a [chat completion agent](/semantic-kernel/frameworks/agent/agent-types/chat-completion-agent?pivots=programming-language-java), and configures it to let the AI model automatically invoke functions (`FunctionChoiceBehavior.auto(true)`).
65+
- Creates an agent thread that automatically manages the chat history.
66+
67+
:::code language="csharp" source="~/app-service-agentic-semantic-kernel-java/src/main/java/com/example/crudtaskswithagent/service/SemanticKernelAgentService.java" range="41-93" highlight="11-48,58" :::
68+
69+
Each time the prompt is received, the server code uses ChatCompletionAgent.invokeAsync() invoke the agent with the user prompt.
70+
71+
:::code language="csharp" source="~/app-service-agentic-semantic-kernel-java/src/main/java/com/example/crudtaskswithagent/service/SemanticKernelAgentService.java" range="112-161" highlight="8" :::
72+
73+
## Deploy the sample application
74+
75+
1. In the terminal, log into Azure using Azure Developer CLI:
76+
77+
```bash
78+
azd auth login
79+
```
80+
81+
Follow the instructions to complete the authentication process.
82+
83+
4. Deploy the Azure App Service app with the AZD template:
84+
85+
```bash
86+
azd up
87+
```
88+
89+
1. When prompted, give the following answers:
90+
91+
|Question |Answer |
92+
|---------|---------|
93+
|Enter a new environment name: | Type a unique name. |
94+
|Select an Azure Subscription to use: | Select the subscription. |
95+
|Pick a resource group to use: | Select **Create a new resource group**. |
96+
|Select a location to create the resource group in:| Select any region. The resources will actually be created in **East US 2**.|
97+
|Enter a name for the new resource group:| Type **Enter**.|
98+
99+
1. In the AZD output, find the URL of your app and navigate to it in the browser. The URL looks like this in the AZD output:
100+
101+
<pre>
102+
Deploying services (azd deploy)
103+
104+
(✓) Done: Deploying service web
105+
- Endpoint: &lt;URL>
106+
</pre>
107+
108+
1. After successful deployment, you'll see a URL for your deployed application.
109+
110+
You now have an App Service app with a system-assigned managed identity.
111+
112+
## Create and configure the Azure AI Foundry resource
113+
114+
1. In the [Azure AI Foundry portal](https://ai.azure.com), deploy a model of your choice (see [Quickstart: Get started with Azure AI Foundry](/azure/ai-foundry/quickstarts/get-started-code?tabs=azure-ai-foundry&pivots=fdp-project)). A project and a default agent are created for you in the process.
115+
116+
1. From the left menu, select **Overview**.
117+
118+
1. Select **Azure OpenAI** and copy the URL in **Azure OpenAI endpoint** for later.
119+
120+
:::image type="content" source="media/tutorial-ai-agent-web-app-semantic-kernel-foundry-dotnet/foundry-project-endpoints.png" alt-text="Screenshot showing how to copy the OpenAI endpoint and the foundry project endpoint in the foundry portal.":::
121+
122+
## Assign required permissions
123+
124+
1. At the upper right corner of the foundry portal, select the name of the resource, then select **Resource Group** to open it in the Azure portal.
125+
126+
:::image type="content" source="media/tutorial-ai-agent-web-app-semantic-kernel-foundry-dotnet/go-to-azure-portal.png" alt-text="Screenshot showing how to quickly go to the resource group view for the foundry resource in the Azure portal.":::
127+
128+
1. Add a role for each of the two resources for the App Service app's manage identity using the following table:
129+
130+
| Target resource | Required role | Needed for |
131+
|--------------------------------|-------------------------------------|-------------------------|
132+
| Azure AI Foundry | Cognitive Services OpenAI User | The chat completion service in the semantic kernel. |
133+
134+
For instructions, see [Assign Azure roles using the Azure portal](/azure/role-based-access-control/role-assignments-portal).
135+
136+
## Configure connection variables in your sample application
137+
138+
1. Open *src/main/resources/application.properties*. Using the values you copied earlier from the AI Foundry portal, configure the following variables:
139+
140+
| Variable | Description |
141+
|-------------------------------|----------------------------------------------------------|
142+
| `azure.openai.endpoint` | Azure OpenAI endpoint (copied from the Overview page). This is needed by the Semantic Kernel agent. |
143+
| `azure.openai.deployment` | Model name in the deployment (copied from the Agents setup pane). This is needed by the Semantic Kernel agent. |
144+
145+
> [!NOTE]
146+
> To keep the tutorial simple, you'll use these variables in *src/main/resources/application.properties* instead of overwriting them with app settings in App Service.
147+
148+
1. Sign in to Azure with the Azure CLI:
149+
150+
```bash
151+
az login
152+
```
153+
154+
This allows the Azure Identity client library in the sample code to receive an authentication token for the logged in user. Remember that you added the required role for this user earlier.
155+
156+
1. Run the application locally:
157+
158+
```bash
159+
mvn spring-boot:run
160+
```
161+
162+
1. When you see **Your application running on port 8080 is available**, select **Open in Browser**.
163+
164+
1. Try out the chat interface. If you get a response, your application is connecting successfully to the Azure AI Foundry resource.
165+
166+
1. Back in the GitHub codespace, deploy your app changes.
167+
168+
```bash
169+
azd up
170+
```
171+
172+
1. Navigate to the deployed application again and test the chat agents.
173+
174+
:::image type="content" source="media/tutorial-ai-agent-web-app-semantic-java/semantic-kernel-agent.png" alt-text="Screenshot of a chat completion session with a semantic kernel agent.":::
175+
176+
## Clean up resources
177+
178+
When you're done with the application, you can delete the App Service resources to avoid incurring further costs:
179+
180+
```bash
181+
azd down --purge
182+
```
183+
184+
Sind the AZD template doesn't include the Azure AI Foundry resources, you need to delete them manually if you want.
185+
186+
## More resources
187+
188+
- [Integrate AI into your Azure App Service applications](overview-ai-integration.md)
189+
- [Introduction to Semantic Kernel](/semantic-kernel/overview/)

articles/app-service/tutorial-ai-integrate-azure-ai-agent-dotnet.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Integrate web app with OpenAPI in Azure AI Foundry Agent Service
2+
title: Integrate web app with OpenAPI in Azure AI Foundry Agent Service (.NET)
33
description: Empower your existing web apps by integrating their capabilities into Azure AI Foundry Agent Service with OpenAPI, enabling AI agents to perform real-world tasks.
44
author: cephalin
55
ms.author: cephalin
@@ -167,7 +167,7 @@ At a minimum, open the [sample application](https://github.com/Azure-Samples/msd
167167
168168
1. Back in the codespace terminal, deploy your changes by committing your changes (GitHub Actions method) or run `azd up` (Azure Developer CLI method).
169169
170-
1. Once your changes are deployed, navigate to https://<your-app's-url>/swagger/v1/swagger.json and copy the schema for later.
170+
1. Once your changes are deployed, navigate to `https://<your-app's-url>/swagger/v1/swagger.json` and copy the schema for later.
171171
172172
## Create an agent in Azure AI Foundry
173173
@@ -204,5 +204,5 @@ To take the next step and learn how to run your agent directly within Azure App
204204
205205
## More resources
206206
207-
[Integrate AI into your Azure App Service applications](overview-ai-integration.md)
208-
[What is Azure AI Foundry Agent Service?](/azure/ai-services/agents/overview)
207+
- [Integrate AI into your Azure App Service applications](overview-ai-integration.md)
208+
- [What is Azure AI Foundry Agent Service?](/azure/ai-services/agents/overview)

0 commit comments

Comments
 (0)