Agento konteksto konfigūravimas "Azure" agentuose

Pastaba.

Copilot Studio botas pervadintas į Copilot agentą (agentą arba AI agentą). Žmogiškasis agentas dabar pervadinamas į klientų aptarnavimo atstovą (aptarnavimo atstovą arba atstovą). Galite susidurti su nuorodomis į senas ir naujas sąlygas, kai atnaujiname produkto vartotojo sąsają, dokumentaciją ir mokymo turinį.

Jei naudojate "Azure" agentus, prieš konfigūruodami agento kontekstą, turite įdiegti agento SDK ir sukurti daugiakanalę tarpinę programinę įrangą.

Įdiekite roboto SDK savo projekte

  1. Norėdami atidaryti "NuGet" Package Manager, dešiniuoju pelės mygtuku spustelėkite savo projektą ir pasirinkite Tvarkyti "NuGet" paketus.

  2. NuGet Package Manager pasirinkite paketo šaltinį kaip nuget.org ir naršykite "Microsoft.Dynamics. AgentsSDK.Middleware". Pasirinkite paketą, tada pasirinkite Diegti. Sužinokite daugiau Nuget puslapyje.

    Arba galite naudoti šią komandą NuGet CLI.

    Install-Package Microsoft.Dynamics.AgentsSDK.Middleware
    

Agento SDK dabar įdiegtas ir daugiakanalė tarpinė programinė įranga yra jūsų projekte.

Naudokite daugiakanalę tarpinę programinę įrangą savo agento kode

  1. Atidarykite AdapterWithErrorHandler.cs failą.

  2. Pridėkite importo sakinį ir sukurkite daugiakanalę tarpinę programinę įrangą.

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

Paskesni veiksmai

Analizuoti veiklą JSON, kad gautumėte agento kontekstą

Siųsti pasirinktinį kontekstą
setContextProvider
"Azure" agento integravimas