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.00
# Semantic Kernel
1
2
Semantic 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.
3
4
## Package Information
5
6
- **Package Name**: semantic-kernel
7
- **Language**: Python
8
- **Installation**: `pip install semantic-kernel`
9
10
## Core Imports
11
12
```python
13
from semantic_kernel import Kernel
14
```
15
16
For specific functionality:
17
18
```python
19
# Functions and plugins
20
from semantic_kernel.functions import KernelFunction, KernelPlugin, kernel_function
21
22
# AI connectors
23
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion, AzureChatCompletion
24
25
# Content types
26
from semantic_kernel.contents import ChatHistory, ChatMessageContent
27
28
# Agents
29
from semantic_kernel.agents import ChatCompletionAgent, AgentGroupChat
30
```
31
32
## Basic Usage
33
34
```python
35
import asyncio
36
from semantic_kernel import Kernel
37
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
38
from semantic_kernel.contents import ChatHistory
39
from semantic_kernel.functions import kernel_function
40
41
# Initialize kernel with AI service
42
kernel = Kernel()
43
service = OpenAIChatCompletion(
44
service_id="chat-gpt",
45
ai_model_id="gpt-4",
46
api_key="your-api-key"
47
)
48
kernel.add_service(service)
49
50
# Create a simple function
51
class MathPlugin:
52
@kernel_function(name="add")
53
def add_numbers(self, a: int, b: int) -> int:
54
"""Add two integers."""
55
return a + b
56
57
# Add plugin to kernel
58
kernel.add_plugin(MathPlugin(), plugin_name="math")
59
60
# Execute function
61
async def main():
62
from semantic_kernel.functions import KernelArguments
63
arguments = KernelArguments(a=5, b=3)
64
result = await kernel.invoke(
65
function_name="add",
66
plugin_name="math",
67
arguments=arguments
68
)
69
print(f"Result: {result}")
70
71
asyncio.run(main())
72
```
73
74
## Architecture
75
76
Semantic Kernel follows a modular architecture centered around several key components:
77
78
- **Kernel**: Central orchestrator managing services, plugins, and execution
79
- **Functions**: Executable units of work that can be Python methods or AI prompts
80
- **Plugins**: Collections of related functions grouped by functionality
81
- **Connectors**: Integrations with AI services, vector databases, and external APIs
82
- **Agents**: Autonomous entities that can converse and collaborate
83
- **Contents**: Structured data types for messages, media, and function calls
84
- **Filters**: Middleware for intercepting and modifying execution flow
85
86
This design enables flexible composition of AI workflows, from simple function calls to complex multi-agent orchestration.
87
88
## Capabilities
89
90
### Core Kernel and Functions
91
92
The foundational classes for creating and executing functions, managing plugins, and orchestrating AI workflows. Includes the main Kernel class, function decorators, and plugin management.
93
94
```python { .api }
95
class Kernel:
96
def __init__(self, plugins=None, services=None, ai_service_selector=None): ...
97
async def invoke(self, function=None, arguments=None, function_name=None, plugin_name=None, **kwargs): ...
98
async def invoke_stream(self, function=None, arguments=None, function_name=None, plugin_name=None, **kwargs): ...
99
async def invoke_prompt(self, prompt: str, arguments=None, **kwargs): ...
100
async def invoke_prompt_stream(self, prompt: str, arguments=None, **kwargs): ...
101
def add_service(self, service): ...
102
def add_plugin(self, plugin, plugin_name: str): ...
103
104
@kernel_function
105
def function_decorator(func): ...
106
107
class KernelFunction:
108
def __init__(self, function, metadata): ...
109
async def invoke(self, kernel, arguments): ...
110
111
class KernelPlugin:
112
def __init__(self, name: str, functions: list): ...
113
```
114
115
[Core Kernel and Functions](./core-kernel.md)
116
117
### AI Connectors
118
119
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.
120
121
```python { .api }
122
class OpenAIChatCompletion:
123
def __init__(self, ai_model_id: str = None, service_id: str = None, api_key: str = None, org_id: str = None, **kwargs): ...
124
async def get_chat_message_contents(self, chat_history, settings): ...
125
126
class AzureChatCompletion:
127
def __init__(self, service_id: str = None, api_key: str = None, deployment_name: str = None, endpoint: str = None, **kwargs): ...
128
async def get_chat_message_contents(self, chat_history, settings): ...
129
130
class OpenAITextEmbedding:
131
def __init__(self, ai_model_id: str, api_key: str): ...
132
async def generate_embeddings(self, texts: list): ...
133
```
134
135
[AI Connectors](./ai-connectors.md)
136
137
### Content Types and Chat History
138
139
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.
140
141
```python { .api }
142
class ChatHistory:
143
def __init__(self, messages: list = None): ...
144
def add_message(self, message): ...
145
def add_user_message(self, content: str): ...
146
def add_assistant_message(self, content: str): ...
147
148
class ChatMessageContent:
149
def __init__(self, role: str, content: str, name: str = None): ...
150
151
class ImageContent:
152
def __init__(self, uri=None, data_uri=None, data=None, data_format=None, mime_type=None, **kwargs): ...
153
154
class FunctionCallContent:
155
def __init__(self, id: str, name: str, arguments: dict): ...
156
```
157
158
[Content Types and Chat History](./content-types.md)
159
160
### Agents and Multi-Agent Systems
161
162
Autonomous AI agents capable of conversation, collaboration, and orchestrated workflows. Supports various agent types, group chats, and orchestration patterns for complex multi-agent scenarios.
163
164
```python { .api }
165
class ChatCompletionAgent:
166
def __init__(self, *, arguments=None, description=None, function_choice_behavior=None,
167
id=None, instructions=None, kernel=None, name=None, plugins=None,
168
prompt_template_config=None, service=None): ...
169
async def invoke(self, history: ChatHistory): ...
170
171
class AgentGroupChat:
172
def __init__(self, agents: list): ...
173
async def invoke(self, message: str): ...
174
175
class OpenAIAssistantAgent:
176
def __init__(self, kernel: Kernel, service_id: str, name: str): ...
177
async def create_thread(self): ...
178
```
179
180
[Agents and Multi-Agent Systems](./agents.md)
181
182
### Memory and Vector Stores
183
184
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.
185
186
```python { .api }
187
class MemoryStore:
188
async def create_collection(self, collection_name: str): ...
189
async def upsert(self, collection_name: str, record): ...
190
async def get(self, collection_name: str, key: str): ...
191
async def search(self, collection_name: str, query_embedding: list): ...
192
```
193
194
[Memory and Vector Stores](./memory-stores.md)
195
196
### Core Plugins
197
198
Built-in plugins providing essential functionality including HTTP requests, mathematical operations, text processing, time operations, web search, and Python code execution.
199
200
```python { .api }
201
class HttpPlugin:
202
@kernel_function
203
async def get(self, url: str): ...
204
@kernel_function
205
async def post(self, url: str, body: str): ...
206
207
class MathPlugin:
208
@kernel_function
209
def add(self, value1: float, value2: float): ...
210
@kernel_function
211
def multiply(self, value1: float, value2: float): ...
212
213
class TextPlugin:
214
@kernel_function
215
def uppercase(self, input: str): ...
216
@kernel_function
217
def concat(self, input1: str, input2: str): ...
218
```
219
220
[Core Plugins](./core-plugins.md)
221
222
### Prompt Templates and Template Engines
223
224
Template systems for dynamic prompt generation supporting Handlebars, Jinja2, and native kernel template formats. Enables parameterized prompts with variable substitution and complex templating logic.
225
226
```python { .api }
227
class KernelPromptTemplate:
228
def __init__(self, template: str, config: PromptTemplateConfig): ...
229
async def render(self, kernel: Kernel, arguments: dict): ...
230
231
class HandlebarsPromptTemplate:
232
def __init__(self, template: str): ...
233
async def render(self, kernel: Kernel, arguments: dict): ...
234
235
class PromptTemplateConfig:
236
def __init__(self, template: str, input_variables: list): ...
237
```
238
239
[Prompt Templates](./prompt-templates.md)
240
241
### Filters and Middleware
242
243
Extensible filter system for intercepting and modifying function invocation, prompt rendering, and auto-function invocation. Enables custom middleware, logging, validation, and transformation logic.
244
245
```python { .api }
246
class FunctionInvocationContext:
247
def __init__(self, function, kernel, arguments): ...
248
249
class PromptRenderContext:
250
def __init__(self, function, kernel, arguments): ...
251
252
class AutoFunctionInvocationContext:
253
def __init__(self, function, kernel, arguments): ...
254
```
255
256
[Filters and Middleware](./filters.md)
257
258
### Process Framework
259
260
Structured workflow and business process automation capabilities enabling the creation of complex, multi-step AI workflows with state management and orchestration.
261
262
```python { .api }
263
class ProcessBuilder:
264
def __init__(self): ...
265
def add_step(self, step): ...
266
def build(self): ...
267
```
268
269
[Process Framework](./processes.md)