microsoft/semantic-kernel · error · KernelException

Auto-invocation with KernelFunctions is not supported when n

Error message

Auto-invocation with KernelFunctions is not supported when no kernel is provided.

What it means

Thrown as a KernelException when auto-invocation of KernelFunctions is enabled (MaximumAutoInvokeAttempts > 0) but the kernel passed to the request is null. Auto-invocation requires a kernel to actually execute the functions the model calls back on. The connector fails early rather than promising the model it can handle tool calls and then failing at execution time.

Source

Thrown at dotnet/src/Connectors/Connectors.MistralAI/MistralAIToolCallBehavior.cs:153

        }

        internal override void ConfigureRequest(Kernel? kernel, ChatCompletionRequest request)
        {
            var functionsMetadata = kernel?.Plugins?.GetFunctionsMetadata();
            if (functionsMetadata is null)
            {
                return;
            }

            // If auto-invocation is specified, we need a kernel to be able to invoke the functions.
            // Lack of a kernel is fatal: we don't want to tell the model we can handle the functions
            // and then fail to do so, so we fail before we get to that point. This is an error
            // on the consumers behalf: if they specify auto-invocation with any functions, they must
            // specify the kernel and the kernel must contain those functions.
            bool autoInvoke = this.MaximumAutoInvokeAttempts > 0;
            if (autoInvoke && kernel is null)
            {
                throw new KernelException($"Auto-invocation with {nameof(KernelFunctions)} is not supported when no kernel is provided.");
            }

            request.ToolChoice = "auto";

            foreach (var functionMetadata in functionsMetadata)
            {
                request.AddTool(ToMistralTool(functionMetadata));
            }
        }

        internal override bool AllowAnyRequestedKernelFunction => true;
    }

    /// <summary>
    /// Represents a <see cref="MistralAIToolCallBehavior"/> that provides a specified list of functions to the model.
    /// </summary>
    internal sealed class AnyFunction(IEnumerable<KernelFunction> functions, bool autoInvoke) : MistralAIToolCallBehavior(autoInvoke)
    {

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass a non-null Kernel instance when invoking the completion service with auto-invocation enabled.
  2. If you do not want auto-invocation, set MaximumAutoInvokeAttempts to 0 so the kernel is not required.
  3. Ensure the kernel is available in the call chain from your service layer down to the connector.

Example fix

// before
var behavior = MistralAIToolCallBehavior.AutoInvokeKernelFunctions; // requires kernel
var result = await service.GetChatMessageContentAsync(history, settings, kernel: null);

// after
var result = await service.GetChatMessageContentAsync(history, settings, kernel: myKernel);
Defensive patterns

Strategy: validation

Validate before calling

if (behavior.MaximumAutoInvokeAttempts > 0 && kernel is null)
{
    throw new InvalidOperationException("Auto-invocation requires a non-null kernel.");
}

Type guard

static bool CanAutoInvoke(MistralAIToolCallBehavior behavior, Kernel? kernel) =>
    behavior.MaximumAutoInvokeAttempts == 0 || kernel is not null;

Prevention

When it happens

Trigger: Configuring MistralAIToolCallBehavior with KernelFunctions and enabling auto-invoke, but calling the completion service without passing a Kernel instance (kernel parameter is null).

Common situations: Calling chat completion methods that accept an optional kernel but omitting it; migrating from manual function-calling to auto-invoke without threading the kernel through; using a stateless service without the kernel context.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/c666a656e682e202. Report an issue: GitHub.