Share via


Quickstart: Set up and run the JavaScript LangChain sample agent

In this Quickstart, walk through setting up a working JavaScript LangChain agent using Agent 365 tooling, notifications, observability, and testing the agent using Agents Playground and Teams.

Prerequisites

Set up the LangChain + Node.js sample from the Microsoft 365 Agents Toolkit

To get everything ready, you install the Microsoft 365 Agents Toolkit in VS Code, open the sample gallery, and scaffold the LangChain + Node.js sample locally so you can configure and run it later. The following screenshots show what you should expect to see as you go.

  1. Open Visual Studio Code, then open the Extensions panel Ctrl+Shift+X.

  2. In the search bar, type "Agents Toolkit".
    You should see the result shown in the screenshot here:

    Screenshot of Extensions Marketplace search for Agents Toolkit.

  3. Select Microsoft 365 Agents Toolkit.

  4. Select Install.

    VS Code shows the extension details view similar to:

    Screenshot of Extension details page with Install and Enable buttons.

  5. Once installed, the M365 Agents Toolkit icon appears in the left navigation bar.

  6. Select it to open the welcome experience.

    You should now see options like Build a Declarative Agent, Create a New Agent/App, and View Samples, as shown here:

    Screenshot of Toolkit Welcome View with Build a Declarative Agent, Create a New Agent or App, and View Samples options.

  7. Select View Samples.

  8. In the samples list, scroll to find the LangChain + Node.js agent sample.

  9. Select it.

    You will see two choices: Create (scaffold locally) or View on GitHub.

  10. Choose Create.

  11. When prompted, select a folder on your machine where the sample should be generated. For example: C:\A365-Ignite-Demo

    The toolkit scaffolds the LangChain + Node.js sample into a subfolder (such as sample_agent) and then open it automatically in VS Code.

    Once scaffolding completes, you now have a fully functional LangChain + Node.js agent project on your machine

Install required Agent 365 packages

Before running the sample, open the package.json in your project and confirm that all required Agent 365 and Agent framework dependencies are listed. The sample generated by the Microsoft 365 Agents Toolkit already includes these entries.

Once you've reviewed the package.json, install everything by running:

npm install

This pulls down all Agent 365 libraries, Agent framework dependencies, hosting components, and any other dependencies defined in the sample. After installation, verify the project builds and runs by starting the dev server

npm run dev

Add Microsoft 365 tools (MCP servers)

You can explore and manage MCP servers using the a365 develop commands in the CLI.

When working with MCP servers, you can:

  • Discover which MCP servers are available for use
  • Add one or more MCP servers to your agent's configuration
  • Review the MCP servers currently configured
  • Remove MCP servers you no longer need

After MCP servers are added, your agent's tooling manifest expands to include entries similar to:

{
   "mcpServers": [
      {
         "mcpServerName": "mcp_MailTools",
         "mcpServerUniqueName": "mcp_MailTools",
         "scope": "McpServers.Mail.All",
         "audience": "api://00001111-aaaa-2222-bbbb-3333cccc4444"
      }
   ]
}

Learn how to add and manage tools

Notification subscription and handling

The sample agent subscribes to all Agent 365 notifications using onAgentNotification("*") and routes them to a single handler. This handler allows the agent to react to background or system events, not just direct user messages.

Learn how to notify agents

The following code shows how notification is configured in the agent.ts file.

constructor() {
   super();

   this.onAgentNotification("agents:*", async(context, state, activity) => {

      await this.handleAgentNotificationActivity(context, state, activity);

   });
}

async handleAgentNotificationActivity(context, state, activity)
{
   await context.sendActivity("Received an AgentNotification!");

   // Add custom handling here
}

Observability

This snippet shows the minimal changes needed to enable observability in the sample. It initializes the Agent 365 Observability SDK and wraps each agent invocation in an InferenceScope so inputs, outputs, and metadata can be captured automatically.

The following code shows a streamlined observability example in the client.ts file.

const sdk = ObservabilityManager.configure(b =>
   b.withService('<service-name>', '<version>')
);

sdk.start();

async invokeAgentWithScope(prompt: string) {

   const scope = InferenceScope.start(
      { 
         operationName: InferenceOperationType.CHAT, 
         model: '<llm-name>' 
      },
      { 
         agentId: '<agent-id>', 
         agentName: '<agent-name>', 
         conversationId: '<conv-id>' 
      },
      { tenantId: '<tenant-id>' }
   );

   const response = await this.invokeAgent(prompt);
   scope?.recordInputMessages([prompt]);
   scope?.recordOutputMessages([response]);
   scope?.recordResponseId(`resp-${Date.now()}`);
   return response;

}

This snippet shows the core pattern for enabling observability in the Node.js + LangChain sample. For the complete observability setup see Learn more about observability

Test your agent

Set the required environment variables, select an authentication mode, and start the agent locally. You can test everything end-to-end with Agents Playground without needing a Microsoft 365 tenant unless you want to publish the agent and use it in apps like Teams or Outlook. Please refer to for detailed steps in Learn more about testing to configure testing the agent with agents playground.

Testing steps overview

  • Add your API keys and model settings to a .env file so the sample can talk to an LLM.
  • Choose your authentication mode. For local development, the sample supports Agentic Auth using values created from your Agent Blueprint.
  • Start the agent locally, which exposes it to tools like the Agents Playground.
  • Use Agents Playground to test messages, tools, and notifications without setting up a tenant or deploying anything.
  • When you're ready for real-world behavior, publish a Microsoft 365 tenant and test the agent inside Teams, Outlook, or other Microsoft 365 surfaces.

Publish your agent

When your agent is ready for actual Microsoft 365 experiences like Teams chats, Outlook messages, Word @mentions, you publish it to a Microsoft 365 tenant. The Agent 365 CLI publish command handles the packaging: it updates your manifest, bundles everything, and uploads the agent to the Microsoft Admin Center.

During publishing, review and customize the agent's name, description, icons, and version before completing the upload. Once published, your agent becomes discoverable and installable inside the tenant.

You can view published agents here: https://admin.cloud.microsoft/#/agents/all

Learn more about the full workflow and step-by-step instructions