Agents-for-js
CLAUDE.md90 starsChanged 12 months agoMITView on GitHub
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. Sample agents used for internal testing ("samples"). For learning examples, refer to https://github.com/Microsoft/Agents. Build Process: Uses TypeScript project references defined in tsconfig.build.json. Each package builds independently but respects dependencies through references. Test…
- Reads credentials
In this repositoryOne other file it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
The file
We split this CLAUDE.md into the rules it gives an agent
10 rules. About 0 are common, 0 are distinctive, and 10 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 100
Run npm run repo:doctor after structural, package, documentation, build-reference, dependency, API-baseline, test-agent, Docker, or …
- Very specific: line 102
Do not use implicit npm lifecycle wrappers such as prebuild, postbuild, pretest, or posttest.
- Very specific: line 117
Activity Protocol: All communication uses the Activity schema defined in agents-activity.
- Very specific: line 138
Use TeamsAgentExtension.getTeamsClient(context) for Teams SDK client access.
- Very specific: line 154
Use authorizeJWT() middleware for Express applications to validate incoming requests.
- Very specific: line 172
Use Node's built-in node:test module (import from node:test)
- Very specific: line 173
Use assert from the standard library
- Very specific: line 174
Place tests in test/ directory within each package
- Very specific: line 177
Do not leave a TypeScript cast (as or angle-bracket assertion) in a test callback's final executable statement.
- Very specific: line 256
Test agents and samples load configuration from .env files using Node's --env-file flag.
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
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.
Repository Structure
Core Packages (in 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-fastify: Fastify integration for hosting agents.
- agents-hosting-dialogs: Dialog system for building conversational flows. Replaces
botbuilder-dialogs. - agents-hosting-directline-namedpipes: Direct Line transport over named pipes.
- agents-hosting-extensions-msteams: Teams-specific features (TaskModules, Messaging Extensions).
- agents-hosting-extensions-slack: Slack-specific integration and extensions.
- agents-hosting-extensions-teams: Deprecated legacy Teams extension retained for backward compatibility.
- 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.
- agents-telemetry: Shared telemetry instrumentation for Microsoft 365 Agents SDK packages.
Test Agents (in test-agents/)
Sample agents used for internal testing ("samples"). For learning examples, refer to https://github.com/Microsoft/Agents.
Common Development Commands
Building
# 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.
Testing
# 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.
Linting
# 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.
Documentation
# Generate API documentation using TypeDoc
npm run docsOther Commands
# Check repository structure, package metadata, documentation, and runtime configuration
npm run repo:doctor
# Check API compatibility
npm run compat
# Launch agents playground (interactive testing tool)
npm run playRun npm run repo:doctor after structural, package, documentation, build-reference, dependency, API-baseline, test-agent, Docker, or runtime-configuration changes. Every diagnostic includes a rule ID and a concrete fix instruction.
Do not use implicit npm lifecycle wrappers such as prebuild, postbuild, pretest, or posttest. npm --ignore-scripts skips these hooks, so required work must be explicit. Install-time hooks (preinstall, install, postinstall, and prepare) are prohibited. Put dependent work directly in the explicit command, for example npm run build && node ....
Key Architecture Concepts
Package Dependencies
The 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)
Core Abstractions
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.
Teams Extension (Teams SDK Migration)
The agents-hosting-extensions-msteams package aligns with the Teams SDK-based architecture used in .NET. The legacy agents-hosting-extensions-teams package remains in the workspace for backward compatibility, but is deprecated and should not be used for new development.
- Teams SDK dependency: Uses
@microsoft/teams.api(2.0.14) for Teams models and client operations. - Legacy API isolation:
TeamsConnectorClient,TeamsActivityHandler,TeamsInfo, and the local Teams-specific model wrappers remain available only from the deprecatedagents-hosting-extensions-teamspackage. - Shared Teams client setup: Teams client setup/retrieval for the new package is implemented in
packages/agents-hosting-extensions-msteams/src/teamsApiClientExtensions.ts. - Turn setup requirements:
TeamsAgentExtensionregisters abeforeTurnhandler that configures the Teams client forAgentApplicationscenarios.- Use
TeamsAgentExtension.getTeamsClient(context)for Teams SDK client access.
- Error handling:
- Missing client access throws
TeamsApiClientNotAvailable. - Teams client setup prerequisites throw
TeamsApiClientSetupFailed(for easier misconfiguration diagnosis).
- Missing client access throws
- Parsing simplification:
- Teams channel data parsing was simplified to root-object validation/pass-through (
activity-extensions/teamsChannelData.ts). - Messaging extension query parsing remains validated via a Zod schema (
messageExtensions/messagingExtensionQuery.ts).
- Teams channel data parsing was simplified to root-object validation/pass-through (
Authentication
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.
Module System
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+.
TypeScript Configuration
- 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.
Testing Guidelines
- 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 - Do not leave a TypeScript cast (
asor angle-bracket assertion) in a test callback's final executable statement. The VS Codenode:testextension uses a loose parser for TypeScript; assign the cast result to a typed local earlier in the callback instead.
Common Patterns
Creating an Agent with ActivityHandler
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()
})
}
}Creating an Agent with AgentApplication
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)
})Using Copilot Studio Client
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.
Error Handling Pattern
Across all packages in this repo, thrown errors must use ExceptionHelper.generateException() with a predefined entry from an Errors constant — never use throw new Error(...) or throw new TypeError(...) directly.
// Import pattern
import { ExceptionHelper } from '@microsoft/agents-activity'
import { Errors } from '../errorHelper' // adjust relative path per package
// Usage
throw ExceptionHelper.generateException(Error, Errors.SomeErrorKey)
throw ExceptionHelper.generateException(TypeError, Errors.SomeErrorKey)
// With template substitution (description uses {key} placeholders)
throw ExceptionHelper.generateException(Error, Errors.SomeErrorKey, undefined, { key: value })
// With inner exception
throw ExceptionHelper.generateException(Error, Errors.SomeErrorKey, originalError)Each package keeps its error definitions in a local errorHelper.ts (e.g. packages/agents-hosting/src/errorHelper.ts) as AgentErrorDefinition entries with a unique numeric code, a description, and an optional helplink. When adding new errors, continue the numeric sequence in the appropriate range for the subsystem. Code reviews should flag any raw throw new Error that bypasses this pattern.
Git Workflow
- Main branch:
main - Feature branches: Typically
users/<alias>/<feature-name> - Release branches:
release/* - CI runs on PRs to
mainandrelease/*branches
CI/CD
The CI pipeline (.github/workflows/ci.yml) runs:
- npm ci (clean install)
- npm run quality (doctor, lint, dependency lint, build, tests, compatibility, and samples; logs are folded in GitHub Actions and retained as a seven-day
quality-logsartifact) - node scripts/set-version.mjs (version management)
Node Version
Requires Node.js 20+. The repo uses Node 24 features like --env-file flag for loading .env files without the dotenv package.
Environment Variables
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.
Package Publishing
Packages are published to npm under the @microsoft scope. Nightly builds are available with the @next tag.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

