From 74026e2d27aee1283924c8b4e3720f4b4449cfbb Mon Sep 17 00:00:00 2001 From: Shoumik Chakravarty Date: Sun, 12 Jul 2026 20:31:20 -0500 Subject: [PATCH 1/5] DOC: add Example sections to KernelFunction.from_prompt and invoke Add illustrative code examples to two public methods in KernelFunction: - from_prompt: shows creating a prompt-based function and registering it with the kernel - invoke: shows async invocation with KernelArguments using OpenAIChatCompletion Both examples follow the existing Google-style docstring convention used throughout the module. --- .../functions/kernel_function.py | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/python/semantic_kernel/functions/kernel_function.py b/python/semantic_kernel/functions/kernel_function.py index 15f2ab34c6b7..4753cb8ac793 100644 --- a/python/semantic_kernel/functions/kernel_function.py +++ b/python/semantic_kernel/functions/kernel_function.py @@ -138,7 +138,26 @@ def from_prompt( "PromptExecutionSettings | Sequence[PromptExecutionSettings] | Mapping[str, PromptExecutionSettings] | None" ) = None, ) -> "KernelFunctionFromPrompt": - """Create a new instance of the KernelFunctionFromPrompt class.""" + """Create a new instance of the KernelFunctionFromPrompt class. + + Example: + Create a prompt-based function and register it with the kernel: + + from semantic_kernel import Kernel + from semantic_kernel.functions import KernelFunction + + kernel = Kernel() + func = KernelFunction.from_prompt( + function_name="summarize", + plugin_name="WriterPlugin", + description="Summarizes the provided text in one sentence.", + prompt="Summarize the following in one sentence: {{$input}}", + ) + kernel.add_function(plugin_name="WriterPlugin", function=func) + print(func.name) # summarize + print(func.plugin_name) # WriterPlugin + print(func.is_prompt) # True + """ from semantic_kernel.functions.kernel_function_from_prompt import KernelFunctionFromPrompt return KernelFunctionFromPrompt( @@ -255,6 +274,32 @@ async def invoke( Returns: FunctionResult: The result of the function + + Example: + Invoke a prompt function with arguments: + + import asyncio + from semantic_kernel import Kernel + from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion + from semantic_kernel.functions import KernelArguments, KernelFunction + + async def main(): + kernel = Kernel() + kernel.add_service(OpenAIChatCompletion(service_id="default")) + func = KernelFunction.from_prompt( + function_name="summarize", + plugin_name="WriterPlugin", + prompt="Summarize the following in one sentence: {{$input}}", + ) + result = await func.invoke( + kernel=kernel, + arguments=KernelArguments( + input="Azure API Management is a fully managed gateway service." + ), + ) + print(result) + + asyncio.run(main()) """ if arguments is None: arguments = KernelArguments(**kwargs) From e291eba2cb3748951dfe385bd3d1de4ef44ca719 Mon Sep 17 00:00:00 2001 From: Shoumik Chakravarty Date: Sun, 12 Jul 2026 20:50:00 -0500 Subject: [PATCH 2/5] =?UTF-8?q?DOC:=20address=20Copilot=20review=20?= =?UTF-8?q?=E2=80=94=20add=20ai=5Fmodel=5Fid=20and=20API=20key=20note=20to?= =?UTF-8?q?=20invoke=20example?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/semantic_kernel/functions/kernel_function.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/semantic_kernel/functions/kernel_function.py b/python/semantic_kernel/functions/kernel_function.py index 4753cb8ac793..6213d38040a3 100644 --- a/python/semantic_kernel/functions/kernel_function.py +++ b/python/semantic_kernel/functions/kernel_function.py @@ -285,7 +285,8 @@ async def invoke( async def main(): kernel = Kernel() - kernel.add_service(OpenAIChatCompletion(service_id="default")) + # Requires OPENAI_API_KEY env var (or pass api_key explicitly). + kernel.add_service(OpenAIChatCompletion(ai_model_id="gpt-4o-mini", service_id="default")) func = KernelFunction.from_prompt( function_name="summarize", plugin_name="WriterPlugin", From 181b83e335216788fb0ccc972f2a738d90a881e5 Mon Sep 17 00:00:00 2001 From: Shoumik Chakravarty Date: Thu, 23 Jul 2026 23:23:55 -0500 Subject: [PATCH 3/5] =?UTF-8?q?DOC:=20address=20Copilot=20review=20?= =?UTF-8?q?=E2=80=94=20fix=20Args/Returns=20types=20on=20invoke=20docstrin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/semantic_kernel/functions/kernel_function.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/semantic_kernel/functions/kernel_function.py b/python/semantic_kernel/functions/kernel_function.py index 6213d38040a3..aa3eb67a1564 100644 --- a/python/semantic_kernel/functions/kernel_function.py +++ b/python/semantic_kernel/functions/kernel_function.py @@ -267,13 +267,14 @@ async def invoke( Args: kernel (Kernel): The kernel - arguments (KernelArguments): The Kernel arguments - metadata (Dict[str, Any]): Additional metadata. + arguments (KernelArguments | None): The Kernel arguments. Optional; defaults to None, + in which case arguments are built from kwargs. + metadata (dict[str, Any] | None): Additional metadata. Optional; defaults to None. kwargs (Any): Additional keyword arguments that will be added to the KernelArguments. Returns: - FunctionResult: The result of the function + FunctionResult | None: The result of the function, or None if no result is produced. Example: Invoke a prompt function with arguments: From 7fde85d4a7c8d9b951b3f34f227d5689261a1771 Mon Sep 17 00:00:00 2001 From: Shoumik Chakravarty Date: Tue, 28 Jul 2026 00:37:42 -0500 Subject: [PATCH 4/5] =?UTF-8?q?DOC:=20address=20review=20=E2=80=94=20use?= =?UTF-8?q?=20..=20code-block::=20python=20directive=20in=20Example=20bloc?= =?UTF-8?q?ks=20(from=5Fprompt,=20invoke)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/semantic_kernel/functions/kernel_function.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/semantic_kernel/functions/kernel_function.py b/python/semantic_kernel/functions/kernel_function.py index aa3eb67a1564..50c28d576c79 100644 --- a/python/semantic_kernel/functions/kernel_function.py +++ b/python/semantic_kernel/functions/kernel_function.py @@ -143,6 +143,8 @@ def from_prompt( Example: Create a prompt-based function and register it with the kernel: + .. code-block:: python + from semantic_kernel import Kernel from semantic_kernel.functions import KernelFunction @@ -279,6 +281,8 @@ async def invoke( Example: Invoke a prompt function with arguments: + .. code-block:: python + import asyncio from semantic_kernel import Kernel from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion From 6818b3c44c9f3c7f9eff16c3280ac82535146654 Mon Sep 17 00:00:00 2001 From: Shoumik Chakravarty Date: Tue, 28 Jul 2026 22:49:06 -0500 Subject: [PATCH 5/5] DOC: apply ruff-format docstring-code formatting --- python/semantic_kernel/functions/kernel_function.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/semantic_kernel/functions/kernel_function.py b/python/semantic_kernel/functions/kernel_function.py index 50c28d576c79..d6386480d31d 100644 --- a/python/semantic_kernel/functions/kernel_function.py +++ b/python/semantic_kernel/functions/kernel_function.py @@ -156,9 +156,9 @@ def from_prompt( prompt="Summarize the following in one sentence: {{$input}}", ) kernel.add_function(plugin_name="WriterPlugin", function=func) - print(func.name) # summarize + print(func.name) # summarize print(func.plugin_name) # WriterPlugin - print(func.is_prompt) # True + print(func.is_prompt) # True """ from semantic_kernel.functions.kernel_function_from_prompt import KernelFunctionFromPrompt @@ -288,6 +288,7 @@ async def invoke( from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion from semantic_kernel.functions import KernelArguments, KernelFunction + async def main(): kernel = Kernel() # Requires OPENAI_API_KEY env var (or pass api_key explicitly). @@ -299,12 +300,11 @@ async def main(): ) result = await func.invoke( kernel=kernel, - arguments=KernelArguments( - input="Azure API Management is a fully managed gateway service." - ), + arguments=KernelArguments(input="Azure API Management is a fully managed gateway service."), ) print(result) + asyncio.run(main()) """ if arguments is None: