Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 56 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,64 @@
# Agent 365 SDK Samples
# Microsoft Agent 365 SDK Samples and Prompts

This repository contains sample agents and prompts for building with the Microsoft Agent 365 SDK. The Microsoft Agent 365 SDK extends the Microsoft 365 Agents SDK with enterprise-grade capabilities for building sophisticated agents. It provides comprehensive tooling for observability, notifications, runtime utilities, and development tools that help developers create production-ready agents for platforms including M365, Teams, Copilot Studio, and Webchat.

- **Sample agents** are available in C# (.NET), Python, and Node.js/TypeScript
- **Prompts** to help you get started with AI-powered development tools like Cursor IDE

## 📋 **Telemetry**
> #### Note:
> Use the information in this README to contribute to this open-source project. To learn about using this SDK in your projects, refer to the [Microsoft Agent 365 Developer documentation](https://learn.microsoft.com/en-us/microsoft-agent-365/developer/).

Data Collection. The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft's privacy statement. Our privacy statement is located at https://go.microsoft.com/fwlink/?LinkID=824704. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices.
## Current Repository State

This samples repository is currently in active development and contains:
- **Sample Agents**: Production-ready examples in C#/.NET, Python, and Node.js/TypeScript demonstrating observability, notifications, tooling, and hosting patterns
- **Prompts**: Guides for using AI-powered development tools (e.g., Cursor IDE) to accelerate agent development

## Documentation

For comprehensive documentation and guides, visit the [Microsoft Agent 365 Developer Documentation](https://learn.microsoft.com/en-us/microsoft-agent-365/developer/).

### Microsoft Agent 365 SDK

The sample agents in this repository use the Microsoft Agent 365 SDK, which provides enterprise-grade extensions for observability, notifications, runtime utilities, and developer tools. Explore the SDK repositories below:

- [Microsoft Agent 365 SDK - C# /.NET repository](https://github.com/microsoft/Agent365-dotnet)
- [Microsoft Agent 365 SDK - Python repository](https://github.com/microsoft/Agent365-python)
- [Microsoft Agent 365 SDK - Node.js/TypeScript repository](https://github.com/microsoft/Agent365-nodejs)
- [Microsoft Agent 365 SDK Samples repository](https://github.com/microsoft/Agent365-Samples) - You are here

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

## Useful Links

### Microsoft 365 Agents SDK

The core SDK for building conversational AI agents for Microsoft 365 platforms.

- [Microsoft 365 Agents SDK - C# /.NET repository](https://github.com/Microsoft/Agents-for-net)
- [Microsoft 365 Agents SDK - NodeJS /TypeScript repository](https://github.com/Microsoft/Agents-for-js)
- [Microsoft 365 Agents SDK - Python repository](https://github.com/Microsoft/Agents-for-python)
- [Microsoft 365 Agents documentation](https://learn.microsoft.com/microsoft-365/agents-sdk/)

## Additional Resources

For language-specific documentation and additional resources, explore the following links:

- [.NET documentation](https://learn.microsoft.com/dotnet/api/?view=m365-agents-sdk&preserve-view=true)
- [Node.js documentation](https://learn.microsoft.com/javascript/api/?view=m365-agents-sdk&preserve-view=true)
- [Python documentation](https://learn.microsoft.com/python/api/?view=m365-agents-sdk&preserve-view=true)

## Trademarks

*Microsoft, Windows, Microsoft Azure and/or other Microsoft products and services referenced in the documentation may be either trademarks or registered trademarks of Microsoft in the United States and/or other countries. The licenses for this project do not grant you rights to use any Microsoft names, logos, or trademarks. Microsoft's general trademark guidelines can be found at http://go.microsoft.com/fwlink/?LinkID=254653.*

## License
Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT License - see the LICENSE file for details.
216 changes: 51 additions & 165 deletions dotnet/semantic-kernel/sample-agent/README.md
Original file line number Diff line number Diff line change
@@ -1,172 +1,58 @@
# Agent 365 Sample Agent - .NET Semantic Kernel
# Semantic Kernel Sample Agent - C#/.NET

This directory contains a sample agent implementation using .NET and Semantic Kernel, hosted on an ASP.NET Core web service. This agent will handle multiple "turns" to get the required information from the user.
This sample demonstrates how to build an agent using Semantic Kernel in C#/.NET with the Microsoft Agent 365 SDK. It covers:

This Agent Sample is intended to introduce you to the basics of integrating Agent 365 and Semantic Kernel with the Microsoft 365 Agents SDK in order to build powerful Agents. It can also be used as the base for a custom Agent that you choose to develop.
- **Observability**: End-to-end tracing, caching, and monitoring for agent applications
- **Notifications**: Services and models for managing user notifications
- **Tools**: Model Context Protocol tools for building advanced agent solutions
- **Hosting Patterns**: Hosting with Microsoft 365 Agents SDK

## Demonstrates
This sample uses the [Microsoft Agent 365 SDK for .NET](https://github.com/microsoft/Agent365-dotnet).

This sample demonstrates how to build an agent using the Agent 365 framework with .NET and Semantic Kernel. It shows the three key Agent 365 concepts; Notifications, Observability, and Tooling, and shows how by combining these concepts, powerful scenarios can be unlocked.
For comprehensive documentation and guidance on building agents with the Microsoft Agent 365 SDK, including how to add tooling, observability, and notifications, visit the [Microsoft Agent 365 Developer Documentation](https://learn.microsoft.com/en-us/microsoft-agent-365/developer/).

## Prerequisites

- [.NET 8.0](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)+
- Azure OpenAI or OpenAI API key
- Optional: [Microsoft 365 Agents Playground](https://learn.microsoft.com/en-us/microsoft-365/agents-sdk/test-with-toolkit-project)
- Optional: [dev tunnel](https://learn.microsoft.com/azure/developer/dev-tunnels/get-started)

## How to run this sample

### Configuration

1. You will need an Azure OpenAI or OpenAI resource using, e.g., model `gpt-4o-mini`
2. Configure OpenAI in `appsettings.json`
```json
"AIServices": {
"AzureOpenAI": {
"DeploymentName": "", // This is the Deployment (as opposed to model) Name of the Azure OpenAI model
"Endpoint": "", // This is the Endpoint of the Azure OpenAI model deployment
"ApiKey": "" // This is the API Key of the Azure OpenAI model deployment
},
"OpenAI": {
"ModelId": "", // This is the Model ID of the OpenAI model
"ApiKey": "" // This is the API Key of the OpenAI model
},
"UseAzureOpenAI": true // This is a flag to determine whether to use the Azure OpenAI model or the OpenAI model
}
```
3. For information on how to create an Azure OpenAI deployment, see [Create and deploy an Azure OpenAI in Azure AI Foundry Models resource](https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/create-resource?pivots=web-portal).
4. Verify the local development settings in `Properties/launchSettings.json` are configured for your environment.

### Run using Microsoft 365 Agents Playground

1. If you haven't done so already, install the Agents Playground:
```bash
winget install agentsplayground
```
2. Start the agent in Visual Studio or VS Code in debug mode
3. Start Agents Playground at a command prompt:
```bash
agentsplayground
```
The tool will open a web browser showing the Microsoft 365 Agents Playground, ready to send messages to your agent.
4. Interact with the agent via the browser


### Run using WebChat or Teams

**Overview of running and testing an agent:**
- Provision an Azure Bot in your Azure Subscription
- Configure your agent settings to use the desired authentication type
- Run an instance of the agent app (either locally or deployed to Azure)
- Test in a client

#### Setup

1. Create an Azure Bot with one of these authentication types
- [SingleTenant, Client Secret](https://learn.microsoft.com/en-us/microsoft-365/agents-sdk/azure-bot-create-single-secret)
- [SingleTenant, Federated Credentials](https://learn.microsoft.com/en-us/microsoft-365/agents-sdk/azure-bot-create-federated-credentials)
- [User Assigned Managed Identity](https://learn.microsoft.com/en-us/microsoft-365/agents-sdk/azure-bot-create-managed-identity)

> **Note:** Be sure to follow the **Next Steps** at the end of these docs to configure your agent settings.

> **IMPORTANT:** If you want to run your agent locally via devtunnels, the only supported auth type is Client Secrets and Certificates.

2. Running the agent

**Option A: Run the agent locally**

- Requires a tunneling tool to allow for local development and debugging when connected to an external client such as Microsoft Teams.
- **For Client Secret or Certificate authentication types only.** Federated Credentials and Managed Identity will not work via a tunnel to a local agent and must be deployed to an App Service or container.

Steps:
1. Run `dev tunnels`. Follow [Create and host a dev tunnel](https://learn.microsoft.com/azure/developer/dev-tunnels/get-started?tabs=windows) and host the tunnel with anonymous user access as shown below:
```bash
devtunnel host -p 3978 --allow-anonymous
```
2. On the Azure Bot, select **Settings**, then **Configuration**, and update the **Messaging endpoint** to `{tunnel-url}/api/messages`
3. Start the agent in Visual Studio

**Option B: Deploy agent code to Azure**

1. Deploy using Visual Studio Publish or any tool used to deploy web applications.
2. On the Azure Bot, select **Settings**, then **Configuration**, and update the **Messaging endpoint** to `https://{{appServiceDomain}}/api/messages`

#### Testing this agent with WebChat

1. Select **Test in WebChat** on the Azure Bot resource in the Azure portal

#### Testing this agent in Teams or Microsoft 365

1. Update the `manifest.json` file:
- Edit the `manifest.json` file in the `appManifest` folder
- Replace `<<AAD_APP_CLIENT_ID>>` with your AppId (created above) *everywhere* it appears
- Replace `<<BOT_DOMAIN>>` with your agent URL (for example, the tunnel host name)
- Zip the contents of the `appManifest` folder to create `manifest.zip` (include all three files):
- `manifest.json`
- `outline.png`
- `color.png`
2. Ensure your Azure Bot has the **Microsoft Teams** channel added under **Channels**.
3. Navigate to the Microsoft 365 admin center. Under **Settings** and **Integrated Apps**, select **Upload Custom App**.
4. Select the `manifest.zip` file created in the previous step.
5. After a short period, the agent will appear in Microsoft Teams and Microsoft 365 Copilot.

#### Enabling JWT token validation

1. By default, ASP.NET token validation is disabled to support local debugging.
2. Enable it by updating `appsettings.json`:
```json
"TokenValidation": {
"Enabled": true,
"Audiences": [
"{{ClientId}}" // This is the Client ID used for the Azure Bot
],
"TenantId": "{{TenantId}}"
},
```

### Developing the agent / Understanding the code

- See the [Agent Code Walkthrough](./Agent-Code-Walkthrough.md) for a detailed explanation of the code.

### Troubleshooting

#### Missing OpenAI key in appsettings.json

- **Error when project is run through Visual Studio**

When the project is run through Visual Studio, the following error occurs:
```
System.ArgumentException: 'The value cannot be an empty string or composed entirely of whitespace. (Parameter 'endpoint')'
```
The exception has call stack:
```
> System.Private.CoreLib.dll!System.ArgumentException.ThrowNullOrWhiteSpaceException(string argument, string paramName) Line 113 C#
System.Private.CoreLib.dll!System.ArgumentException.ThrowIfNullOrWhiteSpace(string argument, string paramName) Line 98 C#
Microsoft.SemanticKernel.Connectors.OpenAI.dll!Microsoft.SemanticKernel.Verify.NotNullOrWhiteSpace(string str, string paramName) Line 38 C#
Microsoft.SemanticKernel.Connectors.AzureOpenAI.dll!Microsoft.SemanticKernel.AzureOpenAIServiceCollectionExtensions.AddAzureOpenAIChatCompletion(Microsoft.Extensions.DependencyInjection.IServiceCollection services, string deploymentName, string endpoint, string apiKey, string serviceId, string modelId, string apiVersion, System.Net.Http.HttpClient httpClient) Line 30 C#
SemanticKernelSampleAgent.dll!Program.<Main>$(string[] args) Line 33 C#
```

- **Error when project is run through command line**

When the project is run through the the command line:
```bash
dotnet run
```
The following error occurs:
```
C:\Agent365-Samples\dotnet\semantic-kernel\sample-agent\MyAgent.cs(145,48): warning CS8602: Dereference of a possibly null reference.
Unhandled exception. System.ArgumentException: The value cannot be an empty string or composed entirely of whitespace. (Parameter 'endpoint')
at System.ArgumentException.ThrowNullOrWhiteSpaceException(String argument, String paramName)
at System.ArgumentException.ThrowIfNullOrWhiteSpace(String argument, String paramName)
at Microsoft.SemanticKernel.AzureOpenAIServiceCollectionExtensions.AddAzureOpenAIChatCompletion(IServiceCollection services, String deploymentName, String endpoint, String apiKey, String serviceId, String modelId, String apiVersion, HttpClient httpClient)
at Program.<Main>$(String[] args) in C:\Agent365-samples\dotnet\semantic-kernel\sample-agent\Program.cs:line 33
```

- **Solution**

Configure the OpenAI or Azure OpenAI settings in `appsettings.json` as described in the [Configuration](#configuration) section above.

## Further reading
To learn more about Agent 365, see [Agent 365](https://learn.microsoft.com/en-us/microsoft-365/agents-sdk/).
- .NET 8.0 or higher
- Microsoft Agent 365 SDK
- Semantic Kernel 1.66.0 or higher
- Azure/OpenAI API credentials

## Running the Agent

To set up and test this agent, refer to the [Configure Agent Testing](https://learn.microsoft.com/en-us/microsoft-agent-365/developer/testing?tabs=dotnet) guide for complete instructions.

For a detailed explanation of the agent code and implementation, see the [Agent Code Walkthrough](Agent-Code-Walkthrough.md).

## Support

For issues, questions, or feedback:

- **Issues**: Please file issues in the [GitHub Issues](https://github.com/microsoft/Agent365-dotnet/issues) section
- **Documentation**: See the [Microsoft Agents 365 Developer documentation](https://learn.microsoft.com/en-us/microsoft-agent-365/developer/)
- **Security**: For security issues, please see [SECURITY.md](SECURITY.md)

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit <https://cla.opensource.microsoft.com>.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

## Additional Resources

- [Microsoft Agent 365 SDK - .NET repository](https://github.com/microsoft/Agent365-dotnet)
- [Microsoft 365 Agents SDK - .NET repository](https://github.com/Microsoft/Agents-for-net)
- [Semantic Kernel documentation](https://learn.microsoft.com/semantic-kernel/)
- [.NET API documentation](https://learn.microsoft.com/dotnet/api/?view=m365-agents-sdk&preserve-view=true)

## Trademarks

*Microsoft, Windows, Microsoft Azure and/or other Microsoft products and services referenced in the documentation may be either trademarks or registered trademarks of Microsoft in the United States and/or other countries. The licenses for this project do not grant you rights to use any Microsoft names, logos, or trademarks. Microsoft's general trademark guidelines can be found at http://go.microsoft.com/fwlink/?LinkID=254653.*

## License

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT License - see the [LICENSE](LICENSE.md) file for details.
Loading
Loading