Socket
Book a DemoInstallSign in
Socket

@microsoft/agents-copilotstudio-client

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@microsoft/agents-copilotstudio-client

Microsoft Copilot Studio Client for JavaScript. Copilot Studio Client.

latest
Source
npmnpm
Version
1.0.15
Version published
Weekly downloads
831
48.13%
Maintainers
1
Weekly downloads
 
Created
Source

@microsoft/agents-copilotstudio-client

Overview

The @microsoft/agents-copilotstudio-client package allows you to interact with Copilot Studio Agents using the Direct Engine Protocol. This client library is designed to facilitate communication with agents, enabling seamless integration and interaction within your JavaScript or TypeScript applications.

This package provides exports for CommonJS and ES6 modules, and also a bundle to be used in the browser.

[!NOTE] The Client needs to be initialized with a valid JWT Token.

Installation

To install the package, use npm or yarn:

npm install @microsoft/agents-copilotstudio-client

Prerequisite

To use this library, you will need the following:

  • An Agent Created in Microsoft Copilot Studio.
  • Ability to Create or Edit an Application Identity in Azure
    • (Option 1) for a Public Client/Native App Registration or access to an existing registration (Public Client/Native App) that has the CopilotStudio.Copilot.Invoke API Delegated Permission assigned.
    • (Option 2) for a Confidential Client/Service Principal App Registration or access to an existing App Registration (Confidential Client/Service Principal) with the CopilotStudio.Copilot.Invoke API Application 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

[!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 (OBO) authentication token. You can find more information about this authentication flow in Entra Documentation.

When using this method, you will need to add the CopilotStudio.Copilots.Invoke delegated API permision to your application registration's API privilages

Add the CopilotStudio.Copilots.Invoke permissions to your Application Registration in Entra ID to support User or Service Principal authentication to Copilot Studio

This step will require permissions to edit application identities in your Azure tenant.

  • In your azure application
    • 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.
      • For User Interactive Permissions, choose Delegated Permissions
        • In the permissions list choose CopilotStudio and Check CopilotStudio.Copilots.Invoke
        • Click Add Permissions
      • For Service Principal/Confidential Client, choose Application Permissions
        • In the permissions list choose CopilotStudio and Check CopilotStudio.Copilots.Invoke
        • Click Add Permissions
        • An appropriate administrator must then Grant Admin consent for copilotsdk before the permissions will be available to the application.
    • Close Azure Portal

[!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

How-to use

The Copilot Client is configured using the ConnectionSettings class and a jwt token to authenticate to the service. The ConnectionSettings class can be configured using either instantiating the class or loading the settings from a .env.

Using the default class

There are a few options for configuring the ConnectionSettings class. The following are the most common options:

Using Environment ID and Copilot Studio Agent Schema Name:

const settings: ConnectionSettings = {
  environmentId: "your-environment-id",
  agentIdentifier: "your-agent-schema-name",
};

Using the DirectConnectUrl:

const settings: ConnectionSettings = {
  directConnectUrl: "https://direct.connect.url",
};

[!NOTE] By default, it's assumed your agent is in the Microsoft Public Cloud. If you are using a different cloud, you will need to set the Cloud property to the appropriate value. See the PowerPlatformCloud enum for the supported values

Using the .env file

You can use the loadCopilotStudioConnectionSettingsFromEnv function to load the ConnectionSettings from a .env file.

The following are the most common options:

Using Environment ID and Copilot Studio Agent Schema Name:

environmentId=your-environment-id
agentIdentifier=your-agent-schema-name

Using the DirectConnectUrl:

directConnectUrl=https://direct.connect.url

Example of how to create a Copilot client

const createClient = async (): Promise<CopilotStudioClient> => {
  const settings = loadCopilotStudioConnectionSettingsFromEnv()
  const token = await acquireToken(settings)
  const copilotClient = new CopilotStudioClient(settings, token)
  return copilotClient
}
const copilotClient = await createClient()
const replies = await copilotClient.startConversationAsync(true)
replies.forEach(r => console.log(r.text))

Keywords

Agents

FAQs

Package last updated on 08 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.