diff --git a/shell/agents/Microsoft.Azure.Agent/AzureAgent.cs b/shell/agents/Microsoft.Azure.Agent/AzureAgent.cs index f0d2ef7a..7e5fb983 100644 --- a/shell/agents/Microsoft.Azure.Agent/AzureAgent.cs +++ b/shell/agents/Microsoft.Azure.Agent/AzureAgent.cs @@ -183,20 +183,29 @@ public async Task ChatAsync(string input, IShell shell) { ResetArgumentPlaceholder(); - // Process CLI handler response specially to support parameter injection. - ResponseData data = null; - if (_copilotResponse.TopicName == CopilotActivity.CLIHandlerTopic) + if (_copilotResponse.IsError) { - data = ParseCLIHandlerResponse(shell); + host.WriteErrorLine() + .WriteErrorLine(_copilotResponse.Text) + .WriteErrorLine(); } - - if (data?.PlaceholderSet is not null) + else { - ArgPlaceholder = new ArgumentPlaceholder(input, data, _httpClient); - } + // Process CLI handler response specially to support parameter injection. + ResponseData data = null; + if (_copilotResponse.TopicName == CopilotActivity.CLIHandlerTopic) + { + data = ParseCLIHandlerResponse(shell); + } - string answer = data is null ? _copilotResponse.Text : GenerateAnswer(data); - host.RenderFullResponse(answer); + if (data?.PlaceholderSet is not null) + { + ArgPlaceholder = new ArgumentPlaceholder(input, data, _httpClient); + } + + string answer = data is null ? _copilotResponse.Text : GenerateAnswer(data); + host.RenderFullResponse(answer); + } } else { diff --git a/shell/agents/Microsoft.Azure.Agent/ChatSession.cs b/shell/agents/Microsoft.Azure.Agent/ChatSession.cs index 888fd55a..de11cd1d 100644 --- a/shell/agents/Microsoft.Azure.Agent/ChatSession.cs +++ b/shell/agents/Microsoft.Azure.Agent/ChatSession.cs @@ -27,8 +27,6 @@ internal class ChatSession : IDisposable private readonly HttpClient _httpClient; private readonly Dictionary _flights; - internal string ConversationId => _conversationId; - internal ChatSession(HttpClient httpClient) { _httpClient = httpClient; @@ -328,6 +326,7 @@ internal async Task GetChatResponseAsync(string input, IStatusC { "typing" => new CopilotResponse(activity, new ChunkReader(_copilotReceiver, activity)), "acceptingInput" => new CopilotResponse(activity), + "error" => new CopilotResponse(activity) { IsError = true }, _ => throw CorruptDataException.Create($"The 'inputHint' is {activity.InputHint}.", activity) }; @@ -338,6 +337,7 @@ internal async Task GetChatResponseAsync(string input, IStatusC ret.ConversationState = state; } + ret.ConversationId = _conversationId; return ret; } diff --git a/shell/agents/Microsoft.Azure.Agent/Schema.cs b/shell/agents/Microsoft.Azure.Agent/Schema.cs index 1424a927..a88b08c0 100644 --- a/shell/agents/Microsoft.Azure.Agent/Schema.cs +++ b/shell/agents/Microsoft.Azure.Agent/Schema.cs @@ -192,6 +192,9 @@ internal CopilotResponse(CopilotActivity activity) internal string Locale { get; } internal string TopicName { get; } internal string ReplyToId { get; } + + internal bool IsError { get; set; } + internal string ConversationId { get; set; } internal string[] SuggestedUserResponses { get; set; } internal ConversationState ConversationState { get; set; } }