Option
HeimHeim Skill API-Entwicklung m365-agents-ts

m365-agents-ts

microsoft/skills microsoft/skills

Erstellen Sie Enterprise-Agenten für Microsoft 365, Teams und Copilot Studio mithilfe des Microsoft 365 Agents SDK mit Express-Hosting, AgentApplication-Routing, Streaming-Antworten und Copilot Studio Client-Integrationen.

...Alle erweitern
4
Zeit aktualisiert 12. September 2026

Microsoft 365 Agents SDK (TypeScript)

Erstellen Sie Unternehmensagenten für Microsoft 365, Teams und Copilot Studio mithilfe der Microsoft 365 Agents SDK mit Express-Hosting, AgentApplication-Routing, Streaming-Antworten und Copilot Studio-Client-Integrationen.

Vor der Implementierung

  • Verwenden Sie das microsoft-docs MCP, um die neuesten API-Signaturen für AgentApplication, startServer und CopilotStudioClient zu überprüfen.
  • Bestätigen Sie die Paketversionen auf npm, bevor Sie Beispiele oder Vorlagen verdrahten.

Installation

npm install @microsoft/agents-hosting @microsoft/agents-hosting-express @microsoft/agents-activity
npm install @microsoft/agents-copilotstudio-client

Umgebungsvariablen

PORT=3978
AZURE_RESOURCE_NAME=<azure-openai-resource>
AZURE_API_KEY=<azure-openai-key>
AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4o-mini

TENANT_ID=<tenant-id>
CLIENT_ID=<client-id>
CLIENT_SECRET=<client-secret>

COPILOT_ENVIRONMENT_ID=<environment-id>
COPILOT_SCHEMA_NAME=<schema-name>
COPILOT_CLIENT_ID=<copilot-app-client-id>
COPILOT_BEARER_TOKEN=<copilot-jwt></copilot-jwt></copilot-app-client-id></schema-name></environment-id></client-secret></client-id></tenant-id></azure-openai-key></azure-openai-resource>

Kernworkflow: Express-gehosteter AgentApplication

import {
  AgentApplication,
  TurnContext,
  TurnState,
} from "@microsoft/agents-hosting";
import { startServer } from "@microsoft/agents-hosting-express";

const agent = new AgentApplication<turnstate>();

agent.onConversationUpdate("membersAdded", async (context: TurnContext) => {
  await context.sendActivity("Willkommen beim Agenten.");
});

agent.onMessage("hello", async (context: TurnContext) => {
  await context.sendActivity(`Echo: ${context.activity.text}`);
});

startServer(agent);
</turnstate>

Streaming-Antworten mit Azure OpenAI

import { azure } from "@ai-sdk/azure";
import {
  AgentApplication,
  TurnContext,
  TurnState,
} from "@microsoft/agents-hosting";
import { startServer } from "@microsoft/agents-hosting-express";
import { streamText } from "ai";

const agent = new AgentApplication<turnstate>();

agent.onMessage("poem", async (context: TurnContext) => {
  context.streamingResponse.setFeedbackLoop(true);
  context.streamingResponse.setGeneratedByAILabel(true);
  context.streamingResponse.setSensitivityLabel({
    type: "https://schema.org/Message",
    "@type": "CreativeWork",
    name: "Intern",
  });

  await context.streamingResponse.queueInformativeUpdate("ein Gedicht wird erstellt...");

  const { fullStream } = streamText({
    model: azure(process.env.AZURE_OPENAI_DEPLOYMENT_NAME || "gpt-4o-mini"),
    system: "Sie sind ein kreativer Assistent.",
    prompt: "Schreiben Sie ein Gedicht über Apollo.",
  });

  try {
    for await (const part of fullStream) {
      if (part.type === "text-delta" && part.text.length > 0) {
        await context.streamingResponse.queueTextChunk(part.text);
      }
      if (part.type === "error") {
        throw new Error(`Streaming-Fehler: ${part.error}`);
      }
    }
  } finally {
    await context.streamingResponse.endStream();
  }
});

startServer(agent);
</turnstate>

Verarbeitung von Invoke-Aktivitäten

import { Activity, ActivityTypes } from "@microsoft/agents-activity";
import {
  AgentApplication,
  TurnContext,
  TurnState,
} from "@microsoft/agents-hosting";

const agent = new AgentApplication<turnstate>();

agent.onActivity("invoke", async (context: TurnContext) => {
  const invokeResponse = Activity.fromObject({
    type: ActivityTypes.InvokeResponse,
    value: { status: 200 },
  });

  await context.sendActivity(invokeResponse);
  await context.sendActivity("Danke, dass Sie Ihr Feedback eingereicht haben.");
});
</turnstate>

Copilot Studio-Client (Direkt zur Engine)

import { CopilotStudioClient } from "@microsoft/agents-copilotstudio-client";

const settings = {
  environmentId: process.env.COPILOT_ENVIRONMENT_ID!,
  schemaName: process.env.COPILOT_SCHEMA_NAME!,
  clientId: process.env.COPILOT_CLIENT_ID!,
};

const tokenProvider = async (): Promise<string> => {
  return process.env.COPILOT_BEARER_TOKEN!;
};

const client = new CopilotStudioClient(settings, tokenProvider);

const conversation = await client.startConversationAsync();
const reply = await client.askQuestionAsync("Hallo!", conversation.id);
console.log(reply);
</string>

Copilot Studio WebChat-Integration

import { CopilotStudioWebChat } from "@microsoft/agents-copilotstudio-client";

const directLine = CopilotStudioWebChat.createConnection(client, {
  showTyping: true,
});

window.WebChat.renderWebChat(
  {
    directLine,
  },
  document.getElementById("webchat")!,
);

Best Practices

  1. Verwenden Sie AgentApplication für das Routing und halten Sie Handler auf eine einzige Verantwortung fokussiert.
  2. Bevorzugen Sie streamingResponse für langandauernde Vervollständigungen und rufen Sie endStream in finally-Blöcken auf.
  3. Halten Sie Geheimnisse aus dem Quellcode; laden Sie Token aus Umgebungsvariablen oder sicheren Speichern.
  4. Wiederverwenden Sie CopilotStudioClient-Instanzen und zwischenspeichern Sie Token in Ihrem Token-Provider.
  5. Validieren Sie Invoke-Payloads, bevor Sie Feedback protokollieren oder speichern.

Referenzlinks

RessourceURL
Microsoft 365 Agents SDKhttps://learn.microsoft.com/en-us/microsoft-365/agents-sdk/
JavaScript SDK-Übersichthttps://learn.microsoft.com/en-us/javascript/api/overview/agents-overview?view=agents-sdk-js-latest
@microsoft/agents-hosting-expresshttps://learn.microsoft.com/en-us/javascript/api/%40microsoft/agents-hosting-express?view=agents-sdk-js-latest
@microsoft/agents-copilotstudio-clienthttps://learn.microsoft.com/en-us/javascript/api/%40microsoft/agents-copilotstudio-client?view=agents-sdk-js-latest
Integration mit Copilot Studiohttps://learn.microsoft.com/en-us/microsoft-365/agents-sdk/integrate-with-mcs
GitHub-Beispielehttps://github.com/microsoft/Agents/tree/main/samples/nodejs
Auf GitHub ansehen
---
name: m365-agents-ts
description: Build enterprise agents for Microsoft 365, Teams, and Copilot Studio using the Microsoft 365 Agents SDK with Express hosting, AgentApplication routing, streaming responses, and Copilot Studio client integrations.
license: MIT
---

# Microsoft 365 Agents SDK (TypeScript)

Build enterprise agents for Microsoft 365, Teams, and Copilot Studio using the Microsoft 365 Agents SDK with Express hosting, AgentApplication routing, streaming responses, and Copilot Studio client integrations.

## Before implementation

- Use the microsoft-docs MCP to verify the latest API signatures for AgentApplication, startServer, and CopilotStudioClient.
- Confirm package versions on npm before wiring up samples or templates.

## Installation

```bash
npm install @microsoft/agents-hosting @microsoft/agents-hosting-express @microsoft/agents-activity
npm install @microsoft/agents-copilotstudio-client
```

## Environment Variables

```bash
PORT=3978
AZURE_RESOURCE_NAME=<azure-openai-resource>
AZURE_API_KEY=<azure-openai-key>
AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4o-mini

TENANT_ID=<tenant-id>
CLIENT_ID=<client-id>
CLIENT_SECRET=<client-secret>

COPILOT_ENVIRONMENT_ID=<environment-id>
COPILOT_SCHEMA_NAME=<schema-name>
COPILOT_CLIENT_ID=<copilot-app-client-id>
COPILOT_BEARER_TOKEN=<copilot-jwt>
```

## Core Workflow: Express-hosted AgentApplication

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

const agent = new AgentApplication<TurnState>();

agent.onConversationUpdate("membersAdded", async (context: TurnContext) => {
  await context.sendActivity("Welcome to the agent.");
});

agent.onMessage("hello", async (context: TurnContext) => {
  await context.sendActivity(`Echo: ${context.activity.text}`);
});

startServer(agent);
```

## Streaming responses with Azure OpenAI

```typescript
import { azure } from "@ai-sdk/azure";
import {
  AgentApplication,
  TurnContext,
  TurnState,
} from "@microsoft/agents-hosting";
import { startServer } from "@microsoft/agents-hosting-express";
import { streamText } from "ai";

const agent = new AgentApplication<TurnState>();

agent.onMessage("poem", async (context: TurnContext) => {
  context.streamingResponse.setFeedbackLoop(true);
  context.streamingResponse.setGeneratedByAILabel(true);
  context.streamingResponse.setSensitivityLabel({
    type: "https://schema.org/Message",
    "@type": "CreativeWork",
    name: "Internal",
  });

  await context.streamingResponse.queueInformativeUpdate("starting a poem...");

  const { fullStream } = streamText({
    model: azure(process.env.AZURE_OPENAI_DEPLOYMENT_NAME || "gpt-4o-mini"),
    system: "You are a creative assistant.",
    prompt: "Write a poem about Apollo.",
  });

  try {
    for await (const part of fullStream) {
      if (part.type === "text-delta" && part.text.length > 0) {
        await context.streamingResponse.queueTextChunk(part.text);
      }
      if (part.type === "error") {
        throw new Error(`Streaming error: ${part.error}`);
      }
    }
  } finally {
    await context.streamingResponse.endStream();
  }
});

startServer(agent);
```

## Invoke activity handling

```typescript
import { Activity, ActivityTypes } from "@microsoft/agents-activity";
import {
  AgentApplication,
  TurnContext,
  TurnState,
} from "@microsoft/agents-hosting";

const agent = new AgentApplication<TurnState>();

agent.onActivity("invoke", async (context: TurnContext) => {
  const invokeResponse = Activity.fromObject({
    type: ActivityTypes.InvokeResponse,
    value: { status: 200 },
  });

  await context.sendActivity(invokeResponse);
  await context.sendActivity("Thanks for submitting your feedback.");
});
```

## Copilot Studio client (Direct to Engine)

```typescript
import { CopilotStudioClient } from "@microsoft/agents-copilotstudio-client";

const settings = {
  environmentId: process.env.COPILOT_ENVIRONMENT_ID!,
  schemaName: process.env.COPILOT_SCHEMA_NAME!,
  clientId: process.env.COPILOT_CLIENT_ID!,
};

const tokenProvider = async (): Promise<string> => {
  return process.env.COPILOT_BEARER_TOKEN!;
};

const client = new CopilotStudioClient(settings, tokenProvider);

const conversation = await client.startConversationAsync();
const reply = await client.askQuestionAsync("Hello!", conversation.id);
console.log(reply);
```

## Copilot Studio WebChat integration

```typescript
import { CopilotStudioWebChat } from "@microsoft/agents-copilotstudio-client";

const directLine = CopilotStudioWebChat.createConnection(client, {
  showTyping: true,
});

window.WebChat.renderWebChat(
  {
    directLine,
  },
  document.getElementById("webchat")!,
);
```

## Best Practices

1. Use AgentApplication for routing and keep handlers focused on one responsibility.
2. Prefer streamingResponse for long-running completions and call endStream in finally blocks.
3. Keep secrets out of source code; load tokens from environment variables or secure stores.
4. Reuse CopilotStudioClient instances and cache tokens in your token provider.
5. Validate invoke payloads before logging or persisting feedback.

## Reference Links

| Resource                               | URL                                                                                                                 |
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| Microsoft 365 Agents SDK               | https://learn.microsoft.com/en-us/microsoft-365/agents-sdk/                                                         |
| JavaScript SDK overview                | https://learn.microsoft.com/en-us/javascript/api/overview/agents-overview?view=agents-sdk-js-latest                 |
| @microsoft/agents-hosting-express      | https://learn.microsoft.com/en-us/javascript/api/%40microsoft/agents-hosting-express?view=agents-sdk-js-latest      |
| @microsoft/agents-copilotstudio-client | https://learn.microsoft.com/en-us/javascript/api/%40microsoft/agents-copilotstudio-client?view=agents-sdk-js-latest |
| Integrate with Copilot Studio          | https://learn.microsoft.com/en-us/microsoft-365/agents-sdk/integrate-with-mcs                                       |
| GitHub samples                         | https://github.com/microsoft/Agents/tree/main/samples/nodejs                                                        |

Alle Dateien

0 Dateien

m365-agents-ts installieren

Laden Sie die Skill-Dateien herunter und extrahieren Sie diese in Ihr .claude/skills/-Verzeichnis.

ZIP herunterladen

Klonen Sie das Repository und kopieren Sie die Skill-Dateien in Ihr Projekt.

git clone https://github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-typescript/skills/m365-agents-ts # Copy SKILL.md to your .claude/skills/ directory

Kopieren Kopieren
Schnelle Einrichtung: Kopieren Sie den Ordner „skill“ nach .claude/skills/. Claude erkennt und verwendet die Fähigkeit automatisch.
Repository microsoft/skills

Ähnliche Skills

brightdata-cli
Zeit aktualisiert 29. Juni 2026
humanize
Zeit aktualisiert 7. Juli 2026
agentwallet
Zeit aktualisiert 7. Juli 2026
korean-stock-search
Zeit aktualisiert 8. Juli 2026
OR