.Net: Bug: SequentialOrchestration hangs indefinetly on agent exception
Describe the bug When calling SequentialOrchestration with invalid parameters, GetResultAsync() hangs indefinetly.
To Reproduce
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents.Orchestration.Sequential;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Agents.Runtime.InProcess;
var builder = Kernel.CreateBuilder();
// intentionally bad model/api key so that endpoint throws HTTP 401 (invalid_request_error: invalid_api_key)
builder.AddOpenAIChatCompletion(modelId: "foo", apiKey: "bar");
var kernel = builder.Build();
#pragma warning disable SKEXP0110
var agent = new ChatCompletionAgent { Kernel = kernel, Instructions = "You are helpful assistant.", Description = "Test agent" };
var orchestration = new SequentialOrchestration(agent);
var runtime = new InProcessRuntime();
try
{
await runtime.StartAsync();
var result = await orchestration.InvokeAsync("Hi", runtime);
// hangs here, never returns, no exceptions
await result.GetValueAsync();
}
catch (Exception ex)
{
// never called
Console.WriteLine(ex);
}
await runtime.RunUntilIdleAsync();
Expected behavior Exception from agent invoke is propagated somewhere.
Platform
- Language: C#
- Source:
Microsoft.SemanticKernel.Agents.Core Version=1.64.0
Microsoft.SemanticKernel.Agents.OpenAI Version=1.64.0-preview
Microsoft.SemanticKernel.Agents.Orchestration Version=1.64.0-preview
Microsoft.SemanticKernel.Agents.Runtime.InProcess Version=1.64.0-preview
- AI model: none
- IDE: Visual Studio
- OS: Windows
Additional context Exception
System.ClientModel.ClientResultException: 'HTTP 401 (invalid_request_error: invalid_api_key)
Incorrect API key provided: bar. You can find your API key at https://platform.openai.com/account/api-keys.'
Can be caught under debugger, it occurs right away, but is swallowed silently.
Another reported instance of this:
I just came across .Net: Bug: SequentialOrchestration hangs indefinetly on agent exception · Issue #13040 · microsoft/… and I wonder whether you need additional input. The same just happened to me after defining an invalid agent definition (had a space in the agent name); the exception gets handled somewhere without propagation.
I am also facing the same issue pretty much in every orchestration. My errors are related to content filter policy set by organization. I really need the actual exception in the calling code to determine the next step in my workflow. Currently I am setting timeout to get out of this behaviour, but the exception never propagates to the calling code. Please suggest if there are any alternatives. var response = await result.GetValueAsync(TimeSpan.FromSeconds(60)).ConfigureAwait(false);
Same here, orchestration never returns anything but I don't see any exception or anything, it just never provide a result... Important note: i used open router, is that relevant? I'll try with OpenAi or azureAi and see if that changed anything.
EDIT: solved, it was the field description supposedly nullable but it is mandatory to be able to use orchestration, otherwise it hangs until TimeOut.