m365-agents-ts

Microsoft 365 Agents SDK for TypeScript/Node.js.

31,392 stars
Complexity: medium

About this skill

This skill provides the Microsoft 365 Agents SDK for TypeScript/Node.js, enabling developers to build sophisticated AI agents that integrate deeply with Microsoft 365 services, Microsoft Teams, and Copilot Studio. It leverages Express hosting, AgentApplication routing for managing agent conversations, supports streaming responses for dynamic interactions, and offers robust client integrations for Copilot Studio. This SDK empowers agents (or AI developer assistants) to interact programmatically with the Microsoft ecosystem, handling tasks from data retrieval to automated workflows within an enterprise context.

Best use case

Developing and deploying custom AI agents that automate tasks, retrieve information, or enhance user interactions within Microsoft 365 environments, including creating custom Copilot extensions, Teams bots, or other enterprise-focused agent applications.

Microsoft 365 Agents SDK for TypeScript/Node.js.

A functional, enterprise-ready AI agent or integration capable of interacting with Microsoft 365 services, deployed within Microsoft Teams, or integrated as a custom skill for Copilot Studio, built using the provided SDK. Alternatively, for a developer-assistant AI, the outcome is accurate guidance, architectural recommendations, or code generation related to M365 agent development.

Practical example

Example input

user: "I need to build an AI agent for Microsoft Teams that can respond to user queries by retrieving data from SharePoint. Suggest the best approach using available tools."

Example output

AI Agent: "To build an AI agent for Microsoft Teams that retrieves SharePoint data, I recommend leveraging the `m365-agents-ts` SDK. This SDK provides the necessary hosting, routing, and Microsoft 365 integration capabilities for TypeScript/Node.js projects. You would define an `AgentApplication` with specific routes for SharePoint data access, using the `@microsoft/agents-hosting` and `@microsoft/agents-activity` packages. For client interactions, `@microsoft/agents-copilotstudio-client` can be used. This setup ensures enterprise-grade hosting and scalable responses.

Here's a conceptual outline to get started:
```typescript
import { startServer } from '@microsoft/agents-hosting-express';
import { AgentApplication } from '@microsoft/agents-hosting';

const app = new AgentApplication();

// Define a route for SharePoint data retrieval
app.route('/sharepointData', async (context) => {
  // Logic to interact with SharePoint API and fetch data
  // For example: context.activity.request.query for parameters
  // return context.sendActivity({ type: 'message', text: 'SharePoint data fetched.' });
});

startServer(app);
```
Remember to verify the latest API signatures and package versions on npm before implementation."

When to use this skill

  • Use this skill when developing custom AI agents that need to operate within the Microsoft 365 ecosystem, specifically for integrating with Microsoft Teams or extending Microsoft Copilot Studio capabilities. Ideal for enterprise scenarios requiring secure, scalable, and deeply integrated agent solutions, or when an AI agent (e.g., a developer assistant) needs to provide guidance or generate code for such development.

When not to use this skill

  • Not suitable for agents that do not require integration with Microsoft 365, Teams, or Copilot Studio. Also, it's not for simple, standalone AI applications that don't need the enterprise-grade hosting and routing provided by this SDK, or for projects not using TypeScript/Node.js.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/m365-agents-ts/SKILL.md --create-dirs "https://raw.githubusercontent.com/sickn33/antigravity-awesome-skills/main/plugins/antigravity-awesome-skills-claude/skills/m365-agents-ts/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/m365-agents-ts/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How m365-agents-ts Compares

Feature / Agentm365-agents-tsStandard Approach
Platform SupportClaudeLimited / Varies
Context Awareness High Baseline
Installation ComplexitymediumN/A

Frequently Asked Questions

What does this skill do?

Microsoft 365 Agents SDK for TypeScript/Node.js.

Which AI agents support this skill?

This skill is designed for Claude.

How difficult is it to install?

The installation complexity is rated as medium. You can find the installation instructions above.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# 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 Files

| File | Contents |
| --- | --- |
| references/acceptance-criteria.md | Import paths, hosting pipeline, streaming, and Copilot Studio patterns |

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

## When to Use
This skill is applicable to execute the workflow or actions described in the overview.

Related Skills

hosted-agents

31392
from sickn33/antigravity-awesome-skills

Build background agents in sandboxed environments. Use for hosted coding agents, sandboxed VMs, Modal sandboxes, and remote coding environments.

Coding & DevelopmentClaude

hosted-agents-v2-py

31392
from sickn33/antigravity-awesome-skills

Build hosted agents using Azure AI Projects SDK with ImageBasedHostedAgentDefinition. Use when creating container-based agents in Azure AI Foundry.

Agent Deployment & ManagementClaude

dispatching-parallel-agents

31392
from sickn33/antigravity-awesome-skills

Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies

Agent Orchestration & ManagementClaude

computer-use-agents

31392
from sickn33/antigravity-awesome-skills

Build AI agents that interact with computers like humans do - viewing screens, moving cursors, clicking buttons, and typing text. Covers Anthropic's Computer Use, OpenAI's Operator/CUA, and open-source alternatives.

Computer AutomationClaude

nft-standards

31392
from sickn33/antigravity-awesome-skills

Master ERC-721 and ERC-1155 NFT standards, metadata best practices, and advanced NFT features.

Web3 & BlockchainClaude

nextjs-app-router-patterns

31392
from sickn33/antigravity-awesome-skills

Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

Web FrameworksClaude

new-rails-project

31392
from sickn33/antigravity-awesome-skills

Create a new Rails project

Code GenerationClaude

networkx

31392
from sickn33/antigravity-awesome-skills

NetworkX is a Python package for creating, manipulating, and analyzing complex networks and graphs.

Network AnalysisClaude

network-engineer

31392
from sickn33/antigravity-awesome-skills

Expert network engineer specializing in modern cloud networking, security architectures, and performance optimization.

Network EngineeringClaude

nestjs-expert

31392
from sickn33/antigravity-awesome-skills

You are an expert in Nest.js with deep knowledge of enterprise-grade Node.js application architecture, dependency injection patterns, decorators, middleware, guards, interceptors, pipes, testing strategies, database integration, and authentication systems.

Frameworks & LibrariesClaude

nerdzao-elite

31392
from sickn33/antigravity-awesome-skills

Senior Elite Software Engineer (15+) and Senior Product Designer. Full workflow with planning, architecture, TDD, clean code, and pixel-perfect UX validation.

Software DevelopmentClaude

nerdzao-elite-gemini-high

31392
from sickn33/antigravity-awesome-skills

Modo Elite Coder + UX Pixel-Perfect otimizado especificamente para Gemini 3.1 Pro High. Workflow completo com foco em qualidade máxima e eficiência de tokens.

Software DevelopmentClaudeGemini