Skip to content

.Net: Bug: SequentialOrchestration hangs indefinetly on agent exception #13040

@ghord

Description

@ghord

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.

Metadata

Metadata

Assignees

Labels

.NETIssue or Pull requests regarding .NET codeagentsbugSomething isn't workingmulti-agentIssues for multi-agent orchestration

Type

Projects

Status

Bug

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions