Back to Blog
1 min read

Semantic Kernel Patterns: Building AI Applications with Microsoft's SDK

Semantic Kernel is Microsoft’s SDK for building AI applications. Let’s explore key patterns and best practices.

Semantic Kernel Fundamentals

import semantic_kernel as sk
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion

# Initialize kernel
kernel = sk.Kernel()

# Add AI service
kernel.add_service(AzureChatCompletion(
    deployment_name="gpt-4o",
    endpoint=azure_endpoint,
    api_key=api_key
))

# Create a plugin with functions
class DataAnalysisPlugin:
    @sk.kernel_function(description="Query the database")
    async def query_database(self, query: str) -> str:
        # Execute query
        return results

    @sk.kernel_function(description="Analyze data patterns")
    async def analyze_patterns(self, data: str) -> str:
        # Analysis logic
        return analysis

kernel.add_plugin(DataAnalysisPlugin(), "data")

# Use natural language to invoke
result = await kernel.invoke_prompt(
    "Query the sales database and analyze the patterns",
    plugin_name="data"
)

Semantic Kernel provides a clean abstraction for building AI applications with plugins and natural language orchestration.

Michael John Peña

Michael John Peña

Senior Data Engineer based in Sydney. Writing about data, cloud, and technology.