0
# Core Plugins
1
2
Built-in plugins providing essential functionality including HTTP requests, mathematical operations, text processing, time operations, web search, conversation summarization, and Python code execution.
3
4
## Capabilities
5
6
### HTTP Plugin
7
8
HTTP client functionality for making web requests and API calls.
9
10
```python { .api }
11
class HttpPlugin:
12
"""
13
Plugin for making HTTP requests.
14
"""
15
16
@kernel_function(description="Send HTTP GET request")
17
async def get(self, url: str, headers: str = "") -> str:
18
"""
19
Send HTTP GET request.
20
21
Parameters:
22
- url: Target URL for the request
23
- headers: Optional headers as JSON string
24
25
Returns:
26
Response content as string
27
"""
28
29
@kernel_function(description="Send HTTP POST request")
30
async def post(self, url: str, body: str = "", headers: str = "") -> str:
31
"""
32
Send HTTP POST request.
33
34
Parameters:
35
- url: Target URL for the request
36
- body: Request body content
37
- headers: Optional headers as JSON string
38
39
Returns:
40
Response content as string
41
"""
42
43
@kernel_function(description="Send HTTP PUT request")
44
async def put(self, url: str, body: str = "", headers: str = "") -> str:
45
"""
46
Send HTTP PUT request.
47
48
Parameters:
49
- url: Target URL for the request
50
- body: Request body content
51
- headers: Optional headers as JSON string
52
53
Returns:
54
Response content as string
55
"""
56
57
@kernel_function(description="Send HTTP DELETE request")
58
async def delete(self, url: str, headers: str = "") -> str:
59
"""
60
Send HTTP DELETE request.
61
62
Parameters:
63
- url: Target URL for the request
64
- headers: Optional headers as JSON string
65
66
Returns:
67
Response content as string
68
"""
69
```
70
71
### Math Plugin
72
73
Mathematical operations and calculations.
74
75
```python { .api }
76
class MathPlugin:
77
"""
78
Plugin for mathematical operations.
79
"""
80
81
@kernel_function(description="Add two numbers")
82
def add(self, value1: float, value2: float) -> float:
83
"""
84
Add two numbers.
85
86
Parameters:
87
- value1: First number
88
- value2: Second number
89
90
Returns:
91
Sum of the two numbers
92
"""
93
94
@kernel_function(description="Subtract two numbers")
95
def subtract(self, value1: float, value2: float) -> float:
96
"""
97
Subtract second number from first.
98
99
Parameters:
100
- value1: First number (minuend)
101
- value2: Second number (subtrahend)
102
103
Returns:
104
Difference of the two numbers
105
"""
106
107
@kernel_function(description="Multiply two numbers")
108
def multiply(self, value1: float, value2: float) -> float:
109
"""
110
Multiply two numbers.
111
112
Parameters:
113
- value1: First number
114
- value2: Second number
115
116
Returns:
117
Product of the two numbers
118
"""
119
120
@kernel_function(description="Divide two numbers")
121
def divide(self, value1: float, value2: float) -> float:
122
"""
123
Divide first number by second.
124
125
Parameters:
126
- value1: Dividend
127
- value2: Divisor
128
129
Returns:
130
Quotient of the division
131
"""
132
133
@kernel_function(description="Calculate absolute value")
134
def abs(self, value: float) -> float:
135
"""
136
Calculate absolute value.
137
138
Parameters:
139
- value: Input number
140
141
Returns:
142
Absolute value of the input
143
"""
144
145
@kernel_function(description="Calculate ceiling of a number")
146
def ceiling(self, value: float) -> int:
147
"""
148
Calculate ceiling (round up) of a number.
149
150
Parameters:
151
- value: Input number
152
153
Returns:
154
Smallest integer greater than or equal to input
155
"""
156
157
@kernel_function(description="Calculate floor of a number")
158
def floor(self, value: float) -> int:
159
"""
160
Calculate floor (round down) of a number.
161
162
Parameters:
163
- value: Input number
164
165
Returns:
166
Largest integer less than or equal to input
167
"""
168
169
@kernel_function(description="Calculate maximum of two numbers")
170
def max(self, value1: float, value2: float) -> float:
171
"""
172
Find maximum of two numbers.
173
174
Parameters:
175
- value1: First number
176
- value2: Second number
177
178
Returns:
179
Maximum of the two numbers
180
"""
181
182
@kernel_function(description="Calculate minimum of two numbers")
183
def min(self, value1: float, value2: float) -> float:
184
"""
185
Find minimum of two numbers.
186
187
Parameters:
188
- value1: First number
189
- value2: Second number
190
191
Returns:
192
Minimum of the two numbers
193
"""
194
```
195
196
### Text Plugin
197
198
Text manipulation and processing utilities.
199
200
```python { .api }
201
class TextPlugin:
202
"""
203
Plugin for text manipulation operations.
204
"""
205
206
@kernel_function(description="Convert text to uppercase")
207
def uppercase(self, input: str) -> str:
208
"""
209
Convert text to uppercase.
210
211
Parameters:
212
- input: Input text
213
214
Returns:
215
Text converted to uppercase
216
"""
217
218
@kernel_function(description="Convert text to lowercase")
219
def lowercase(self, input: str) -> str:
220
"""
221
Convert text to lowercase.
222
223
Parameters:
224
- input: Input text
225
226
Returns:
227
Text converted to lowercase
228
"""
229
230
@kernel_function(description="Trim whitespace from text")
231
def trim(self, input: str) -> str:
232
"""
233
Remove leading and trailing whitespace.
234
235
Parameters:
236
- input: Input text
237
238
Returns:
239
Text with whitespace trimmed
240
"""
241
242
@kernel_function(description="Trim start whitespace from text")
243
def trim_start(self, input: str) -> str:
244
"""
245
Remove leading whitespace.
246
247
Parameters:
248
- input: Input text
249
250
Returns:
251
Text with leading whitespace removed
252
"""
253
254
@kernel_function(description="Trim end whitespace from text")
255
def trim_end(self, input: str) -> str:
256
"""
257
Remove trailing whitespace.
258
259
Parameters:
260
- input: Input text
261
262
Returns:
263
Text with trailing whitespace removed
264
"""
265
266
@kernel_function(description="Get text length")
267
def length(self, input: str) -> int:
268
"""
269
Get the length of text.
270
271
Parameters:
272
- input: Input text
273
274
Returns:
275
Number of characters in the text
276
"""
277
278
@kernel_function(description="Concatenate two strings")
279
def concat(self, input1: str, input2: str) -> str:
280
"""
281
Concatenate two strings.
282
283
Parameters:
284
- input1: First string
285
- input2: Second string
286
287
Returns:
288
Concatenated string
289
"""
290
```
291
292
### Time Plugin
293
294
Date and time operations.
295
296
```python { .api }
297
class TimePlugin:
298
"""
299
Plugin for date and time operations.
300
"""
301
302
@kernel_function(description="Get current date and time")
303
def now(self) -> str:
304
"""
305
Get current date and time.
306
307
Returns:
308
Current date and time as ISO string
309
"""
310
311
@kernel_function(description="Get current UTC date and time")
312
def utc_now(self) -> str:
313
"""
314
Get current UTC date and time.
315
316
Returns:
317
Current UTC date and time as ISO string
318
"""
319
320
@kernel_function(description="Get today's date")
321
def today(self) -> str:
322
"""
323
Get today's date.
324
325
Returns:
326
Today's date as string
327
"""
328
329
@kernel_function(description="Get current time")
330
def time(self) -> str:
331
"""
332
Get current time.
333
334
Returns:
335
Current time as string
336
"""
337
338
@kernel_function(description="Get current year")
339
def year(self) -> int:
340
"""
341
Get current year.
342
343
Returns:
344
Current year as integer
345
"""
346
347
@kernel_function(description="Get current month")
348
def month(self) -> int:
349
"""
350
Get current month.
351
352
Returns:
353
Current month as integer (1-12)
354
"""
355
356
@kernel_function(description="Get current day")
357
def day(self) -> int:
358
"""
359
Get current day of month.
360
361
Returns:
362
Current day as integer (1-31)
363
"""
364
365
@kernel_function(description="Get day of week")
366
def day_of_week(self) -> str:
367
"""
368
Get current day of the week.
369
370
Returns:
371
Day of week as string (e.g., "Monday")
372
"""
373
374
@kernel_function(description="Get current hour")
375
def hour(self) -> int:
376
"""
377
Get current hour.
378
379
Returns:
380
Current hour as integer (0-23)
381
"""
382
383
@kernel_function(description="Get current minute")
384
def minute(self) -> int:
385
"""
386
Get current minute.
387
388
Returns:
389
Current minute as integer (0-59)
390
"""
391
392
@kernel_function(description="Get current second")
393
def second(self) -> int:
394
"""
395
Get current second.
396
397
Returns:
398
Current second as integer (0-59)
399
"""
400
```
401
402
### Web Search Engine Plugin
403
404
Web search capabilities for retrieving information from search engines.
405
406
```python { .api }
407
class WebSearchEnginePlugin:
408
"""
409
Plugin for web search functionality.
410
"""
411
412
def __init__(self, search_engine: WebSearchEngineBase):
413
"""
414
Initialize web search plugin.
415
416
Parameters:
417
- search_engine: Web search engine implementation
418
"""
419
420
@kernel_function(description="Search the web for information")
421
async def search(self, query: str, count: int = 1, offset: int = 0) -> str:
422
"""
423
Search the web for information.
424
425
Parameters:
426
- query: Search query string
427
- count: Number of results to return (default: 1)
428
- offset: Number of results to skip (default: 0)
429
430
Returns:
431
Search results as formatted string
432
"""
433
```
434
435
### Conversation Summary Plugin
436
437
Summarization capabilities for chat histories and conversations.
438
439
```python { .api }
440
class ConversationSummaryPlugin:
441
"""
442
Plugin for conversation summarization.
443
"""
444
445
def __init__(self, kernel: Kernel):
446
"""
447
Initialize conversation summary plugin.
448
449
Parameters:
450
- kernel: Kernel instance for AI operations
451
"""
452
453
@kernel_function(description="Summarize a conversation")
454
async def summarize_conversation(
455
self,
456
input: str,
457
kernel: Kernel | None = None
458
) -> str:
459
"""
460
Summarize a conversation or chat history.
461
462
Parameters:
463
- input: Conversation text to summarize
464
- kernel: Kernel instance (uses plugin kernel if not provided)
465
466
Returns:
467
Summary of the conversation
468
"""
469
470
@kernel_function(description="Get conversation action items")
471
async def get_conversation_action_items(
472
self,
473
input: str,
474
kernel: Kernel | None = None
475
) -> str:
476
"""
477
Extract action items from a conversation.
478
479
Parameters:
480
- input: Conversation text to analyze
481
- kernel: Kernel instance (uses plugin kernel if not provided)
482
483
Returns:
484
List of action items from the conversation
485
"""
486
487
@kernel_function(description="Get conversation topics")
488
async def get_conversation_topics(
489
self,
490
input: str,
491
kernel: Kernel | None = None
492
) -> str:
493
"""
494
Extract main topics from a conversation.
495
496
Parameters:
497
- input: Conversation text to analyze
498
- kernel: Kernel instance (uses plugin kernel if not provided)
499
500
Returns:
501
List of main topics discussed
502
"""
503
```
504
505
### Text Memory Plugin
506
507
Text-based memory operations for storing and retrieving information.
508
509
```python { .api }
510
class TextMemoryPlugin:
511
"""
512
Plugin for text memory operations.
513
"""
514
515
def __init__(self, memory: SemanticTextMemory):
516
"""
517
Initialize text memory plugin.
518
519
Parameters:
520
- memory: Semantic text memory instance
521
"""
522
523
@kernel_function(description="Recall information from memory")
524
async def recall(
525
self,
526
ask: str,
527
collection: str = "generic",
528
relevance: float = 0.0,
529
limit: int = 1
530
) -> str:
531
"""
532
Recall information from memory based on a query.
533
534
Parameters:
535
- ask: Question or query for memory search
536
- collection: Memory collection to search in
537
- relevance: Minimum relevance score (0.0 to 1.0)
538
- limit: Maximum number of results to return
539
540
Returns:
541
Most relevant information from memory
542
"""
543
544
@kernel_function(description="Save information to memory")
545
async def save(
546
self,
547
text: str,
548
key: str,
549
collection: str = "generic"
550
) -> str:
551
"""
552
Save information to memory.
553
554
Parameters:
555
- text: Information to save
556
- key: Unique key for the information
557
- collection: Memory collection to save to
558
559
Returns:
560
Confirmation message
561
"""
562
```
563
564
### Sessions Python Tool
565
566
Python code execution environment for running Python code safely.
567
568
```python { .api }
569
class SessionsPythonTool:
570
"""
571
Plugin for executing Python code in isolated sessions.
572
"""
573
574
def __init__(
575
self,
576
pool_management_endpoint: str | None = None,
577
code_interpreter_user_identity: str | None = None
578
):
579
"""
580
Initialize Sessions Python Tool.
581
582
Parameters:
583
- pool_management_endpoint: Endpoint for session pool management
584
- code_interpreter_user_identity: User identity for code interpreter
585
"""
586
587
@kernel_function(description="Execute Python code")
588
async def execute_code(
589
self,
590
code: str,
591
session_id: str | None = None
592
) -> str:
593
"""
594
Execute Python code in an isolated session.
595
596
Parameters:
597
- code: Python code to execute
598
- session_id: Optional session ID for persistence
599
600
Returns:
601
Execution result including output and any errors
602
"""
603
604
@kernel_function(description="Create a new code session")
605
async def create_session(self) -> str:
606
"""
607
Create a new code execution session.
608
609
Returns:
610
Session ID for the new session
611
"""
612
613
@kernel_function(description="List available sessions")
614
async def list_sessions(self) -> str:
615
"""
616
List all available code execution sessions.
617
618
Returns:
619
List of session IDs
620
"""
621
622
@kernel_function(description="Delete a code session")
623
async def delete_session(self, session_id: str) -> str:
624
"""
625
Delete a code execution session.
626
627
Parameters:
628
- session_id: ID of the session to delete
629
630
Returns:
631
Confirmation message
632
"""
633
```
634
635
## Usage Examples
636
637
### Using Core Plugins
638
639
```python
640
from semantic_kernel import Kernel
641
from semantic_kernel.core_plugins import HttpPlugin, MathPlugin, TextPlugin, TimePlugin
642
643
# Initialize kernel
644
kernel = Kernel()
645
646
# Add core plugins
647
kernel.add_plugin(HttpPlugin(), plugin_name="http")
648
kernel.add_plugin(MathPlugin(), plugin_name="math")
649
kernel.add_plugin(TextPlugin(), plugin_name="text")
650
kernel.add_plugin(TimePlugin(), plugin_name="time")
651
652
# Use HTTP plugin
653
api_result = await kernel.invoke("http", "get", url="https://api.example.com/data")
654
print(f"API Response: {api_result.value}")
655
656
# Use math plugin
657
sum_result = await kernel.invoke("math", "add", value1=15, value2=25)
658
print(f"15 + 25 = {sum_result.value}")
659
660
# Use text plugin
661
upper_result = await kernel.invoke("text", "uppercase", input="hello world")
662
print(f"Uppercase: {upper_result.value}")
663
664
# Use time plugin
665
current_time = await kernel.invoke("time", "now")
666
print(f"Current time: {current_time.value}")
667
```
668
669
### Memory and Summarization
670
671
```python
672
from semantic_kernel.core_plugins import ConversationSummaryPlugin, TextMemoryPlugin
673
from semantic_kernel.memory import SemanticTextMemory
674
675
# Setup memory
676
memory = SemanticTextMemory(storage=vector_store, embeddings_generator=embedding_service)
677
678
# Add memory and summary plugins
679
kernel.add_plugin(TextMemoryPlugin(memory), plugin_name="memory")
680
kernel.add_plugin(ConversationSummaryPlugin(kernel), plugin_name="summary")
681
682
# Save information to memory
683
await kernel.invoke(
684
"memory",
685
"save",
686
text="Semantic Kernel supports multiple AI providers",
687
key="sk_providers",
688
collection="documentation"
689
)
690
691
# Recall information
692
result = await kernel.invoke(
693
"memory",
694
"recall",
695
ask="What AI providers does Semantic Kernel support?",
696
collection="documentation"
697
)
698
print(f"Memory result: {result.value}")
699
700
# Summarize conversation
701
conversation = "User: Tell me about AI. Assistant: AI is artificial intelligence..."
702
summary = await kernel.invoke("summary", "summarize_conversation", input=conversation)
703
print(f"Summary: {summary.value}")
704
```
705
706
### Python Code Execution
707
708
```python
709
from semantic_kernel.core_plugins import SessionsPythonTool
710
711
# Add Python execution plugin
712
python_tool = SessionsPythonTool()
713
kernel.add_plugin(python_tool, plugin_name="python")
714
715
# Execute Python code
716
code = """
717
import math
718
result = math.sqrt(16) + math.pi
719
print(f"Result: {result}")
720
"""
721
722
execution_result = await kernel.invoke("python", "execute_code", code=code)
723
print(f"Python execution result: {execution_result.value}")
724
```