Configure agent context in Azure agents

Napomena

Copilot Studio bot je preimenovan u Copilot agent (agent ili AI agent). Ljudski agent sada je preimenovan u predstavnika korisničke službe (predstavnik usluge ili predstavnik). Možda ćete naići na reference na stare i nove pojmove dok ažuriramo korisničko sučelje proizvoda, dokumentaciju i sadržaj obuke.

Za Azure agente morate instalirati agent SDK i instancirati Omnichannel middleware prije nego što konfigurirate kontekst agenta.

Instalirajte SDK bota u svoj projekt

  1. Za otvaranje NuGet Package Manager, desnim klikom kliknite na svoj projekt, a zatim odaberite Manage NuGet Packages.

  2. U NuGet Package Manager odaberite izvorni kod paketa kao nuget.org i pretražujte "Microsoft.Dynamics. AgentsSDK.Middleware". Odaberi paket, a zatim odaberi Instaliraj. Saznajte više na Nuget stranici.

    Alternativno, možete koristiti sljedeću naredbu u NuGet CLI-ju.

    Install-Package Microsoft.Dynamics.AgentsSDK.Middleware
    

Agent SDK je sada instaliran i Omnichannel middleware je dostupan u vašem projektu.

Koristite Omnichannel middleware u svom agentskom kodu

  1. Otvorite AdapterWithErrorHandler.cs datoteku.

  2. Dodajte naredbu o uvozu i instancirajte međusoftver aplikacije Svi kanali.

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

Sljedeći koraci

Raščlanjivanje JSON aktivnosti radi dobivanja konteksta agenta

Slanje prilagođenog konteksta
setContextProvider
Integracija agenta za Azure