Configurar el context de l'agent en Azure agents

Nota

Copilot Studio bot passa a anomenar-se agent Copilot (agent o agent d'IA). L'agent humà ara passa a anomenar-se representant d'atenció al client (representant o representant del servei). És possible que trobeu referències als termes antics i nous mentre actualitzem la interfície d'usuari, la documentació i el contingut de formació del producte.

Per als agents d'Azure, has d'instal·lar l'SDK de l'agent i instanciar el middleware Omnichannel abans de configurar el context de l'agent.

Instal·lar l'SDK del bot al projecte

  1. Per obrir el Package Manager NuGet, fes clic dret al teu projecte i després selecciona Gestionar paquets NuGet.

  2. A la Package Manager NuGet, selecciona la font del paquet com a nuget.org i busca "Microsoft.Dynamics. AgentsSDK.Middleware". Selecciona el paquet i després selecciona Instal·lar. Més informació a la pàgina Nuget.

    Com a alternativa, podeu utilitzar l'ordre següent a la CLI del NuGet.

    Install-Package Microsoft.Dynamics.AgentsSDK.Middleware
    

L'SDK de l'agent ja està instal·lat i el middleware omnicanal està disponible al teu projecte.

Utilitza el middleware omnicanal al codi del teu agent

  1. Obriu el fitxer AdapterWithErrorHandler.cs .

  2. Afegiu la instrucció import i creeu una instància del middleware omnicanal.

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

Passos següents

Analitzar JSON d'activitat per obtenir el context de l'agent

Enviar context personalitzat
setContextProvider
Integrar un agent de l'Azure