Skip to content

DOC: add Example sections to KernelFunction.from_prompt and invoke#14150

Open
shoumikchakravarty-dev wants to merge 2 commits into
microsoft:mainfrom
shoumikchakravarty-dev:DOC/add-examples-kernelfunction-from-prompt-invoke
Open

DOC: add Example sections to KernelFunction.from_prompt and invoke#14150
shoumikchakravarty-dev wants to merge 2 commits into
microsoft:mainfrom
shoumikchakravarty-dev:DOC/add-examples-kernelfunction-from-prompt-invoke

Conversation

@shoumikchakravarty-dev

Copy link
Copy Markdown

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.

Motivation and Context

Please help reviewers and future users, providing the following information:

  1. The from_prompt and invoke methods are the primary entry points for defining and running prompt-based functions in Semantic Kernel, yet their docstrings contain only a one-line description or a parameter list — no usage examples.
  2. Developers exploring the Semantic Kernel Python SDK through IDE tooltips, help(), or generated API docs currently see no usage examples for from_prompt and invoke
  3. Any scenario where a developer is getting started with Semantic Kernel's Python SDK and wants to understand how to define a prompt-based function and invoke it with arguments — without leaving their IDE or the API reference
  4. No open issue. This is a proactive documentation improvement spotted while exploring the Python SDK codebase.

Description

This PR adds illustrative code examples to two public methods in
KernelFunction that currently have minimal docstrings:

  • 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. No logic changes.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the SK Contribution Guidelines and the pre-submission formatting script raises no violations
  • All unit tests pass, and I have added new tests where possible (Documentation only PR)
  • I didn't break anyone 😄 (Documentation only PR)

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.
Copilot AI review requested due to automatic review settings July 13, 2026 01:43
@shoumikchakravarty-dev shoumikchakravarty-dev requested a review from a team as a code owner July 13, 2026 01:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds usage examples to two key public KernelFunction entry points in the Python SDK so developers can discover common workflows (creating prompt-based functions and invoking them) directly from docstrings / generated API docs.

Changes:

  • Expanded KernelFunction.from_prompt docstring with an example that creates a prompt function and registers it with a Kernel.
  • Expanded KernelFunction.invoke docstring with an async example invoking a prompt function using KernelArguments and OpenAIChatCompletion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread python/semantic_kernel/functions/kernel_function.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants