Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Microsoft Semantic kernel FunctionChoiceBehavior Auto

From Leeroopedia
Knowledge Sources
Domains AI_Orchestration, Function_Calling, Tool_Use
Last Updated 2026-02-11 19:00 GMT

Overview

Concrete tool for configuring automatic function selection behavior, allowing AI models to autonomously choose which registered functions to call in Microsoft Semantic Kernel.

Description

FunctionChoiceBehavior.Auto() is a static factory method that creates an AutoFunctionChoiceBehavior instance. This behavior presents all (or a filtered subset of) the kernel's registered plugin functions to the AI model, and allows the model to decide autonomously whether to call any functions and which ones to call.

When autoInvoke is true (the default), the AI connector automatically executes the functions chosen by the model, passes the results back into the conversation, and continues the model's reasoning loop. When autoInvoke is false, the connector returns the raw function call requests to the caller for manual handling.

The method accepts an optional functions parameter that can restrict which functions are advertised to the model. If null, all functions from all registered kernel plugins are presented. If an empty collection is provided, function calling is effectively disabled.

The behavior is typically set on a PromptExecutionSettings object (such as OpenAIPromptExecutionSettings) via the FunctionChoiceBehavior property, and is passed to the kernel when invoking a prompt.

Usage

Use FunctionChoiceBehavior.Auto() when you want the AI model to have full autonomy in deciding which functions to call. This is the standard mode for conversational AI agents that need access to tools.

Code Reference

Source Location

  • Repository: semantic-kernel
  • File: dotnet/src/SemanticKernel.Abstractions/AI/FunctionChoiceBehaviors/FunctionChoiceBehavior.cs:L62-65

Signature

public static FunctionChoiceBehavior Auto(
    IEnumerable<KernelFunction>? functions = null,
    bool autoInvoke = true,
    FunctionChoiceBehaviorOptions? options = null)

Import

using Microsoft.SemanticKernel;

I/O Contract

Inputs

Name Type Required Description
functions IEnumerable<KernelFunction>? No Functions to provide to the model. If null, all kernel plugin functions are provided. If empty, no functions are provided (disables function calling).
autoInvoke bool No Whether the framework should automatically invoke functions chosen by the model. Default is true.
options FunctionChoiceBehaviorOptions? No Additional options for configuring the behavior.

Outputs

Name Type Description
return FunctionChoiceBehavior An AutoFunctionChoiceBehavior instance that can be assigned to execution settings.

Usage Examples

Basic Auto Function Calling

using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;

// Build kernel with plugins
IKernelBuilder kernelBuilder = Kernel.CreateBuilder();
kernelBuilder.AddOpenAIChatClient(modelId: "gpt-4o", apiKey: "your-api-key");
kernelBuilder.Plugins.AddFromType<TimeInformation>();
Kernel kernel = kernelBuilder.Build();

// Enable auto function calling
OpenAIPromptExecutionSettings settings = new()
{
    FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()
};

// The model will automatically call TimeInformation.GetCurrentUtcTime if needed
Console.WriteLine(await kernel.InvokePromptAsync("How many days until Christmas?", new(settings)));

Auto with Manual Invocation

using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;

// Disable auto-invoke to handle function calls manually
OpenAIPromptExecutionSettings settings = new()
{
    FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(autoInvoke: false)
};

// Function call requests will be returned to the caller instead of being executed automatically
var result = await kernel.InvokePromptAsync("What time is it?", new(settings));

Auto with Filtered Functions

using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;

// Only expose specific functions to the model
var timeFunction = kernel.Plugins["TimeInformation"]["GetCurrentUtcTime"];
OpenAIPromptExecutionSettings settings = new()
{
    FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(
        functions: [timeFunction])
};

Console.WriteLine(await kernel.InvokePromptAsync("What is the current time?", new(settings)));

Comparing All Three Behavior Modes

using Microsoft.SemanticKernel;

// Auto: model decides freely whether to call functions
var auto = FunctionChoiceBehavior.Auto();

// Required: model must call at least one function
var required = FunctionChoiceBehavior.Required();

// None: model sees functions but cannot call them
var none = FunctionChoiceBehavior.None();

Related Pages

Implements Principle

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment