{"id":3291,"date":"2024-09-17T15:21:44","date_gmt":"2024-09-17T22:21:44","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/semantic-kernel\/?p=3291"},"modified":"2024-09-25T15:14:49","modified_gmt":"2024-09-25T22:14:49","slug":"new-function-calling-model-available-in-net-for-semantic-kernel","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/agent-framework\/new-function-calling-model-available-in-net-for-semantic-kernel\/","title":{"rendered":"New Function Calling Available in .NET for Semantic Kernel"},"content":{"rendered":"<p>We are happy to announce release of the <a href=\"https:\/\/learn.microsoft.com\/en-us\/semantic-kernel\/concepts\/ai-services\/chat-completion\/function-calling\/function-choice-behaviors?pivots=programming-language-csharp\">new function-calling<\/a> capabilities available in <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.SemanticKernel\/1.20.0\">Semantic Kernel v1.20 (.NET)<\/a>.<\/p>\n<p>The new capabilities incorporates the best parts of the existing function-calling, such as ease of use, and improves on it by making it more extensible and reusable.<\/p>\n<p>Function calling allows Plugin descriptions to be passed into a model for dynamic planning to occur.\u00a0 The AI model will create a step-by-step plan based on the users ask and based on the function descriptions that are passed into it.\u00a0 Allowing for the right functions to be called, in the right order and used together to solve the users ask or question.\u00a0 All of the calls are orchestrated by Semantic Kernel.<\/p>\n<p>Let&#8217;s see this in action:<\/p>\n<pre class=\"prettyprint language-cs language-csharp\"><code class=\"language-cs language-csharp\">using Microsoft.SemanticKernel;\r\n\r\nIKernelBuilder builder = Kernel.CreateBuilder();\r\n\r\n\/\/ Register OpenAI connector\r\nbuilder.AddOpenAIChatCompletion(\"&lt;model-id&gt;\", \"&lt;api-key&gt;\");\r\n\r\n\/\/ Register a few plugins\r\nbuilder.Plugins.AddFromType&lt;WeatherForecastUtils&gt;();  \r\nbuilder.Plugins.AddFromType&lt;DateTimeUtils&gt;();  \r\n\r\nKernel kernel = builder.Build();\r\n\r\n\/\/ Configure function calling to:\r\n\/\/ 1. Send all the functions from the plugins to the OpenAI model to decide which one(s) to choose.\r\n\/\/ 2. Invoke them automatically by Semantic Kernel.\r\nPromptExecutionSettings settings = new() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() }; \r\n\r\nawait kernel.InvokePromptAsync(\"What is the likely color of the sky in Boston?\", new(settings));\r\n<\/code><\/pre>\n<h3><\/h3>\n<h3>One function-calling capabilities for all SK connectors<\/h3>\n<p>Today, Semantic Kernel has a few sets of classes for function calling. One set is for the AzureOpenAI and OpenAI AI connectors. Another set is for the Gemini AI connector, and the third one is for the Mistral connector.<\/p>\n<p>These sets of function-calling classes are almost identical, with only minor differences &#8211; each set references internal code specific to the AI connector.\nThis makes it impossible to reuse the same function-calling classes for other AI connectors. As a result, each new AI connector requires a new set of function-calling classes to be created.<\/p>\n<p>The new function-calling addresses this problem by being designed to be connector\/service agnostic. It resides within Semantic Kernel abstractions and is intended for use by all AI connectors that work with function-calling capable AI models. This design makes the new function-calling model reusable and supports polymorphic scenarios, allowing the same instance of the function-calling configuration and behavior to be used by different AI connectors.<\/p>\n<p><div class=\"alert alert-primary\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Info\"><\/i><strong>Note<\/strong><\/p>As of today, the new function-calling model is used by the Azure OpenAI and OpenAI AI connectors only, with plans to add support for other AI connectors in future Semantic Kernel releases. See the <a href=\"https:\/\/learn.microsoft.com\/en-us\/semantic-kernel\/concepts\/ai-services\/chat-completion\/function-calling\/function-choice-behaviors?pivots=programming-language-csharp#supported-ai-connectors\" target=\"_blank\" rel=\"noopener\">Supported AI Connectors<\/a> section to see the list of AI connectors supporting the new model.<\/div><\/p>\n<h3>Function-calling capabilities of modern AI models and Extensibility<\/h3>\n<p>The existing function-calling model in Semantic Kernel was created soon after the function-calling capabilities for AI models were introduced and has not changed since then.\nMeanwhile, there were a few small features added on the AI model side that have not found their way into the existing function-calling model.<\/p>\n<p>The new capabilities incorporates some of these features from day one, such as support for multiple required functions and exposing the &#8220;None&#8221; function choice behavior, leaving others like parallel function calling and concurrent function invocation to future Semantic Kernel releases.\nThe new model is designed to be extensible and support new AI model features as they may be introduced, regardless of whether they are applicable to all function-calling capable models or specific ones.<\/p>\n<h3>Prompt template configuration support<\/h3>\n<p>The new function-calling subsystem can be configured not only through code but also via prompt template configuration, as demonstrated by the example:<\/p>\n<pre class=\"prettyprint language-cs language-csharp\"><code class=\"language-cs language-csharp\">using Microsoft.SemanticKernel;\r\n\r\nIKernelBuilder builder = Kernel.CreateBuilder();\r\n\r\n\/\/ Register OpenAI connector\r\nbuilder.AddOpenAIChatCompletion(\"&lt;model-id&gt;\", \"&lt;api-key&gt;\");\r\n\r\n\/\/ Register a few plugins\r\nbuilder.Plugins.AddFromType&lt;WeatherForecastUtils&gt;();  \r\nbuilder.Plugins.AddFromType&lt;DateTimeUtils&gt;();  \r\n\r\nstring promptTemplateConfig = \"\"\"\r\n    template_format: semantic-kernel\r\n    template: What is the likely color of the sky in Boston?\r\n    execution_settings:\r\n      default:\r\n        function_choice_behavior:\r\n          type: auto\r\n    \"\"\";\r\n\r\nKernelFunction promptFunction = KernelFunctionYaml.FromPromptYaml(promptTemplateConfig);\r\n\r\nKernel kernel = builder.Build();\r\n\r\nawait kernel.InvokeAsync(promptFunction);<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>Next steps<\/h3>\n<p>Now that you know about the new function-calling capabilities, you can get more detailed information about it in the <a href=\"https:\/\/learn.microsoft.com\/en-us\/semantic-kernel\/concepts\/ai-services\/chat-completion\/function-calling\/function-choice-behaviors?pivots=programming-language-csharp\">function choice behaviors article<\/a> to start using it.\nIf you are using existing function-calling and you would like to update to the latest technology &#8211; the <a href=\"https:\/\/review.learn.microsoft.com\/en-us\/semantic-kernel\/support\/migration\/function-calling-migration-guide?pivots=programming-language-csharp\">migration guide<\/a> can help you migrate your code to the new capabilities.\nFor more hands-on samples, you can check the <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/dotnet\/samples\/Concepts\/FunctionCalling\/FunctionCalling.cs\">function calling samples<\/a><\/p>\n<p>Please reach out if you have any questions or feedback through our\u00a0<a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/discussions\/categories\/general\" target=\"_blank\" rel=\"noopener\">Semantic Kernel GitHub Discussion Channel<\/a>. We look forward to hearing from you!\u00a0We would also love your support, if you\u2019ve enjoyed using Semantic Kernel, give us a star on\u00a0<a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\" target=\"_blank\" rel=\"noopener\">GitHub<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We are happy to announce release of the new function-calling capabilities available in Semantic Kernel v1.20 (.NET). The new capabilities incorporates the best parts of the existing function-calling, such as ease of use, and improves on it by making it more extensible and reusable. Function calling allows Plugin descriptions to be passed into a model [&hellip;]<\/p>\n","protected":false},"author":157200,"featured_media":2364,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[78,47,1],"tags":[48,63,9],"class_list":["post-3291","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-net","category-announcement","category-semantic-kernel","tag-ai","tag-microsoft-semantic-kernel","tag-semantic-kernel"],"acf":[],"blog_post_summary":"<p>We are happy to announce release of the new function-calling capabilities available in Semantic Kernel v1.20 (.NET). The new capabilities incorporates the best parts of the existing function-calling, such as ease of use, and improves on it by making it more extensible and reusable. Function calling allows Plugin descriptions to be passed into a model [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/3291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/users\/157200"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/comments?post=3291"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/3291\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media\/2364"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media?parent=3291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/categories?post=3291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/tags?post=3291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}