microsoft/autogen · error · Exception

Could not create chat manager

Error message

Could not create chat manager

What it means

GroupChatBase.CreateChatManager instantiates TManager via Activator.CreateInstance(typeof(TManager), options). If the manager's (GroupChatOptions) constructor itself throws, the reflection wraps it in TargetInvocationException; this catch unwraps InnerException and rethrows as Exception("Could not create chat manager", inner) — the real cause (bad options, null model config, etc.) is in InnerException.

Source

Thrown at dotnet/src/Microsoft.AutoGen/AgentChat/GroupChat/GroupChatBase.cs:125

    public string TeamId
    {
        get;
        private set;
    }

    public virtual TManager CreateChatManager(GroupChatOptions options)
    {
        try
        {
            if (Activator.CreateInstance(typeof(TManager), options) is TManager result)
            {
                return result;
            }
        }
        catch (TargetInvocationException tie)
        {
            throw new Exception("Could not create chat manager", tie.InnerException);
        }
        catch (Exception ex)
        {
            throw new Exception("Could not create chat manager", ex);
        }

        throw new Exception("Could not create chat manager; make sure that it contains a ctor() or ctor(GroupChatOptions), or override the CreateChatManager method");
    }

    private sealed class RuntimeLayer(GroupChatBase<TManager> groupChat) : IRunContextLayer
    {
        public GroupChatBase<TManager> GroupChat { get; } = groupChat;
        public InProcessRuntime? Runtime { get; private set; }
        public OutputSink? OutputSink { get; private set; }

        public Task? InitOnceTask { get; set; }
        public Task ShutdownTask { get; set; } = Task.CompletedTask;

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Inspect ex.InnerException — it holds the original constructor failure
  2. Fix the GroupChatOptions passed to the run/start call so all fields the manager's constructor requires are populated
  3. Give TManager a parameterless ctor() (also accepted) or override CreateChatManager to construct it explicitly with DI

Example fix

// before
var options = new GroupChatOptions(); // ModelClient unset; manager ctor dereferences it
await team.RunAsync(task, options);
// after
var options = new GroupChatOptions { ModelClient = client, ... };
await team.RunAsync(task, options);
Defensive patterns

Strategy: try-catch

Validate before calling

var probe = (TManager?)Activator.CreateInstance(typeof(TManager), options); // returns null instead of throwing when signature is missing
if (probe is null) throw new InvalidOperationException($"{typeof(TManager).Name} lacks ctor()/ctor(GroupChatOptions)");

Type guard

static bool HasSupportedCtor<T>() => typeof(T).GetConstructors().Any(c => c.GetParameters().Length == 0 || (c.GetParameters().Length == 1 && c.GetParameters()[0].ParameterType == typeof(GroupChatOptions)));

Try / catch

catch (Exception ex) when (ex.Message == "Could not create chat manager")
{
    var cause = ex.InnerException?.Message ?? ex.Message;
    throw new InvalidOperationException($"Chat manager construction failed: {cause}", ex);
}

Prevention

When it happens

Trigger: A TManager whose ctor(GroupChatOptions) throws — e.g. it dereferences options.ModelClient or another property the caller never set when starting the team.

Common situations: Starting a round-robin/graph group chat with GroupChatOptions missing required fields; custom chat managers that validate options eagerly; DI-dependent managers constructed via reflection without their dependencies.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/b27b7fa8052b84c1. Report an issue: GitHub.