重要
Semantic Kernel は現在 Microsoft Agent Framework になりました。Microsoft Agent Framework (MAF) は Semantic Kernel のエンタープライズ対応後継製品です。Microsoft Agent Framework はバージョン 1.0 として本番環境対応のリリースとして利用可能になりました。安定した API と長期サポートへのコミットメントがあります。単一のアシスタントを構築する場合でも、専門的なエージェントのフロートを調整する場合でも、Microsoft Agent Framework 1.0 は、エンタープライズグレードのマルチエージェント調整、マルチプロバイダーモデルサポート、および A2A と MCP 経由のクロスランタイム相互運用性を提供します。
Semantic Kernel と Agent Framework について詳しくは、こちらをご覧ください: Agent Framework ブログの Semantic Kernel と Microsoft Agent Framework と、Semantic Kernel マイグレーションガイド を試してみてください。
このエンタープライズ対応の調整フレームワークで、インテリジェント AI エージェントとマルチエージェントシステムを構築します
Semantic Kernel はモデルに依存しない SDK で、開発者が AI エージェントとマルチエージェントシステムを構築、調整、デプロイできるよう支援します。シンプルなチャットボットを構築する場合でも、複雑なマルチエージェントワークフローを構築する場合でも、Semantic Kernel はエンタープライズグレードの信頼性と柔軟性を備えた必要なツールを提供します。
- Python: 3.10 以上
- .NET: .NET 10.0 以上
- Java: JDK 17 以上
- OS サポート: Windows、macOS、Linux
- モデルの柔軟性: OpenAI、Azure OpenAI、Hugging Face、NVidia などの組み込みサポートで任意の LLM に接続します
- エージェントフレームワーク: ツール/プラグイン、メモリ、計画機能にアクセスできるモジュラー AI エージェントを構築します
- マルチエージェントシステム: 協力する専門的なエージェントを使用して複雑なワークフローを調整します
- プラグインエコシステム: ネイティブコード関数、プロンプトテンプレート、OpenAPI 仕様、または Model Context Protocol (MCP) で拡張します
- ベクターDB サポート: Azure AI Search、Elasticsearch、Chroma などとシームレスに統合します
- マルチモーダルサポート: テキスト、ビジョン、オーディオ入力を処理します
- ローカルデプロイ: Ollama、LMStudio、または ONNX で実行します
- プロセスフレームワーク: 構造化されたワークフロータプローチで複雑なビジネスプロセスをモデル化します
- エンタープライズレディ: 可観測性、セキュリティ、安定した API 向けに構築されています
まず、AI サービスの環境変数を設定してください:
Azure OpenAI:
export AZURE_OPENAI_API_KEY=AAA....または OpenAI 直接:
export OPENAI_API_KEY=sk-...pip install semantic-kerneldotnet add package Microsoft.SemanticKernel
dotnet add package Microsoft.SemanticKernel.Agents.Coresemantic-kernel-java build の指示を参照してください。
ユーザープロンプトに応答する簡単なアシスタントを作成します:
import asyncio
from semantic_kernel.agents import ChatCompletionAgent
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion
async def main():
# Initialize a chat agent with basic instructions
agent = ChatCompletionAgent(
service=AzureChatCompletion(),
name="SK-Assistant",
instructions="You are a helpful assistant.",
)
# Get a response to a user message
response = await agent.get_response(messages="Write a haiku about Semantic Kernel.")
print(response.content)
asyncio.run(main())
# Output:
# Language's essence,
# Semantic threads intertwine,
# Meaning's core revealed.using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
var builder = Kernel.CreateBuilder();
builder.AddAzureOpenAIChatCompletion(
Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT"),
Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"),
Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY")
);
var kernel = builder.Build();
ChatCompletionAgent agent =
new()
{
Name = "SK-Agent",
Instructions = "You are a helpful assistant.",
Kernel = kernel,
};
await foreach (AgentResponseItem<ChatMessageContent> response
in agent.InvokeAsync("Write a haiku about Semantic Kernel."))
{
Console.WriteLine(response.Message);
}
// Output:
// Language's essence,
// Semantic threads intertwine,
// Meaning's core revealed.カスタムツール(プラグイン)と構造化された出力を使ってエージェントを強化します:
import asyncio
from typing import Annotated
from pydantic import BaseModel
from semantic_kernel.agents import ChatCompletionAgent
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatPromptExecutionSettings
from semantic_kernel.functions import kernel_function, KernelArguments
class MenuPlugin:
@kernel_function(description="Provides a list of specials from the menu.")
def get_specials(self) -> Annotated[str, "Returns the specials from the menu."]:
return """
Special Soup: Clam Chowder
Special Salad: Cobb Salad
Special Drink: Chai Tea
"""
@kernel_function(description="Provides the price of the requested menu item.")
def get_item_price(
self, menu_item: Annotated[str, "The name of the menu item."]
) -> Annotated[str, "Returns the price of the menu item."]:
return "$9.99"
class MenuItem(BaseModel):
price: float
name: str
async def main():
# Configure structured output format
settings = OpenAIChatPromptExecutionSettings()
settings.response_format = MenuItem
# Create agent with plugin and settings
agent = ChatCompletionAgent(
service=AzureChatCompletion(),
name="SK-Assistant",
instructions="You are a helpful assistant.",
plugins=[MenuPlugin()],
arguments=KernelArguments(settings)
)
response = await agent.get_response(messages="What is the price of the soup special?")
print(response.content)
# Output:
# The price of the Clam Chowder, which is the soup special, is $9.99.
asyncio.run(main()) using System.ComponentModel;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.ChatCompletion;
var builder = Kernel.CreateBuilder();
builder.AddAzureOpenAIChatCompletion(
Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT"),
Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"),
Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY")
);
var kernel = builder.Build();
kernel.Plugins.Add(KernelPluginFactory.CreateFromType<MenuPlugin>());
ChatCompletionAgent agent =
new()
{
Name = "SK-Assistant",
Instructions = "You are a helpful assistant.",
Kernel = kernel,
Arguments = new KernelArguments(new PromptExecutionSettings() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() })
};
await foreach (AgentResponseItem<ChatMessageContent> response
in agent.InvokeAsync("What is the price of the soup special?"))
{
Console.WriteLine(response.Message);
}
sealed class MenuPlugin
{
[KernelFunction, Description("Provides a list of specials from the menu.")]
public string GetSpecials() =>
"""
Special Soup: Clam Chowder
Special Salad: Cobb Salad
Special Drink: Chai Tea
""";
[KernelFunction, Description("Provides the price of the requested menu item.")]
public string GetItemPrice(
[Description("The name of the menu item.")]
string menuItem) =>
"$9.99";
}