次の方法で共有


Azure エージェントでエージェント コンテキストを構成する

Copilot Studio ボットの名前が Copilot エージェント (エージェントまたは AI エージェント) に変更されました。 人間 エージェント は、顧客サービス担当者 (サービス担当者または担当者) に名前が変更されました。 製品の UI、ドキュメント、トレーニング コンテンツを更新しているときに、古い用語と新しい用語への言及に出くわす可能性があります。

Azure エージェントの場合は、エージェント コンテキストを構成する前に、エージェント SDK をインストールし、オムニチャネル ミドルウェアをインスタンス化する必要があります。

プロジェクトにボット SDK をインストールする

  1. NuGet パッケージ マネージャーを開くには、プロジェクトを右クリックし、[ NuGet パッケージの管理] を選択します。

  2. NuGet パッケージ マネージャーで、 nuget.org としてパッケージ ソースを選択し、"Microsoft.Dynamics.AgentsSDK.Middleware" を参照します。 パッケージを選択し、インストールを選択します。 詳細については、 Nuget のページを参照してください。

    または、NuGet CLI で次のコマンドを使用することもできます。

    Install-Package Microsoft.Dynamics.AgentsSDK.Middleware
    

エージェント SDK がインストールされ、オムニチャネル ミドルウェアがプロジェクトで使用できるようになりました。

エージェント コードでオムニチャネル ミドルウェアを使用する

  1. AdapterWithErrorHandler.cs ファイルを開きます。

  2. import ステートメントを追加し、オムニチャネル ミドルウェアをインスタンス化します。

    using Microsoft.Dynamics.AgentsSDK.Middleware.Core; 
    Use(new OmnichannelMiddleware()); 
    
    using System.Globalization;
    using System.Text;
    using Microsoft.Agents.Connector;
    using Microsoft.Agents.Core;
    using Microsoft.Agents.Core.Errors;
    using Microsoft.Extensions.Logging;
    using Microsoft.Dynamics.AgentsSDK.Middleware.Core;
    
    namespace Microsoft.CCaaS.MessagingRuntime.TestAgent;
    
    public class AdapterWithErrorHandler : CloudAdapter
    {
        public AdapterWithErrorHandler(
            IChannelServiceClientFactory channelServiceClientFactory,
            IActivityTaskQueue activityTaskQueue,
            ILogger<CloudAdapter> logger)
            : base(channelServiceClientFactory, activityTaskQueue, logger)
        {
            // OmnichannelMiddleware has special handling for OC event messages
            Use(new OmnichannelMiddleware());
    
            OnTurnError = async (turnContext, exception) =>
            {
                var exceptionInfo = GetExceptionInfo(exception);
                logger.LogAppException(exceptionInfo, exception);
    
                // Send a message to the user
                await turnContext.SendActivityAsync($"The bot encountered an error or bug.{Environment.NewLine}{exceptionInfo}");
                await turnContext.SendActivityAsync("To continue to run this bot, please fix the bot source code.");
    
                // Send a trace activity, which will be displayed in the Bot Framework Emulator
                await turnContext.TraceActivityAsync("OnTurnError Trace", exception.Message, "https://www.botframework.com/schemas/error", "TurnError");
            };
        }
    
        private static string GetExceptionInfo(Exception exception)
        {
            var sb = new StringBuilder();
    
            // Pull some well known info from ErrorResponse.Exception if available.
            if (exception is ErrorResponseException responseException)
            {
                sb.AppendLine(CultureInfo.InvariantCulture, $"Error code: {responseException.Body?.Error?.Code ?? "NA"}");
                sb.AppendLine(CultureInfo.InvariantCulture, $"Error message: {responseException.Body?.Error?.Message ?? "NA"}");
            }
    
            sb.AppendLine(CultureInfo.InvariantCulture, $"Exception message: {exception.Message}");
            sb.AppendLine();
            sb.AppendLine(exception.ToString());
    
            var exceptionInfo = sb.ToString();
            return exceptionInfo;
        }
    }
    

次のステップ

アクティビティ JSON を解析してエージェント コンテキストを取得する

カスタム コンテキストを送信する
setContextProvider
Azure エージェントの統合