Skip to content

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

Open
Shoumik Chakravarty (shoumikchakravarty-dev) wants to merge 5 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
Shoumik Chakravarty (shoumikchakravarty-dev) wants to merge 5 commits into
microsoft:mainfrom
shoumikchakravarty-dev:DOC/add-examples-kernelfunction-from-prompt-invoke

Conversation

@shoumikchakravarty-dev

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)

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
@shoumikchakravarty-dev

Copy link
Copy Markdown
Author

Hello Gatekeepers , This is my first submission to update on the Kernel function documents. Please review & let me know if this needs any changes.

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread python/semantic_kernel/functions/kernel_function.py

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@shoumikchakravarty-dev

Copy link
Copy Markdown
Author

Hi SergeyMenshykh , apologies for the direct ping — CODEOWNERS points at microsoft/octo-semantickernel-pr-python and I noticed you've been active in this area recently. This PR has 7 pending workflow approvals blocking human review; would you (or someone you can route me to) be able to trigger the runs? Happy to rebase if the branch has gone stale. Thanks!

Comment thread python/semantic_kernel/functions/kernel_function.py
@github-actions

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
functions
   kernel_function.py2055374%111, 113, 320, 335–339, 392, 418–423, 480, 482, 484, 486–487, 489–490, 494–502, 506–507, 509–527, 529
TOTAL28967563980% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4074 23 💤 0 ❌ 0 🔥 2m 14s ⏱️

@moonbox3

Copy link
Copy Markdown
Collaborator

Please have a look at the CI/CD failures.

@shoumikchakravarty-dev

Copy link
Copy Markdown
Author

Please have a look at the CI/CD failures.

Hi Evan Mattson (@moonbox3) — took care of the CI failures; there was an ruff-format issue with the embedded docstring code, which is now fixed. waiting for the integration test check to be finished.

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@shoumikchakravarty-dev

Copy link
Copy Markdown
Author

Evan Mattson (@moonbox3) - I think the python-integration-tests-check workflow is waiting on maintainer approval to run. Could you trigger it when you get a moment? Thanks!

@shoumikchakravarty-dev

Copy link
Copy Markdown
Author

Hi Evan Mattson (@moonbox3) / SergeyMenshykh — friendly check-in on this one. Applied the ruff-format fixes from your earlier feedback and CI is green on the checks that run automatically. The python-integration-tests-check workflow is still pending workflow approval — happy to make any additional changes if you want to see anything else before we get it moving. Thanks!

@shoumikchakravarty-dev

Copy link
Copy Markdown
Author

The current failing test (tests/unit/connectors/mcp/test_mcp.py) is unrelated to this PR — the root cause is:
ImportError: cannot import name 'streamablehttp_client' from 'mcp.client.streamable_http'

My PR only touches docstring formatting in KernelFunction.from_prompt and KernelFunction.invoke — no MCP code paths or dependencies are touched. Likely a version pin issue in uv.lock.

Happy to rebase against latest main if the dependency has been updated there. Let me know how you'd like to proceed.

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.
@shoumikchakravarty-dev
Shoumik Chakravarty (shoumikchakravarty-dev) force-pushed the DOC/add-examples-kernelfunction-from-prompt-invoke branch from f1d6fae to 6818b3c Compare August 5, 2026 04:23
@shoumikchakravarty-dev

Copy link
Copy Markdown
Author

Rebased against latest main. Automated CI is running; python-integration-tests-check is again pending workflow approval. Standing by for review.

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.

3 participants