Skip to main content

O1: Semantic Kernel

Raw LLM API calls don't survive production. You need orchestration โ€” the middleware that handles prompt management, tool use, memory, error handling, and safety between your application and the model. This module covers Semantic Kernel, Microsoft's open-source SDK for AI orchestration. For the prompting and grounding techniques SK manages, see R1: Prompt Engineering and R2: RAG Architecture.

Why Raw API Calls Break in Productionโ€‹

ConcernRaw API CallWith Orchestration
Prompt versioningStrings in code, no historyVersioned templates with variables
Tool useManual JSON parsing of function callsDeclarative plugin registration
MemoryDeveloper manages conversation historyBuilt-in chat history + vector memory
Error handlingTry/catch per callRetry, fallback, circuit breaker
SafetyManual content filteringPre/post filters with content safety
ObservabilityCustom loggingBuilt-in telemetry + OpenTelemetry
Model switchingRewrite integration codeChange one config line

What Is Semantic Kernel?โ€‹

Semantic Kernel (SK) is Microsoft's open-source AI orchestration SDK. It powers M365 Copilot, GitHub Copilot, and Azure AI Foundry internally.

  • Languages: C#, Python, Java
  • License: MIT
  • Philosophy: Bring AI to your existing app (not rebuild around AI)
  • Design: Plugin-first, enterprise-grade, model-agnostic
info

SK is not a framework you build inside โ€” it's a library you add to your existing application. A typical integration is 50โ€“200 lines of code on top of your current codebase.

Core Conceptsโ€‹

The Kernelโ€‹

The central object that wires everything together โ€” services, plugins, memory, and filters:

from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion

kernel = Kernel()

kernel.add_service(AzureChatCompletion(
deployment_name="gpt-4o",
endpoint="https://my-oai.openai.azure.com/",
# Uses DefaultAzureCredential automatically
))

Plugins (Native + Prompt)โ€‹

Plugins are SK's unit of reusable AI capability. Two types:

Native plugins โ€” regular code the AI can call:

from semantic_kernel.functions import kernel_function

class WeatherPlugin:
@kernel_function(description="Get current weather for a city")
def get_weather(self, city: str) -> str:
# Call a real weather API here
return f"Weather in {city}: 22ยฐC, partly cloudy"

kernel.add_plugin(WeatherPlugin(), plugin_name="weather")

Prompt plugins โ€” templated prompts with variables:

from semantic_kernel.functions import KernelFunction
from semantic_kernel.prompt_template import PromptTemplateConfig

summarize = KernelFunction.from_prompt(
prompt="Summarize this text in {{$style}} style:\n\n{{$input}}",
plugin_name="text",
function_name="summarize",
template_format="semantic-kernel",
)
kernel.add_function(plugin=summarize)

Memoryโ€‹

SK provides pluggable memory backends for conversation history and semantic recall:

Memory TypeUse CaseBackend
Chat historyMulti-turn conversationsIn-memory, Redis, Cosmos DB
Vector memorySemantic search over past interactionsAzure AI Search, Qdrant, Chroma
Text memoryKey-value knowledge storeAny vector DB

Filtersโ€‹

Intercept and transform requests/responses at any point in the pipeline:

from semantic_kernel.filters import FunctionInvocationFilter

class SafetyFilter(FunctionInvocationFilter):
async def on_function_invocation(self, context, next):
# Pre-processing: validate input
if contains_pii(context.arguments["input"]):
raise ValueError("PII detected in input")

await next(context) # Call the actual function

# Post-processing: validate output
context.result = mask_sensitive_data(context.result)

kernel.add_filter(SafetyFilter())

:::tip Combining Frameworks SK is designed to coexist. Use SK for orchestration + LangChain for advanced chains + LlamaIndex for indexing โ€” they're complementary, not competing. FrootAI Play 01 uses SK for orchestration with Azure AI Search for retrieval. :::

The Orchestration Landscapeโ€‹

FrameworkLanguageStrengthsBest For
Semantic KernelC#, Python, JavaEnterprise-grade, plugin system, M365 integration, model-agnostic.NET shops, M365/Azure ecosystem
LangChainPython, JSLargest ecosystem, LCEL chains, LangSmith observabilityRapid prototyping, Python-first teams
LlamaIndexPythonBest-in-class data indexing, query engines, knowledge graphsData-heavy RAG, document Q&A
Prompt FlowPython (Azure)Visual flow editor, built-in evaluation, Azure-nativeAzure AI Foundry users, low-code teams
AutoGenPythonMulti-agent conversations, code execution sandboxMulti-agent systems, research
CrewAIPythonRole-based agents, task delegationTeam-of-agents patterns

Detailed Comparisonโ€‹

CapabilitySKLangChainLlamaIndexAutoGen
Plugin systemโœ… Native + Promptโœ… Toolsโœ… Toolsโœ… Tools
Memoryโœ… Pluggableโœ… Multipleโœ… Built-inโš ๏ธ Basic
Streamingโœ…โœ…โœ…โš ๏ธ Limited
Multi-agentโš ๏ธ Via Agent Frameworkโœ… LangGraphโŒโœ… Native
Evaluationโš ๏ธ Externalโœ… LangSmithโœ… Built-inโš ๏ธ External
Enterprise authโœ… Entra ID nativeโš ๏ธ Manualโš ๏ธ Manualโš ๏ธ Manual
.NET supportโœ… First-classโŒโŒโš ๏ธ Experimental
Azure integrationโœ… Deepโš ๏ธ Connectorsโš ๏ธ Connectorsโœ… Good

When to Use Whatโ€‹

Is your team .NET / Azure-first?
โ””โ”€ YES โ†’ Semantic Kernel
โ””โ”€ NO โ†’ Continue...

Is it primarily a data/RAG problem?
โ””โ”€ YES โ†’ LlamaIndex (indexing) + SK or LangChain (orchestration)
โ””โ”€ NO โ†’ Continue...

Do you need multi-agent collaboration?
โ””โ”€ YES โ†’ AutoGen or CrewAI (with SK for individual agent orchestration)
โ””โ”€ NO โ†’ Continue...

Rapid prototyping with Python?
โ””โ”€ YES โ†’ LangChain
โ””โ”€ NO โ†’ Semantic Kernel (safe default for production)

SK in FrootAI Solution Playsโ€‹

PlayHow SK Is Used
01 โ€” Enterprise RAGKernel + Azure AI Search plugin + chat history
03 โ€” Deterministic AgentFilters for input/output validation + structured output
05 โ€” IT Ticket ResolutionNative plugin for ServiceNow API + routing
07 โ€” Multi-Agent ServiceSK Agent Framework for multi-agent orchestration
14 โ€” Cost-Optimized GatewayModel routing plugin (GPT-4o-mini โ†’ GPT-4o fallback)

Key Takeawaysโ€‹

  1. Orchestration is mandatory for production โ€” raw API calls accumulate technical debt
  2. SK is the safe default for Azure/.NET teams โ€” battle-tested in M365 Copilot
  3. Plugins are the core abstraction โ€” wrap every capability as a native or prompt plugin
  4. Filters give you safety rails โ€” intercept every request and response
  5. Frameworks are complementary โ€” combine SK + LlamaIndex + AutoGen as needed

For deterministic output strategies managed through SK filters, see R3: Deterministic AI.