Configure agent context in Azure agents

Poznámka

Copilot Studio bot je premenovaný na agenta Copilota (agent alebo agent AI). Ľudský agent je teraz premenovaný na zástupcu zákazníckeho servisu (servisný zástupca alebo zástupca). Počas aktualizácie používateľského rozhrania produktu, dokumentácie a obsahu školení môžete naraziť na odkazy na staré a nové podmienky.

Pre Azure agentov musíte nainštalovať SDK agenta a inštancovať Omnichannel middleware ešte predtým, než nastavíte kontext agenta.

Inštalácia súpravy SDK robota do projektu

  1. Na otvorenie NuGet Package Manager kliknite pravým tlačidlom na svoj projekt a potom vyberte Manage NuGet Packages.

  2. V NuGet Package Manager vyberte zdrojový kód balíka ako nuget.org a vyhľadajte "Microsoft.Dynamics. AgentsSDK.Middleware". Vyberte balík a potom zvoľte Inštalovať. Viac sa dozviete na stránke Nuget.

    Prípadne môžete použiť nasledujúci príkaz v rozhraní príkazového riadenia NuGet.

    Install-Package Microsoft.Dynamics.AgentsSDK.Middleware
    

Agent SDK je teraz nainštalovaný a Omnichannel middleware je dostupný vo vašom projekte.

Použite Omnichannel middleware vo svojom agentovom kóde

  1. Otvorte súbor AdapterWithErrorHandler.cs .

  2. Pridajte príkaz import a vytvorte inštanciu middlevéru Omnikanála.

    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;
        }
    }
    

Ďalšie kroky

Analýza JSON aktivity na získanie kontextu agenta

Odoslanie vlastného kontextu
setContextProvider
Integrujte agenta Azure