Semantic Kernel Python SDK - comprehensive AI development framework for building AI agents and multi-agent systems
npx @tessl/cli install tessl/pypi-semantic-kernel@1.36.0Semantic Kernel is a comprehensive AI development framework that enables developers to build, orchestrate, and deploy AI agents and multi-agent systems. It provides a flexible plugin ecosystem supporting multiple integration types including Python, OpenAPI, and Model Context Protocol (MCP), with extensive LLM support across OpenAI, Azure OpenAI, Hugging Face, Mistral, Vertex AI, ONNX, Ollama, NVIDIA NIM, and other providers.
pip install semantic-kernelfrom semantic_kernel import KernelFor specific functionality:
# Functions and plugins
from semantic_kernel.functions import KernelFunction, KernelPlugin, kernel_function
# AI connectors
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion, AzureChatCompletion
# Content types
from semantic_kernel.contents import ChatHistory, ChatMessageContent
# Agents
from semantic_kernel.agents import ChatCompletionAgent, AgentGroupChatimport asyncio
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
from semantic_kernel.contents import ChatHistory
from semantic_kernel.functions import kernel_function
# Initialize kernel with AI service
kernel = Kernel()
service = OpenAIChatCompletion(
service_id="chat-gpt",
ai_model_id="gpt-4",
api_key="your-api-key"
)
kernel.add_service(service)
# Create a simple function
class MathPlugin:
@kernel_function(name="add")
def add_numbers(self, a: int, b: int) -> int:
"""Add two integers."""
return a + b
# Add plugin to kernel
kernel.add_plugin(MathPlugin(), plugin_name="math")
# Execute function
async def main():
from semantic_kernel.functions import KernelArguments
arguments = KernelArguments(a=5, b=3)
result = await kernel.invoke(
function_name="add",
plugin_name="math",
arguments=arguments
)
print(f"Result: {result}")
asyncio.run(main())Semantic Kernel follows a modular architecture centered around several key components:
This design enables flexible composition of AI workflows, from simple function calls to complex multi-agent orchestration.
The foundational classes for creating and executing functions, managing plugins, and orchestrating AI workflows. Includes the main Kernel class, function decorators, and plugin management.
class Kernel:
def __init__(self, plugins=None, services=None, ai_service_selector=None): ...
async def invoke(self, function=None, arguments=None, function_name=None, plugin_name=None, **kwargs): ...
async def invoke_stream(self, function=None, arguments=None, function_name=None, plugin_name=None, **kwargs): ...
async def invoke_prompt(self, prompt: str, arguments=None, **kwargs): ...
async def invoke_prompt_stream(self, prompt: str, arguments=None, **kwargs): ...
def add_service(self, service): ...
def add_plugin(self, plugin, plugin_name: str): ...
@kernel_function
def function_decorator(func): ...
class KernelFunction:
def __init__(self, function, metadata): ...
async def invoke(self, kernel, arguments): ...
class KernelPlugin:
def __init__(self, name: str, functions: list): ...Comprehensive integrations with major AI providers including chat completions, embeddings, text-to-speech, image generation, and real-time communication capabilities across OpenAI, Azure, Google, Anthropic, and other providers.
class OpenAIChatCompletion:
def __init__(self, ai_model_id: str = None, service_id: str = None, api_key: str = None, org_id: str = None, **kwargs): ...
async def get_chat_message_contents(self, chat_history, settings): ...
class AzureChatCompletion:
def __init__(self, service_id: str = None, api_key: str = None, deployment_name: str = None, endpoint: str = None, **kwargs): ...
async def get_chat_message_contents(self, chat_history, settings): ...
class OpenAITextEmbedding:
def __init__(self, ai_model_id: str, api_key: str): ...
async def generate_embeddings(self, texts: list): ...Structured data types for representing messages, media content, function calls, and conversation history. Includes support for text, images, audio, streaming content, and real-time events.
class ChatHistory:
def __init__(self, messages: list = None): ...
def add_message(self, message): ...
def add_user_message(self, content: str): ...
def add_assistant_message(self, content: str): ...
class ChatMessageContent:
def __init__(self, role: str, content: str, name: str = None): ...
class ImageContent:
def __init__(self, uri=None, data_uri=None, data=None, data_format=None, mime_type=None, **kwargs): ...
class FunctionCallContent:
def __init__(self, id: str, name: str, arguments: dict): ...Content Types and Chat History
Autonomous AI agents capable of conversation, collaboration, and orchestrated workflows. Supports various agent types, group chats, and orchestration patterns for complex multi-agent scenarios.
class ChatCompletionAgent:
def __init__(self, *, arguments=None, description=None, function_choice_behavior=None,
id=None, instructions=None, kernel=None, name=None, plugins=None,
prompt_template_config=None, service=None): ...
async def invoke(self, history: ChatHistory): ...
class AgentGroupChat:
def __init__(self, agents: list): ...
async def invoke(self, message: str): ...
class OpenAIAssistantAgent:
def __init__(self, kernel: Kernel, service_id: str, name: str): ...
async def create_thread(self): ...Agents and Multi-Agent Systems
Vector database integrations for semantic memory, embeddings storage, and retrieval-augmented generation. Supports popular vector stores including Chroma, Pinecone, Qdrant, Redis, and Azure Cognitive Search.
class MemoryStore:
async def create_collection(self, collection_name: str): ...
async def upsert(self, collection_name: str, record): ...
async def get(self, collection_name: str, key: str): ...
async def search(self, collection_name: str, query_embedding: list): ...Built-in plugins providing essential functionality including HTTP requests, mathematical operations, text processing, time operations, web search, and Python code execution.
class HttpPlugin:
@kernel_function
async def get(self, url: str): ...
@kernel_function
async def post(self, url: str, body: str): ...
class MathPlugin:
@kernel_function
def add(self, value1: float, value2: float): ...
@kernel_function
def multiply(self, value1: float, value2: float): ...
class TextPlugin:
@kernel_function
def uppercase(self, input: str): ...
@kernel_function
def concat(self, input1: str, input2: str): ...Template systems for dynamic prompt generation supporting Handlebars, Jinja2, and native kernel template formats. Enables parameterized prompts with variable substitution and complex templating logic.
class KernelPromptTemplate:
def __init__(self, template: str, config: PromptTemplateConfig): ...
async def render(self, kernel: Kernel, arguments: dict): ...
class HandlebarsPromptTemplate:
def __init__(self, template: str): ...
async def render(self, kernel: Kernel, arguments: dict): ...
class PromptTemplateConfig:
def __init__(self, template: str, input_variables: list): ...Extensible filter system for intercepting and modifying function invocation, prompt rendering, and auto-function invocation. Enables custom middleware, logging, validation, and transformation logic.
class FunctionInvocationContext:
def __init__(self, function, kernel, arguments): ...
class PromptRenderContext:
def __init__(self, function, kernel, arguments): ...
class AutoFunctionInvocationContext:
def __init__(self, function, kernel, arguments): ...Structured workflow and business process automation capabilities enabling the creation of complex, multi-step AI workflows with state management and orchestration.
class ProcessBuilder:
def __init__(self): ...
def add_step(self, step): ...
def build(self): ...