This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the Microsoft 365 Agents SDK for JavaScript/TypeScript (formerly known as BotFramework SDK v5). It provides a comprehensive framework for building enterprise-grade conversational agents that work across M365, Teams, Copilot Studio, Webchat, and other platforms.
The repository is a monorepo using npm workspaces with multiple interconnected packages.
- agents-activity: Activity protocol types, validators, and schema definitions using Zod. Replaces
botframework-schema. - agents-hosting: Core hosting components including ActivityHandler, TurnContext, CloudAdapter, authentication, and state management. Replaces
botbuilder. - agents-hosting-express: Express.js integration for hosting agents.
- agents-hosting-dialogs: Dialog system for building conversational flows. Replaces
botbuilder-dialogs. - agents-hosting-extensions-teams: Teams-specific features (TaskModules, Messaging Extensions).
- agents-hosting-storage-blob: Azure Blob Storage adapter. Replaces
botbuilder-azure. - agents-hosting-storage-cosmos: CosmosDB storage adapter. Replaces
botbuilder-azure. - agents-copilotstudio-client: Direct-to-Engine client for interacting with Copilot Studio agents.
Sample agents used for internal testing ("samples"). For learning examples, refer to https://github.com/Microsoft/Agents.
# Build all packages using TypeScript project references
npm run build
# Clean dist directories and rebuild
npm run build:clean
# Build sample test agents
npm run build:samples
# Build browser bundles (runs automatically after build)
npm run build:browserBuild Process: Uses TypeScript project references defined in tsconfig.build.json. Each package builds independently but respects dependencies through references.
# Run all tests using Node's built-in test runner
npm test
# Run a single test file
node --test --import tsx packages/agents-activity/test/exceptionHelper.test.ts
# Run tests for a specific package
node --test --import tsx 'packages/agents-activity/test/**/*.test.ts'Test Framework: Uses Node.js built-in node:test module with tsx for TypeScript support. Test files follow the pattern **/*.test.ts and use describe/it syntax.
# Run eslint on all files
npm run lint
# Lint a specific file
npx eslint packages/agents-activity/src/index.tsLinting: Uses neostandard ESLint configuration with TypeScript support.
# Generate API documentation using TypeDoc
npm run docs# Check API compatibility
npm run compat
# Launch agents playground (interactive testing tool)
npm run playThe package dependency hierarchy (simplified):
agents-activity(base layer - no internal dependencies)agents-hosting(depends onagents-activity)agents-hosting-express(depends onagents-hosting)agents-hosting-dialogs(depends onagents-hosting)- Storage and extension packages (depend on
agents-hosting)
Activity Protocol: All communication uses the Activity schema defined in agents-activity. Activities are validated using Zod schemas and can be created with Activity.fromObject().
TurnContext: Represents a single turn of conversation. Provides access to the activity, state, and methods to send responses. Created by the adapter for each incoming activity.
ActivityHandler: Base class for handling different activity types (message, conversationUpdate, etc.). Provides event-based hooks like onMessage, onConversationUpdate.
AgentApplication: Modern application-style API for building agents. Provides a higher-level abstraction over ActivityHandler with built-in state management, routing, and AI integration capabilities.
CloudAdapter: Processes incoming HTTP requests, authenticates them, and creates TurnContext. Handles the communication with channels.
Storage: Abstraction for persisting state (conversation, user, private). Implementations exist for Memory, Blob, and Cosmos.
Authentication configuration is loaded from environment variables using loadAuthConfigFromEnv(). The SDK supports:
- JWT authentication with JWKS validation
- Microsoft Entra ID (formerly Azure AD) authentication
- Bot Framework authentication
- Copilot Studio authentication (for
agents-copilotstudio-client)
Use authorizeJWT() middleware for Express applications to validate incoming requests.
Important: This project uses ES6 modules ("type": "module" in package.json). All imports must use explicit file extensions in the built output, and the code targets Node.js 20+.
- Target: ES2019 with ES2022 lib
- Module: node16 (ESM)
- Strict mode: Enabled
- Project References: Used for incremental builds
- Source Maps: Generated for debugging
Each package has its own tsconfig.json that extends the root configuration.
- Use Node's built-in
node:testmodule (import fromnode:test) - Use
assertfrom the standard library - Place tests in
test/directory within each package - Name test files with
.test.tssuffix - Tests run with
tsxfor TypeScript support
import { ActivityHandler, TurnContext } from '@microsoft/agents-hosting'
export class MyBot extends ActivityHandler {
constructor() {
super()
this.onMessage(async (context: TurnContext, next) => {
await context.sendActivity(`You said: ${context.activity.text}`)
await next()
})
}
}import { AgentApplication, TurnContext, TurnState } from '@microsoft/agents-hosting'
const app = new AgentApplication<TurnState>({ storage: new MemoryStorage() })
app.onActivity('message', async (context: TurnContext, state: TurnState) => {
const counter = state.getValue('conversation.counter') || 0
await context.sendActivity(`[${counter}] You said: ${context.activity.text}`)
state.setValue('conversation.counter', counter + 1)
})The client requires a JWT token and ConnectionSettings (environment ID + agent schema name, or direct connect URL). See packages/agents-copilotstudio-client/README.md for detailed setup including Azure app registration requirements.
- Main branch:
main - Feature branches: Typically
users/<alias>/<feature-name> - Release branches:
release/* - CI runs on PRs to
mainandrelease/*branches
The CI pipeline (.github/workflows/ci.yml) runs:
- npm ci (clean install)
- npm run lint
- npm run build
- npm test
- npm run build:samples
- node setVersion.js (version management)
Requires Node.js 20+. The repo uses Node 24 features like --env-file flag for loading .env files without the dotenv package.
Test agents and samples load configuration from .env files using Node's --env-file flag. Common variables include authentication settings (app ID, password, tenant ID) and service endpoints.
Packages are published to npm under the @microsoft scope. Nightly builds are available with the @next tag.