Files
semantic-kernel/python
dependabot[bot]andEvan Mattson 7300b843c1 Python: Update pyarrow requirement from <21.0,>=12.0 to >=12.0,<22.0 in /python (#12836)
Updates the requirements on [pyarrow](https://github.com/apache/arrow)
to permit the latest version.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/apache/arrow/releases">pyarrow's
releases</a>.</em></p>
<blockquote>
<h2>Apache Arrow 21.0.0</h2>
<p>Release Notes URL: <a
href="https://arrow.apache.org/release/21.0.0.html">https://arrow.apache.org/release/21.0.0.html</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/apache/arrow/commit/ee4d09ebef61c663c1efbfa4c18e518a03b798be"><code>ee4d09e</code></a>
MINOR: [Release] Update versions for 21.0.0</li>
<li><a
href="https://github.com/apache/arrow/commit/f13a5796008e3a5e546af1a7b2be0fbd3c148c26"><code>f13a579</code></a>
MINOR: [Release] Update .deb/.rpm changelogs for 21.0.0</li>
<li><a
href="https://github.com/apache/arrow/commit/6fd2a167e0ed74dbe4c059e579a561fcc2aae11f"><code>6fd2a16</code></a>
MINOR: [Release] Update CHANGELOG.md for 21.0.0</li>
<li><a
href="https://github.com/apache/arrow/commit/cf261bf58ae74a1f7fa99d81c201ca8e1d679c9b"><code>cf261bf</code></a>
<a
href="https://redirect.github.com/apache/arrow/issues/47078">GH-47078</a>:
[Release] Ensure using cloned apache/arrow for reproducible check
(...</li>
<li><a
href="https://github.com/apache/arrow/commit/ddbc3dc005dfdde5a79d42cb5953190479b12b73"><code>ddbc3dc</code></a>
<a
href="https://redirect.github.com/apache/arrow/issues/47074">GH-47074</a>:
[Release] Use reproducible mtime for csharp/ in source archive (<a
href="https://redirect.github.com/apache/arrow/issues/47">#47</a>...</li>
<li><a
href="https://github.com/apache/arrow/commit/0534eb2d279f445ac67b99a22eca344484749b6f"><code>0534eb2</code></a>
<a
href="https://redirect.github.com/apache/arrow/issues/47071">GH-47071</a>:
[Release] Dereference all hard links in source archive (<a
href="https://redirect.github.com/apache/arrow/issues/47072">#47072</a>)</li>
<li><a
href="https://github.com/apache/arrow/commit/f845b4184664aee522f7fd73864d3093e84b6580"><code>f845b41</code></a>
<a
href="https://redirect.github.com/apache/arrow/issues/47069">GH-47069</a>:
[Release] Add missing &quot;needs: target&quot; (<a
href="https://redirect.github.com/apache/arrow/issues/47070">#47070</a>)</li>
<li><a
href="https://github.com/apache/arrow/commit/1c08f8ee6947bd2a9bffb441af946c6a7373015b"><code>1c08f8e</code></a>
<a
href="https://redirect.github.com/apache/arrow/issues/47067">GH-47067</a>:
[Release] Fix wrong GitHub Actions context in verify_rc.yml (<a
href="https://redirect.github.com/apache/arrow/issues/47068">#47068</a>)</li>
<li><a
href="https://github.com/apache/arrow/commit/70e5c51e6d5de1ca6f669b47ff0b98e1075336d0"><code>70e5c51</code></a>
<a
href="https://redirect.github.com/apache/arrow/issues/47065">GH-47065</a>:
[Release] Fix timeout key in verify_rc.yml (<a
href="https://redirect.github.com/apache/arrow/issues/47066">#47066</a>)</li>
<li><a
href="https://github.com/apache/arrow/commit/254a85c8bddb52eef03d623882836717f027061d"><code>254a85c</code></a>
<a
href="https://redirect.github.com/apache/arrow/issues/47063">GH-47063</a>:
[Release] Define missing RELEASE_TARBALL (<a
href="https://redirect.github.com/apache/arrow/issues/47064">#47064</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/apache/arrow/compare/go/v12.0.0...apache-arrow-21.0.0">compare
view</a></li>
</ul>
</details>
<br />


Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Evan Mattson <[email protected]>
2025-08-05 01:33:57 +00:00
..
2023-04-13 16:12:36 -07:00
2024-08-27 16:45:09 +00:00

Get Started with Semantic Kernel Python

Highlights

  • Flexible Agent Framework: build, orchestrate, and deploy AI agents and multi-agent systems
  • Multi-Agent Systems: Model workflows and collaboration between AI specialists
  • Plugin Ecosystem: Extend with Python, OpenAPI, Model Context Protocol (MCP), and more
  • LLM Support: OpenAI, Azure OpenAI, Hugging Face, Mistral, Vertex AI, ONNX, Ollama, NVIDIA NIM, and others
  • Vector DB Support: Azure AI Search, Elasticsearch, Chroma, and more
  • Process Framework: Build structured business processes with workflow modeling
  • Multimodal: Text, vision, audio

Quick Install

pip install --upgrade semantic-kernel
# Optional: Add integrations
pip install --upgrade semantic-kernel[hugging_face]
pip install --upgrade semantic-kernel[all]

Supported Platforms:

  • Python: 3.10+
  • OS: Windows, macOS, Linux

1. Setup API Keys

Set as environment variables, or create a .env file at your project root:

OPENAI_API_KEY=sk-...
OPENAI_CHAT_MODEL_ID=...
...
AZURE_OPENAI_API_KEY=...
AZURE_OPENAI_ENDPOINT=...
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=...
...

You can also override environment variables by explicitly passing configuration parameters to the AI service constructor:

chat_service = AzureChatCompletion(
    api_key=...,
    endpoint=...,
    deployment_name=...,
    api_version=...,
)

See the following setup guide for more information.

2. Use the Kernel for Prompt Engineering

Create prompt functions and invoke them via the Kernel:

import asyncio
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
from semantic_kernel.functions import KernelArguments

kernel = Kernel()
kernel.add_service(OpenAIChatCompletion())

prompt = """
1) A robot may not injure a human being...
2) A robot must obey orders given it by human beings...
3) A robot must protect its own existence...

Give me the TLDR in exactly {{$num_words}} words."""


async def main():
    result = await kernel.invoke_prompt(prompt, arguments=KernelArguments(num_words=5))
    print(result)


asyncio.run(main())
# Output: Protect humans, obey, self-preserve, prioritized.

3. Directly Use AI Services (No Kernel Required)

You can use the AI service classes directly for advanced workflows:

import asyncio
import asyncio

from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion, OpenAIChatPromptExecutionSettings
from semantic_kernel.contents import ChatHistory


async def main():
    service = OpenAIChatCompletion()
    settings = OpenAIChatPromptExecutionSettings()

    chat_history = ChatHistory(system_message="You are a helpful assistant.")
    chat_history.add_user_message("Write a haiku about Semantic Kernel.")
    response = await service.get_chat_message_content(chat_history=chat_history, settings=settings)
    print(response.content)

    """
    Output:

    Thoughts weave through context,  
    Semantic threads interlace—  
    Kernel sparks meaning.
    """


asyncio.run(main())

4. Build an Agent with Plugins and Tools

Add Python functions as plugins or Pydantic models as structured outputs;

Enhance your agent with custom tools (plugins) and structured output:

import asyncio
from typing import Annotated
from pydantic import BaseModel
from semantic_kernel.agents import ChatCompletionAgent
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatPromptExecutionSettings
from semantic_kernel.functions import kernel_function, KernelArguments

class MenuPlugin:
    @kernel_function(description="Provides a list of specials from the menu.")
    def get_specials(self) -> Annotated[str, "Returns the specials from the menu."]:
        return """
        Special Soup: Clam Chowder
        Special Salad: Cobb Salad
        Special Drink: Chai Tea
        """

    @kernel_function(description="Provides the price of the requested menu item.")
    def get_item_price(
        self, menu_item: Annotated[str, "The name of the menu item."]
    ) -> Annotated[str, "Returns the price of the menu item."]:
        return "$9.99"

class MenuItem(BaseModel):
    # Used for structured outputs
    price: float
    name: str

async def main():
    # Configure structured outputs format
    settings = OpenAIChatPromptExecutionSettings()
    settings.response_format = MenuItem

    # Create agent with plugin and settings
    agent = ChatCompletionAgent(
        service=AzureChatCompletion(),
        name="SK-Assistant",
        instructions="You are a helpful assistant.",
        plugins=[MenuPlugin()],
        arguments=KernelArguments(settings)
    )

    response = await agent.get_response("What is the price of the soup special?")
    print(response.content)

    # Output:
    # The price of the Clam Chowder, which is the soup special, is $9.99.

asyncio.run(main()) 

You can explore additional getting started agent samples here.

5. Multi-Agent Orchestration

Coordinate a group of agents to iteratively solve a problem or refine content together:

import asyncio
from semantic_kernel.agents import ChatCompletionAgent, GroupChatOrchestration, RoundRobinGroupChatManager
from semantic_kernel.agents.runtime import InProcessRuntime
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion

def get_agents():
    return [
        ChatCompletionAgent(
            name="Writer",
            instructions="You are a creative content writer. Generate and refine slogans based on feedback.",
            service=AzureChatCompletion(),
        ),
        ChatCompletionAgent(
            name="Reviewer",
            instructions="You are a critical reviewer. Provide detailed feedback on proposed slogans.",
            service=AzureChatCompletion(),
        ),
    ]

async def main():
    agents = get_agents()
    group_chat = GroupChatOrchestration(
        members=agents,
        manager=RoundRobinGroupChatManager(max_rounds=5),
    )
    runtime = InProcessRuntime()
    runtime.start()
    result = await group_chat.invoke(
        task="Create a slogan for a new electric SUV that is affordable and fun to drive.",
        runtime=runtime,
    )
    value = await result.get()
    print(f"Final Slogan: {value}")

    # Example Output:
    # Final Slogan: "Feel the Charge: Adventure Meets Affordability in Your New Electric SUV!"

    await runtime.stop_when_idle()

if __name__ == "__main__":
    asyncio.run(main())

For orchestration-focused examples, see these orchestration samples.

More Examples & Notebooks

Semantic Kernel Documentation