Skip to main content

Promptflow Tool Semantic Kernel

A Python package that integrates Semantic Kernel with Azure Prompt Flow, enabling efficient LLM application development.

Quality Gate Status Coverage Lines of Code Maintainability Rating Duplicated Lines (%)

Why?

This tool bridges the powerful execution flow of Promptflow with the advanced ReAct capabilities of Semantic Kernel, offering several advantages:

  • Easily pre-process or post-process data from your main assistant with minimal configuration.
  • Leverage Semantic Kernel's planning and reasoning capabilities within your Prompt Flow applications by just providing configuration.
  • Connect to a variety of LLM providers beyond OpenAI, including Anthropic Claude, Amazon Bedrock, Llama, and more through Semantic Kernel's connectors.
  • Access Semantic Kernel's growing plugin ecosystem to extend functionality without writing custom code.
  • Use Promptflow's UI and batch evaluation with your semantic kernel assistant.

The integration creates a best-of-both-worlds solution, combining Promptflow's orchestration capabilities with Semantic Kernel's flexibility and plugin architecture.

Installation

Install the package from PyPI:

pip install promptflow-tool-semantic-kernel

You can find the package on PyPI.

Usage

In VSCode Promptflow

Once installed, the Semantic Kernel tool will be available in your Promptflow tools collection:

New Tool in Sidebar

  1. Create a new promptflow in VSCode
  2. Add a custom LLM tool node
  3. Select "Semantic Kernel LLM Tool" from the tool list
  4. Configure the following parameters:
    • Connection (Azure OpenAI or OpenAI)
    • Deployment name (model name for OpenAI or deployment name for Azure)
    • Chat history (optional)
    • Plugins (optional)
    • Customize your prompt as needed

Semantic Kernel Chat

Running the Demo

The package includes a simple demo script:

# Set up environment variables
export AZURE_OPENAI_API_KEY=your_api_key
export AZURE_OPENAI_ENDPOINT=your_endpoint
export AZURE_OPENAI_DEPLOYMENT_NAME=your_deployment_name

# Run the demo
python -m scripts.main

Using different connections

Google Gemini

Add a CustomConnection via promptflow in vscode as follows, important is that api_type: "google":

$schema: https://azuremlschemas.azureedge.net/promptflow/latest/CustomConnection.schema.json
name: "google_gemini"
type: custom
configs:
  api_type: "google"
  model_id: "gemini-2.0-flash"
secrets:
  # Use'<no-change>' to keep original value or '<user-input>' to update it when the application runs.
  api_key: "<user-input>"

Adding Custom Plugins

Semantic Kernel allows you to easily extend functionality through plugins. Learn more about creating a native plugin.

Here's how to use plugins with this tool:

Built-in Plugins

The tool comes with a built-in LightsPlugin for demonstration:

# Default plugin configuration
plugins = [
     {
          "name": "lights",
          "class": "LightsPlugin",
          "module": "promptflow_tool_semantic_kernel.tools.lights_plugin"
     }
]

Configuring with flow.dag.yaml

You can also configure the tool using a flow.dag.yaml file. This file defines the flow and its components, including the semantic_kernel_chat tool and its plugins. Here is an example configuration:

# filepath: /workspaces/promptflow-tool-semantic-kernel/tests/system/flow.dag.yaml
$schema: https://azuremlschemas.azureedge.net/promptflow/latest/Flow.schema.json
environment:
     python_requirements_txt: requirements.txt
environment_variables:
     PROMPTFLOW_SERVING_ENGINE: fastapi
     PF_DISABLE_TRACING: "false"
inputs:
     chat_history:
          type: list
          is_chat_history: true
          default: []
     question:
          type: string
          is_chat_input: true
outputs:
     answer:
          type: string
          reference: ${semantic_kernel_chat.output}
          is_chat_output: true
nodes:
- name: semantic_kernel_chat
     type: custom_llm
     source:
          type: package_with_prompt
          tool: promptflow_tool_semantic_kernel.tools.semantic_kernel_tool.semantic_kernel_chat
          path: semantic_kernel_chat.jinja2
     inputs:
          connection: open_ai_connection
          deployment_name: gpt-4
          chat_history: ${inputs.chat_history}
          question: ${inputs.question}
          plugins: |
               [
               {
                    "name": "lights",
                    "class": "LightsPlugin",
                    "module": "promptflow_tool_semantic_kernel.tools.lights_plugin"
               }
               ]

This configuration allows you to leverage the power of plugins within your flow. You can define multiple plugins to extend the functionality of the semantic_kernel_chat tool. Each plugin is specified with its name, class, and module, making it easy to integrate and customize as needed.

Development

Setup

  1. Clone the repository
    git clone git@github.com:FabianSchurig/promptflow-tool-semantic-kernel.git
    cd promptflow-tool-semantic-kernel
    cp .devcontainer/devcontainer.env.example .devcontainer/devcontainer.env
    
  2. Start the devcontainer with vs code
  3. Install development dependencies (should automatically run):
    poetry install
    
  4. Activate the environment
    eval $(poetry env activate)
    which python
    uvicorn tests.system.api:app --workers 1 --port 5000
    

Testing

Run the tests with pytest:

poetry run pytest
poetry run pytest --cov-report xml:coverage.xml --cov-report term --cov=promptflow_tool_semantic_kernel --cov-config=.coveragerc tests/

License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) - see the LICENSE file for details.

Metadata

Release files for promptflow-tool-semantic-kernel 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for promptflow-tool-semantic-kernel 0.2.3
File Size Uploaded Provenance Actions
promptflow_tool_semantic_kernel-0.2.3.tar.gz 28.9 kB Without provenance Details for promptflow_tool_semantic_kernel-0.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for promptflow-tool-semantic-kernel 0.2.3
File Interpreter ABI Platform Actions
promptflow_tool_semantic_kernel-0.2.3-cp312-cp312-manylinux_2_36_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.36+ x86-64 Details for promptflow_tool_semantic_kernel-0.2.3-cp312-cp312-manylinux_2_36_x86_64.whl

Total release size: 57.5 kB

Release files / promptflow_tool_semantic_kernel-0.2.3.tar.gz

Download URL promptflow_tool_semantic_kernel-0.2.3.tar.gz
Size 28.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ec101866c90ddcca27778ec973ee9afe78148e02ef53a35c96074c6c711f8c31
BLAKE2b-256 checksum
How to use checksums
f788f1758df9f6baf3c8e824b76dd830f7b90e20ff9a8d1312841e429e585d30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.12.9 Linux/6.8.0-1021-azure

Release files / promptflow_tool_semantic_kernel-0.2.3-cp312-cp312-manylinux_2_36_x86_64.whl

Download URL promptflow_tool_semantic_kernel-0.2.3-cp312-cp312-manylinux_2_36_x86_64.whl
Size 28.5 kB
Tags CPython 3.12 Linux glibc 2.36+ x86-64
SHA-256 checksum
How to use checksums
26074f57ea00f4d8dc13e92f9dbb28fd02fcc9ee78dc73b6b5fd8839dd98d122
BLAKE2b-256 checksum
How to use checksums
3bf5617002ac2418c40c5dcf495c00912e22a8bed924413d832a275275ceb62b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.12.9 Linux/6.8.0-1021-azure

Security for promptflow-tool-semantic-kernel 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page