Microsoft.Agents.CopilotStudio.Client
0.2.171-alpha
Prefix Reserved
See the version list below for details.
dotnet add package Microsoft.Agents.CopilotStudio.Client --version 0.2.171-alpha
NuGet\Install-Package Microsoft.Agents.CopilotStudio.Client -Version 0.2.171-alpha
<PackageReference Include="Microsoft.Agents.CopilotStudio.Client" Version="0.2.171-alpha" />
<PackageVersion Include="Microsoft.Agents.CopilotStudio.Client" Version="0.2.171-alpha" />
<PackageReference Include="Microsoft.Agents.CopilotStudio.Client" />
paket add Microsoft.Agents.CopilotStudio.Client --version 0.2.171-alpha
#r "nuget: Microsoft.Agents.CopilotStudio.Client, 0.2.171-alpha"
#addin nuget:?package=Microsoft.Agents.CopilotStudio.Client&version=0.2.171-alpha&prerelease
#tool nuget:?package=Microsoft.Agents.CopilotStudio.Client&version=0.2.171-alpha&prerelease
Microsoft.Agents.CopilotStudio.Client
Provides a client to interact with agents built in Copilot Studio. This Library is intended to provide access to a given agent's conversational channel.
Instructions - Required Setup to use this library
Prerequisite
To use this library, you will need the following:
- An Agent Created in Microsoft Copilot Studio.
- Ability to Create a Application Identity in Azure for a Public Client/Native App Registration Or access to an existing Public Client/Native App registration with the CopilotStudio.Copilot.Invoke API Permission assigned.
Create a Agent in Copilot Studio
- Create or open an Agent in Copilot Studio
- Make sure that the Copilot is Published
- Goto Settings ⇒ Advanced ⇒ Metadata and copy the following values, You will need them later:
- Schema name - this is the 'unique name' of your agent inside this environment.
- Environment Id - this is the ID of the environment that contains the agent.
Create an Application Registration in Entra ID to support user authentication to Copilot Studio
This is used when you are creating an application soly for the purpose of user interactive login and will be using a client that will surface an Entra ID MultiFactor Authentication Prompt.
[!IMPORTANT] If you are using this client from a service, you will need to exchange the user token used to login to your service for a token for your agent hosted in copilot studio. This is called a On Behalf Of authentication token. You can find more information about this authentication flow in Entra Documentation.
This step will require permissions to Create application identities in your Azure tenant. For user authentication, you will be creating a Native Client Application Identity, which does not have secrets.
- Open https://portal.azure.com
- Navigate to Entra Id
- Create an new App Registration in Entra ID
- Provide an Name
- Choose "Accounts in this organization directory only"
- In the "Select a Platform" list, Choose "Public Client/native (mobile & desktop)
- In the Redirect URI url box, type in
http://localhost
(note: use HTTP, not HTTPS) - Then click register.
- In your newly created application
- On the Overview page, Note down for use later when configuring the example application:
- the Application (client) ID
- the Directory (tenant) ID
- Goto Manage
- Goto API Permissions
- Click Add Permission
- In the side pannel that appears, Click the tab
API's my organization uses
- Search for
Power Platform API
.- If you do not see
Power Platform API
see the note at the bottom of this section.
- If you do not see
- In the permissions list choose
CopilotStudio
and CheckCopilotStudio.Copilots.Invoke
- Click
Add Permissions
- In the side pannel that appears, Click the tab
- (Optional) Click
Grant Admin consent for copilotsdk
- Close Azure Portal
- On the Overview page, Note down for use later when configuring the example application:
[!TIP] If you do not see
Power Platform API
in the list of API's your organization uses, you need to add the Power Platform API to your tenant. To do that, goto Power Platform API Authentication and follow the instructions on Step 2 to add the Power Platform Admin API to your Tenant
Add the CopilotStudio.Copilots.Invoke permissions to your Application Registration in Entra ID to support user authentication to Copilot Studio
How-to use
User Based auth flows
User based authentication flows are the only currently supported flow for this client.
Your code will need to create a User Token ( via MSAL Public Client or an OBO flow for a User access token) to call this service.
There are currently two ways to pass auth to the CopilotClient.
1. Create an HttpMessageRequest Handler that will populate the bearer token and assign it to the httpClient you create
In this case, you would create an HttpMessageRequestHandler that creates the bearer header on the http request message, In the example below, AddTokenHandler
is responsible for adding the bearer header to the http request prior to the send:
// Create an http client for use by the DirectToEngine Client and add the token handler to the client.
builder.Services.AddHttpClient("mcs").ConfigurePrimaryHttpMessageHandler(
() => new AddTokenHandler(settings));
Then create an instance the client and request to start a conversation:
var copilotClient = new CopilotClient(settings, s.GetRequiredService<IHttpClientFactory>(), logger, "mcs");
await foreach (Activity act in copilotClient.StartConversationAsync(emitStartConversationEvent:true, cancellationToken:cancellationToken))
{
}
2. Create a function that returns a user token and pass that to the constructor for the Copilot Client
In this case, the TokenService
is a class is responsible for managing the token acquire flow and returning the access token via the GetToken API
call on the TokenService
Class.
[!NOTE] We do not cover how to create the TokenService Class in this document. The Copilot client is looking for a function that matches the signature
Func<string, Task<string>> tokenProviderFunction
var tokenService = new TokenService(settings);
var copilotClient = new CopilotClient(settings, s.GetRequiredService<IHttpClientFactory>(), tokenService.GetToken, logger, "mcs");
await foreach (Activity act in copilotClient.StartConversationAsync(emitStartConversationEvent:true, cancellationToken:cancellationToken))
{
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- Microsoft.Agents.Core (>= 0.2.171-alpha)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.2.308-alpha | 38 | 4/10/2025 |
0.2.295-alpha | 46 | 4/9/2025 |
0.2.290-alpha | 68 | 4/8/2025 |
0.2.287-alpha | 80 | 4/5/2025 |
0.2.286-alpha | 131 | 4/4/2025 |
0.2.282-alpha | 150 | 4/3/2025 |
0.2.277-alpha | 148 | 4/1/2025 |
0.2.271-alpha | 96 | 3/29/2025 |
0.2.267-alpha | 119 | 3/28/2025 |
0.2.257-alpha | 120 | 3/27/2025 |
0.2.180-alpha | 455 | 3/26/2025 |
0.2.171-alpha | 106 | 3/21/2025 |
0.2.162-alpha | 141 | 3/19/2025 |
0.2.154-alpha | 178 | 3/18/2025 |
0.2.153-alpha | 68 | 3/15/2025 |
0.2.151-alpha | 106 | 3/14/2025 |
0.2.146-alpha | 157 | 3/12/2025 |
0.2.141-alpha | 173 | 3/8/2025 |
0.2.137-alpha | 211 | 3/7/2025 |
0.1.26 | 234 | 11/18/2024 |