{"record":{"id":"575b0ff063db555f","repo":"microsoft/semantic-kernel","slug":"auto-invocation-with-nameof-enabledfunctions-is-575b0f","errorCode":null,"errorMessage":"Auto-invocation with {nameof(EnabledFunctions)} is not supported when no kernel is provided.","messagePattern":"Auto-invocation with (.+?) is not supported when no kernel is provided\\.","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.OpenAI/ToolCallBehavior.cs","lineNumber":206,"sourceCode":"            ChatToolChoice? choice = null;\n            List<ChatTool>? tools = null;\n\n            OpenAIFunction[] openAIFunctions = this._openAIFunctions;\n            ChatTool[] functions = this._functions;\n            Debug.Assert(openAIFunctions.Length == functions.Length);\n\n            if (openAIFunctions.Length > 0)\n            {\n                bool autoInvoke = base.MaximumAutoInvokeAttempts > 0;\n\n                // If auto-invocation is specified, we need a kernel to be able to invoke the functions.\n                // Lack of a kernel is fatal: we don't want to tell the model we can handle the functions\n                // and then fail to do so, so we fail before we get to that point. This is an error\n                // on the consumers behalf: if they specify auto-invocation with any functions, they must\n                // specify the kernel and the kernel must contain those functions.\n                if (autoInvoke && kernel is null)\n                {\n                    throw new KernelException($\"Auto-invocation with {nameof(EnabledFunctions)} is not supported when no kernel is provided.\");\n                }\n\n                choice = ChatToolChoice.CreateAutoChoice();\n                tools = [];\n                for (int i = 0; i < openAIFunctions.Length; i++)\n                {\n                    // Make sure that if auto-invocation is specified, every enabled function can be found in the kernel.\n                    if (autoInvoke)\n                    {\n                        Debug.Assert(kernel is not null);\n                        OpenAIFunction f = openAIFunctions[i];\n                        if (!kernel!.Plugins.TryGetFunction(f.PluginName, f.FunctionName, out _))\n                        {\n                            throw new KernelException($\"The specified {nameof(EnabledFunctions)} function {f.FullyQualifiedName} is not available in the kernel.\");\n                        }\n                    }\n\n                    // Add the function.","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.OpenAI/ToolCallBehavior.cs#L188-L224","documentation":"EnabledFunctions tool-call behavior is configured with auto-invocation enabled (MaximumAutoInvokeAttempts > 0). When ConfigureOptions runs, if there are enabled functions but the kernel argument is null, it throws immediately. The connector refuses to advertise functions to the model that it cannot execute, since the model may call them and the connector would have no kernel to dispatch through.","triggerScenarios":"Creating ToolCallBehavior.EnabledFunctions(functions, autoInvoke: true) and then calling the chat completion API without passing a Kernel instance (kernel is null). This happens when invoking the underlying OpenAI client directly or through a code path that omits the kernel.","commonSituations":"Calling chatPrompt execution methods that don't thread the kernel through. Using KernelFunction-less invocation patterns. Accidentally passing null kernel in a custom orchestration wrapper.","solutions":["Pass a non-null Kernel to the chat completion call — the kernel must contain the plugins with the enabled functions.","If you don't need auto-invocation, create the behavior with autoInvoke: false so no kernel is required.","If you are calling the OpenAI SDK directly without Semantic Kernel, use a non-auto-invoking behavior or none at all."],"exampleFix":"// before — auto-invoke enabled but no kernel\nvar behavior = ToolCallBehavior.EnableFunctions(functions, autoInvoke: true);\nawait chatService.GetChatMessageContentAsync(history, settings); // no kernel!\n\n// after — pass the kernel\nawait chatService.GetChatMessageContentAsync(history, settings, kernel: myKernel);\n// or disable auto-invoke if you handle tool calls manually\nvar behavior = ToolCallBehavior.EnableFunctions(functions, autoInvoke: false);","handlingStrategy":"validation","validationCode":"// Before calling chat completion, verify the invariant:\n// auto-invoking behaviors require a kernel\nif (behavior.MaximumAutoInvokeAttempts > 0 && kernel is null)\n{\n    throw new InvalidOperationException(\n        \"Auto-invocation requires a non-null Kernel. Pass the kernel or disable autoInvoke.\");\n}","typeGuard":null,"tryCatchPattern":"try { await chatService.GetChatMessageContentAsync(history, settings, kernel); }\ncatch (KernelException ex) when (ex.Message.Contains(\"no kernel is provided\"))\n{\n    // Either pass a kernel or disable auto-invoke before retrying\n    throw new InvalidOperationException(\"Pass a Kernel to enable auto-invocation.\", ex);\n}","preventionTips":["Always pass the kernel to chat calls when using EnableFunctions with autoInvoke.","Centralize behavior creation in a factory that also validates kernel availability.","Document that autoInvoke=true requires the kernel in your team's integration guide."],"tags":["tool-calling","auto-invocation","kernel","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}