Semantic Kernel

1.39.4 · active · verified Sat Feb 28

Microsoft's open-source SDK for integrating LLMs into applications. Model-agnostic (OpenAI, Azure OpenAI, Google, Hugging Face, Mistral, etc.), supports Python, C#, and Java. Provides plugins (tools), prompt templating, multi-agent orchestration (AgentChat framework), and vector store integrations for RAG. Production-stable as of v1.x. Currently the primary Microsoft-maintained AI framework (AutoGen is maintenance-only; Microsoft Agent Framework is the future successor).

Warnings

Install

Imports

Quickstart

Basic chat completion with OpenAI

import asyncio
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
from semantic_kernel.connectors.ai.open_ai import OpenAIChatPromptExecutionSettings
from semantic_kernel.contents import ChatHistory

async def main():
    kernel = Kernel()
    kernel.add_service(OpenAIChatCompletion(ai_model_id="gpt-4o"))

    history = ChatHistory(system_message="You are a helpful assistant.")
    history.add_user_message("Hello, what can you do?")

    service = kernel.get_service(type=OpenAIChatCompletion)
    settings = OpenAIChatPromptExecutionSettings()
    response = await service.get_chat_message_content(chat_history=history, settings=settings, kernel=kernel)
    print(response.content)

asyncio.run(main())

view raw JSON →