microsoft/semantic-kernel · error · KernelException

Auto-invocation with {nameof(RequiredFunction)} is not suppo

Error message

Auto-invocation with {nameof(RequiredFunction)} is not supported when no kernel is provided.

What it means

RequiredFunction tool-call behavior forces the model to call a specific function. When auto-invocation is enabled (MaximumAutoInvokeAttempts > 0) but the kernel is null, the connector throws before sending the request. Unlike EnabledFunctions (which 'allows' calls), RequiredFunction 'forces' a call, so a missing kernel is always fatal — the model will call the function and there is nothing to execute it.

Source

Thrown at dotnet/src/Connectors/Connectors.OpenAI/ToolCallBehavior.cs:260

            this._function = function;
            this._tool = function.ToFunctionDefinition(false);
            this._choice = ChatToolChoice.CreateFunctionChoice(this._tool.FunctionName);
        }

        public override string ToString() => $"{nameof(RequiredFunction)}(autoInvoke:{this.MaximumAutoInvokeAttempts != 0}): {this._tool.FunctionName}";

        internal override (IList<ChatTool>? Tools, ChatToolChoice? Choice) ConfigureOptions(Kernel? kernel)
        {
            bool autoInvoke = base.MaximumAutoInvokeAttempts > 0;

            // 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.
            if (autoInvoke && kernel is null)
            {
                throw new KernelException($"Auto-invocation with {nameof(RequiredFunction)} is not supported when no kernel is provided.");
            }

            // Make sure that if auto-invocation is specified, the required function can be found in the kernel.
            if (autoInvoke && !kernel!.Plugins.TryGetFunction(this._function.PluginName, this._function.FunctionName, out _))
            {
                throw new KernelException($"The specified {nameof(RequiredFunction)} function {this._function.FullyQualifiedName} is not available in the kernel.");
            }

            return ([this._tool], this._choice);
        }

        /// <summary>Gets how many requests are part of a single interaction should include this tool in the request.</summary>
        /// <remarks>
        /// Unlike <see cref="EnabledFunctions"/> and <see cref="KernelFunctions"/>, this must use 1 as the maximum
        /// use attempts. Otherwise, every call back to the model _requires_ it to invoke the function (as opposed
        /// to allows it), which means we end up doing the same work over and over and over until the maximum is reached.
        /// Thus for "requires", we must send the tool information only once.
        /// </remarks>

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass a non-null Kernel that contains the required function.
  2. Use autoInvoke: false if you intend to handle the required function call yourself.
  3. Avoid RequireFunction unless you specifically need the model to always call one function — prefer EnableFunctions or KernelFunctions.

Example fix

// before
var behavior = ToolCallBehavior.RequireFunction(myFunc, autoInvoke: true);
await chatService.GetChatMessageContentAsync(history, settings); // no kernel

// after
await chatService.GetChatMessageContentAsync(history, settings, kernel: myKernel);
Defensive patterns

Strategy: validation

Validate before calling

// RequireFunction with autoInvoke requires a kernel
if (behavior is { MaximumAutoInvokeAttempts: > 0 } && kernel is null)
{
    throw new InvalidOperationException(
        "RequireFunction with auto-invocation needs a non-null Kernel.");
}

Try / catch

try { await chatService.GetChatMessageContentAsync(history, settings, kernel); }
catch (KernelException ex) when (ex.Message.Contains("RequiredFunction") && ex.Message.Contains("no kernel"))
{
    throw new InvalidOperationException("Pass a Kernel when using RequireFunction with autoInvoke.", ex);
}

Prevention

When it happens

Trigger: Creating ToolCallBehavior.RequireFunction(function, autoInvoke: true) and calling chat completion without a kernel, or through a path where kernel is null.

Common situations: Same as [411]: custom orchestration omitting the kernel, direct SDK calls, or testing harnesses that invoke the model without a kernel.

Related errors


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