Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions shell/agents/Microsoft.Azure.Agent/AzureAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public async Task RefreshChatAsync(IShell shell, bool force)
{
IHost host = shell.Host;
CancellationToken cancellationToken = shell.CancellationToken;

_copilotResponse = null;
ResetArgumentPlaceholder();

try
Expand Down Expand Up @@ -214,6 +216,9 @@ public async Task<bool> ChatAsync(string input, IShell shell)
IHost host = shell.Host;
CancellationToken token = shell.CancellationToken;

_copilotResponse = null;
ResetArgumentPlaceholder();

if (_turnsLeft is 0)
{
host.WriteLine("\nSorry, you've reached the maximum length of a conversation. Please run '/refresh' to start a new conversation.\n");
Expand Down Expand Up @@ -243,8 +248,6 @@ public async Task<bool> ChatAsync(string input, IShell shell)

if (_copilotResponse.ChunkReader is null)
{
ResetArgumentPlaceholder();

if (_copilotResponse.IsError)
{
string errorMessage = _copilotResponse.Text;
Expand Down Expand Up @@ -325,11 +328,22 @@ public async Task<bool> ChatAsync(string input, IShell shell)

Telemetry.Trace(AzTrace.Chat(_copilotResponse));
}
catch (Exception ex) when (ex is TokenRequestException or ConnectionDroppedException)
catch (Exception ex)
{
host.WriteErrorLine(ex.Message);
host.WriteErrorLine("Please run '/refresh' to start a new chat session and try again.");
return false;
if (ex is TokenRequestException or ConnectionDroppedException)
{
host.WriteErrorLine(ex.Message);
host.WriteErrorLine("Please run '/refresh' to start a new chat session and try again.");
return false;
}

Log.Error(ex, "Exception thrown when processing the query '{0}'", input);
if (_copilotResponse?.Text is not null)
{
Log.Error("Response text:\n{0}", _copilotResponse.Text);
}

throw;
}

return true;
Expand Down