.NET: Declarative workflows - Gracefully handle agent scenarios when no response is returned (#5376)

* Gracefully handle agent scenarios when no response is returned

* Make relevant object disposable and improve exception handling.
This commit is contained in:
Peter Ibekwe
2026-04-21 08:04:49 -07:00
committed by GitHub
Unverified
parent d5777bc546
commit adcd2d33f5
5 changed files with 68 additions and 17 deletions
@@ -122,10 +122,13 @@ internal sealed class QuestionExecutor(Question model, ResponseAgentProvider age
string? workflowConversationId = context.GetWorkflowConversation();
if (workflowConversationId is not null)
{
// Input message always defined if values has been extracted.
ChatMessage input = response.Messages.Last();
await agentProvider.CreateMessageAsync(workflowConversationId, input, cancellationToken).ConfigureAwait(false);
await context.SetLastMessageAsync(input).ConfigureAwait(false);
// Input message expected to be defined when values have been extracted, but guard defensively.
ChatMessage? input = response.Messages.LastOrDefault();
if (input is not null)
{
await agentProvider.CreateMessageAsync(workflowConversationId, input, cancellationToken).ConfigureAwait(false);
await context.SetLastMessageAsync(input).ConfigureAwait(false);
}
}
}