Freigeben über


Structure of an Echobot agent (preview)

[This article is prerelease documentation and is subject to change.]

One of the best and easiest ways to get started with the Microsoft 365 Agents SDK is to use the EchoBot.cs sample in C#. You can access the samples in the Agents SDK sample repo.

The appsettings.json file specifies the configuration information for your agent, such as its app ID. If you're using certain technologies or using this agent in production, you need to add your specific keys or URL to this configuration. However, for this Echobot agent, you don't need to do anything here for the moment. The app ID and password can be left undefined at this time.

The EchoBot.csproj file specifies dependencies and their associated versions for your agent. You should have the required files from the Echobot agent sample. Other dependencies can be installed using NuGet package manager or the dotnet add package command.

Overview

The Echobot agent can be broken down into three parts:

  • Program.cs
  • BotController.cs
  • EchoBot.cs

Resource provisioning

Where StartUp.cs was used previously, Program.cs is now used in .NET 5 or later. The Program.cs file is where the connected services and any keys from appsettings.json are loaded from when the builder object for the web application is created. This process configures the application according to your settings.

Messaging endpoint

The template implements a web service with a messaging endpoint. When it receives a request, the service extracts the authentication header and request payload and forwards them to the adapter.

Each incoming request represents the start of a new turn.

The Bot adapter

The adapter receives activities from the messaging endpoint, and forwards them to the agent's turn handler. The turn handler catches any errors or exceptions the agent's logic doesn't catch. The adapter also forwards activities from your agent to the user's channel.

The adapter allows you to add your own on-turn error handler.

Agent logic

The Echobot agent uses an activity handler. The agent implements handlers for a list of activity types it recognizes and reacts to. The Echobot agent handles two types of activities: message and conversation update.

A conversation update activity includes information on who joins or leaves the conversation. For nongroup conversations, both the agent and the user join the conversation when it starts. For group conversations, a conversation update is generated whenever someone joins or leaves the conversation, whether that's the agent or a user.

A message activity represents a message the user sends to the agent.

The Echobot agent welcomes a user when they join the conversation and echoes back any messages they send to the agent.