# agents-sdk-typescript

Adopt this skill: https://proskills.md/skills/other/microsoft-agents-agent-plugins-agents-for-js-skills-agents-sdk-typescript

Page: https://proskills.md/skills/other/microsoft-agents-agent-plugins-agents-for-js-skills-agents-sdk-typescript
This document is the public skill bundle for that page. It contains SKILL.md and every helper file the catalog carries. No login is required.

## File: agent-plugins/agents-for-js/skills/agents-sdk-typescript/SKILL.md
size: 8018
upstream: https://github.com/microsoft/agents/blob/main/agent-plugins/agents-for-js/skills/agents-sdk-typescript/SKILL.md

````text
---
name: agents-sdk-typescript
description: >
  Use when any code imports @microsoft/agents-hosting, @microsoft/agents-hosting-express,
  or related Agents SDK packages, or when the user is building, configuring, or
  asking questions about a Microsoft 365 Agents SDK agent in TypeScript. Trigger
  on questions about environment variables, connection configuration,
  AgentApplication patterns, OAuth sign-in flows, storage backends, cards,
  streaming, or local testing with the Agents Playground — even if no code exists
  yet and the user is planning or asking how to get started.
---

## Overview

The Microsoft 365 Agents SDK builds multichannel agents for Teams, Copilot Studio, and web chat.

| Package | Purpose |
|---|---|
| `@microsoft/agents-hosting` | Core: AgentApplication, CloudAdapter, TurnContext, TurnState, storage |
| `@microsoft/agents-hosting-express` | `startServer()` convenience wrapper |
| `@microsoft/agents-hosting-storage-blob` | Azure Blob Storage backend |
| `@microsoft/agents-hosting-storage-cosmos` | CosmosDB backend |
| `@microsoft/agents-hosting-dialogs` | Dialog system |

Requires Node 18+. Use `node --env-file .env` (Node 20+) to load environment variables.

## Azure Resources Required

**Microsoft Entra App Registration**
- `clientId` — Application (client) ID
- `clientSecret` — Certificates & secrets
- `tenantId` — Directory (tenant) ID

**Azure Bot Resource**
- Messaging endpoint: `https://<your-host>/api/messages`
- Microsoft App ID must match `clientId`

Local dev: Use Bot Framework Emulator. No Azure Bot needed until deployment. Leave `clientId` blank to skip auth validation.

## Environment Variables

### Modern format (recommended)

Uses `connections__` and `connectionsMap__` prefixes. Double underscores (`__`) separate path segments; `.settings.` is stripped automatically.

**Single connection (most common):**
```
connections__serviceConnection__settings__clientId=<your-app-id>
connections__serviceConnection__settings__clientSecret=<your-secret>
connections__serviceConnection__settings__tenantId=<your-tenant-id>
connectionsMap__0__connection=serviceConnection
connectionsMap__0__serviceUrl=*
```

**How `connectionsMap` works:**
Each entry maps a `serviceUrl` pattern to a named connection. The first matching entry wins.
- `serviceUrl=*` — matches any service URL (use as the default/fallback)
- `serviceUrl` is treated as a regex for all other values

`connectionsMap` can be omitted when there is only one connection — the SDK defaults it to `serviceUrl=*`.

**Multiple connections** (e.g. different identities for different channels):
```
connections__mainConn__settings__clientId=<app-id-1>
connections__mainConn__settings__clientSecret=<secret-1>
connections__mainConn__settings__tenantId=<tenant-id>

connections__teamsConn__settings__clientId=<app-id-2>
connections__teamsConn__settings__clientSecret=<secret-2>
connections__teamsConn__settings__tenantId=<tenant-id>

connectionsMap__0__connection=teamsConn
connectionsMap__0__serviceUrl=https://smba.trafficmanager.net/.*
connectionsMap__1__connection=mainConn
connectionsMap__1__serviceUrl=*
```

Optional `audience` field on a map entry restricts matching to activities whose JWT `aud` claim equals that value:
```
connectionsMap__0__connection=teamsConn
connectionsMap__0__serviceUrl=*
connectionsMap__0__audience=<teams-app-id>
```

**Available connection settings fields:**
`clientId`, `clientSecret`, `tenantId`, `authority`, `certPemFile`, `certKeyFile`, `sendX5C`, `connectionName`, `scope`

### Legacy format — backwards compatibility only

> **Never use the legacy format for new agents.** It exists solely for backwards compatibility with older BotFramework-based bots. Always use the modern `connections__` format above.

```
clientId=<your-app-id>
clientSecret=<your-secret>
tenantId=<your-tenant-id>
```

Both `startServer()` and `loadAuthConfigFromEnv()` auto-detect the format. Leave `clientId` blank locally to skip auth.

### OAuth authorization handler variables

These control the user sign-in flow configured via `authorization: { [id]: { ... } }`. The `id` is the key used in the authorization options (e.g. `graph`).

#### Modern format (recommended)

Uses the prefix `AgentApplication__UserAuthorization__Handlers__<id>__Settings__<property>`. Case-insensitive.

**AzureBot handler** (default — user OAuth flow via Azure Bot Service):
```
AgentApplication__UserAuthorization__Handlers__graph__Settings__azureBotOAuthConnectionName=GraphOAuthConnection
AgentApplication__UserAuthorization__Handlers__graph__Settings__title=Sign in with Microsoft
AgentApplication__UserAuthorization__Handlers__graph__Settings__text=Please sign in to continue
AgentApplication__UserAuthorization__Handlers__graph__Settings__invalidSignInRetryMax=3
AgentApplication__UserAuthorization__Handlers__graph__Settings__enableSso=false

# OBO (on-behalf-of) — auto-exchange on routes using exchangeToken()
AgentApplication__UserAuthorization__Handlers__graph__Settings__oboConnectionName=OBOConnection
AgentApplication__UserAuthorization__Handlers__graph__Settings__oboScopes=https://graph.microsoft.com/.default,Mail.Read

# Custom error messages
AgentApplication__UserAuthorization__Handlers__graph__Settings__invalidSignInRetryMessage=That code was invalid, please try again.
AgentApplication__UserAuthorization__Handlers__graph__Settings__invalidSignInRetryMessageFormat=Please enter the 6-digit code from the sign-in card.
AgentApplication__UserAuthorization__Handlers__graph__Settings__invalidSignInRetryMaxExceededMessage=Too many failed attempts. Please try again later.
```

**AgenticUserAuthorization handler** (agent-to-agent, no user prompt):
```
AgentApplication__UserAuthorization__Handlers__myHandler__Settings__type=AgenticUserAuthorization
AgentApplication__UserAuthorization__Handlers__myHandler__Settings__scopes=https://graph.microsoft.com/.default
AgentApplication__UserAuthorization__Handlers__myHandler__Settings__altBlueprintConnectionName=altConn
```

#### Legacy format (deprecated)

> **Do not use the legacy format for new agents.** It exists solely for backwards compatibility. The SDK emits deprecation warnings when legacy variables are detected.

| Legacy variable | Modern equivalent |
|---|---|
| `graph_connectionName` | `...Handlers__graph__Settings__azureBotOAuthConnectionName` |
| `graph_connectionTitle` | `...Handlers__graph__Settings__title` |
| `graph_connectionText` | `...Handlers__graph__Settings__text` |
| `graph_maxAttempts` | `...Handlers__graph__Settings__invalidSignInRetryMax` |
| `graph_enableSso` | `...Handlers__graph__Settings__enableSso` |
| `graph_obo_connection` | `...Handlers__graph__Settings__oboConnectionName` |
| `graph_obo_scopes` | `...Handlers__graph__Settings__oboScopes` |
| `graph_messages_invalidCode` | `...Handlers__graph__Settings__invalidSignInRetryMessage` |
| `graph_messages_invalidCodeFormat` | `...Handlers__graph__Settings__invalidSignInRetryMessageFormat` |
| `graph_messages_maxAttemptsExceeded` | `...Handlers__graph__Settings__invalidSignInRetryMaxExceededMessage` |
| `myHandler_type=agentic` | `...Handlers__myHandler__Settings__type=AgenticUserAuthorization` |
| `myHandler_scopes` | `...Handlers__myHandler__Settings__scopes` |
| `myHandler_altBlueprintConnectionName` | `...Handlers__myHandler__Settings__altBlueprintConnectionName` |

Priority when both formats are present: runtime options (code) > modern env vars > legacy env vars.

## Quick Start

```typescript
import { startServer } from '@microsoft/agents-hosting-express'
import { AgentApplication, MemoryStorage, TurnContext, TurnState } from '@microsoft/agents-hosting'

class MyAgent extends AgentApplication<TurnState> {
  constructor() {
    super({ storage: new MemoryStorage() })

    this.onConversationUpdate('membersAdded', async (ctx: TurnContext) => {
      await ctx.sendActivity('Hello! Send me a message.')
    })

    this.onActivity('message', async (ctx: TurnContext, state: TurnState) => {
      let coun
````

## File: README.md
upstream: https://github.com/microsoft/agents/blob/main/README.md

````text
# Microsoft 365 Agents SDK

With the Microsoft 365 Agents SDK, you can create agents deployable to channels of your choice, such as Microsoft 365 Copilot, Microsoft Teams, Web & Custom Apps and more, with scaffolding to handle the required communication. Developers can use the AI Services of their choice, and make the agents they build available using the channel management capabilities of the SDK.

Developers need the flexibility to integrate agents from any provider or technology stack into their enterprise systems. The Agents SDK simplifies the implementation of agentic patterns using the AI of their choice, allowing them to select one or more services, models, or agents to meet their specific requirements.

Use the Agents SDK to:

- Quickly build an agent 'container' with state, storage, and the ability to manage activities and events. Deploy this container across any channel, such as Microsoft 365 Copilot or Microsoft Teams.
- Implement agentic patterns without being restricted to a specific technology stack. The Agents SDK is agnostic regarding the AI you choose.
- Customize your agent to align with the specific behaviors of clients, such as Microsoft Teams.

## Get Started

You can get started right here by scolling up and clicking the 'samples' folder in this repo, selecting your language and reviewing the samples list before picking which one you want to start with (QuickStart is recommended for fundamentals).

Microsoft 365 Copilot is one of many channels supported by this SDK, and a *Microsoft 365 Copilot subscription is *not* required* to get started with or use this SDK unless your working specifically with that channel (or others, that require a subscription/service to use their client).

## C#, JavaScript, & Python Repository links

The source for the client libraries exists for the most part in repositories for each language. This repository is meant to be a jumping off point into those language specific repositories. Issues related to a specific language should be opened in the corresponding repository but cross cutting issues can be opened in this repository.

| Language            | Repo                           |
|:--------------------|:------------------------------:|
| General (This repo) | [Agents Repository]            |
| C# /.NET            | [Agents-for-net Repository]    |
| JavaScript          | [Agents-for-js Repository]     |
| Python              | [Agents-for-python Repository] |

## Agent Plugins (Skills)

The Agents SDK provides AI coding assistant plugins that give your assistant
deep knowledge of SDK APIs, patterns, and common mistakes. Skills activate
automatically based on the language and task you are working on.

The plugins are hosted in
[microsoft/Agents — agent-plugins](https://github.com/microsoft/Agents/tree/main/agent-plugins).

**Available plugins across the SDKs:**

| Plugin | SDKs | Skills Included |
|--------|------|-----------------|
| `agents-sdk-common` | All languages | Azure provisioning, identity credentials, and OAuth setup through the `az` CLI |
| `agents-for-js` | TypeScript/JavaScript | Building agents, debugging authentication and startup issues, and configuring OpenTelemetry observability |
| `agents-for-net` | C#/.NET | Building agents, debugging, OpenTelemetry observability, Bot Framework migration, and `ActivityHandler`-to-`AgentApplication` migration |
| `agents-for-python` | Python | Configuring and troubleshooting OpenTelemetry observability |

**Installation (GitHub Copilot CLI or Claude Code):**

```text
/plugin marketplace add microsoft/Agents
/plugin install agents-sdk-common@microsoft-agents-sdk
/plugin install agents-for-js@microsoft-agents-sdk
/plugin install agents-for-net@microsoft-agents-sdk
/plugin install agents-for-python@microsoft-agents-sdk
```

Install the common plugin and the plugins for the SDKs you use. Skills activate
automatically—no manual loading is needed. Run `/plugin` to verify installation.

## Documentation

To learn more about the Agents SDK, you can read our official docs here: [Agents SDK Documentation](https://aka.ms/M365-Agents-SDK-Docs)

The [configuration schema preview](schema/README.md) defines a canonical JSON
document for structural validation in downstream projects. It does not establish
runtime support or replace SDK-specific configuration loading.

## Related SDKs and Agent Platforms

- **Semantic Kernel**. [Semantic Kernel](https://learn.microsoft.com/en-us/semantic-kernel/overview/)
is an SDK that integrates Large Language Models (LLMs) like
[OpenAI](https://platform.openai.com/docs/introduction),
[Azure OpenAI](https://azure.microsoft.com/en-us/products/ai-services/openai-service),
and [Hugging Face](https://huggingface.co/)
with conventional programming languages like C#, Python, and Java. Semantic Kernel achieves this
by allowing you to define [plugins](https://learn.microsoft.com/en-us/semantic-kernel/concepts/plugins)
that can be chained together
in just a [few lines of code](https://learn.microsoft.com/en-us/semantic-kernel/ai-orchestration/chaining-functions?tabs=Csharp#using-the-runasync-method-to-simplify-your-code).

- **Azure AI Foundry**. Provides the core backend agent functionality, providing reasoning, retrieval augmentation, observability, among other core functions. Developers can leverage the Azure AI Agent Service or build their agent functionality with individual components from this SDK.

- **Copilot Studio**. Copilot Studio is an agent building platform that can be used with the Microsoft 365 Agents SDK to integrate your agent into your applications & create multi-agent patterns with Copilot Studio Agents. To get started, go to the samples folder in this repo and select the Copilot Studio Client sample in your chosen language.

The Microsoft 365 Agents SDK brings together core components to allow for developers to create, manage and utilize AI Services and third-party SDKs to power orchestration and develop custom agent logic functionality.

## Using other services with the Agents SDK

Your use of other services in connection with the Microsoft 365 Agents SDK is governed by the respective agreements for those services, which may include codes of conduct and other restrictions

## Contributing

### Note for Microsoft internal developers

- Internal Microsoft Developers should join the Core identity group [Agents SDK Contrib](https://coreidentity.microsoft.com/manage/Entitlement/entitlement/agentssdkint-upyj)

### Non-Microsoft developers

- 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.

## Recommended VS Code Extensions

To ensure a consistent development environment, we recommend using the following VS Code extensions:

|Extension | Description |
|----------|-------------|
|[ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)|Integrates [ESLint](https://eslint.org/) into VS Code. Allows you to find and fix problems in JavaScript code.|
|[GitHub Copilot Chat](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot-chat)|[GitHub Copilot](https://code.visualstudio.com/docs/copilot/overview) is an AI peer programming t
````
