Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Integrate cutting-edge LLM technology quickly and easily into your apps

License

NotificationsYou must be signed in to change notification settings

microsoft/semantic-kernel

Repository files navigation

Build intelligent AI agents and multi-agent systems with this enterprise-ready orchestration framework

License: MITPython packageNuget packageDiscord

What is Semantic Kernel?

Semantic Kernel is a model-agnostic SDK that empowers developers to build, orchestrate, and deploy AI agents and multi-agent systems. Whether you're building a simple chatbot or a complex multi-agent workflow, Semantic Kernel provides the tools you need with enterprise-grade reliability and flexibility.

System Requirements

  • Python: 3.10+
  • .NET: .NET 8.0+
  • Java: JDK 17+
  • OS Support: Windows, macOS, Linux

Key Features

  • Model Flexibility: Connect to any LLM with built-in support forOpenAI,Azure OpenAI,Hugging Face,NVidia and more
  • Agent Framework: Build modular AI agents with access to tools/plugins, memory, and planning capabilities
  • Multi-Agent Systems: Orchestrate complex workflows with collaborating specialist agents
  • Plugin Ecosystem: Extend with native code functions, prompt templates, OpenAPI specs, or Model Context Protocol (MCP)
  • Vector DB Support: Seamless integration withAzure AI Search,Elasticsearch,Chroma, and more
  • Multimodal Support: Process text, vision, and audio inputs
  • Local Deployment: Run withOllama,LMStudio, orONNX
  • Process Framework: Model complex business processes with a structured workflow approach
  • Enterprise Ready: Built for observability, security, and stable APIs

Installation

First, set the environment variable for your AI Services:

Azure OpenAI:

export AZURE_OPENAI_API_KEY=AAA....

or OpenAI directly:

export OPENAI_API_KEY=sk-...

Python

pip install semantic-kernel

.NET

dotnet add package Microsoft.SemanticKerneldotnet add package Microsoft.SemanticKernel.Agents.core

Java

Seesemantic-kernel-java build for instructions.

Quickstart

Basic Agent - Python

Create a simple assistant that responds to user prompts:

importasynciofromsemantic_kernel.agentsimportChatCompletionAgentfromsemantic_kernel.connectors.ai.open_aiimportAzureChatCompletionasyncdefmain():# Initialize a chat agent with basic instructionsagent=ChatCompletionAgent(service=AzureChatCompletion(),name="SK-Assistant",instructions="You are a helpful assistant.",    )# Get a response to a user messageresponse=awaitagent.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.

Basic Agent - .NET

usingMicrosoft.SemanticKernel;usingMicrosoft.SemanticKernel.Agents;varbuilder=Kernel.CreateBuilder();builder.AddAzureOpenAIChatCompletion(Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT"),Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"),Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY"));varkernel=builder.Build();ChatCompletionAgentagent=new(){Name="SK-Agent",Instructions="You are a helpful assistant.",Kernel=kernel,};awaitforeach(AgentResponseItem<ChatMessageContent>responseinagent.InvokeAsync("Write a haiku about Semantic Kernel.")){Console.WriteLine(response.Message);}// Output:// Language's essence,// Semantic threads intertwine,// Meaning's core revealed.

Agent with Plugins - Python

Enhance your agent with custom tools (plugins) and structured output:

importasynciofromtypingimportAnnotatedfrompydanticimportBaseModelfromsemantic_kernel.agentsimportChatCompletionAgentfromsemantic_kernel.connectors.ai.open_aiimportAzureChatCompletion,OpenAIChatPromptExecutionSettingsfromsemantic_kernel.functionsimportkernel_function,KernelArgumentsclassMenuPlugin:@kernel_function(description="Provides a list of specials from the menu.")defget_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.")defget_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"classMenuItem(BaseModel):price:floatname:strasyncdefmain():# Configure structured output formatsettings=OpenAIChatPromptExecutionSettings()settings.response_format=MenuItem# Create agent with plugin and settingsagent=ChatCompletionAgent(service=AzureChatCompletion(),name="SK-Assistant",instructions="You are a helpful assistant.",plugins=[MenuPlugin()],arguments=KernelArguments(settings)    )response=awaitagent.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())

Agent with Plugin - .NET

usingSystem.ComponentModel;usingMicrosoft.SemanticKernel;usingMicrosoft.SemanticKernel.Agents;usingMicrosoft.SemanticKernel.ChatCompletion;varbuilder=Kernel.CreateBuilder();builder.AddAzureOpenAIChatCompletion(Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT"),Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"),Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY"));varkernel=builder.Build();kernel.Plugins.Add(KernelPluginFactory.CreateFromType<MenuPlugin>());ChatCompletionAgentagent=new(){Name="SK-Assistant",Instructions="You are a helpful assistant.",Kernel=kernel,Arguments=newKernelArguments(newPromptExecutionSettings(){FunctionChoiceBehavior=FunctionChoiceBehavior.Auto()})};awaitforeach(AgentResponseItem<ChatMessageContent>responseinagent.InvokeAsync("What is the price of the soup special?")){Console.WriteLine(response.Message);}sealedclassMenuPlugin{[KernelFunction,Description("Provides a list of specials from the menu.")]publicstringGetSpecials()=>"""        Special Soup: Clam Chowder        Special Salad: Cobb Salad        Special Drink: Chai Tea        """;[KernelFunction,Description("Provides the price of the requested menu item.")]publicstringGetItemPrice([Description("The name of the menu item.")]stringmenuItem)=>"$9.99";}

Multi-Agent System - Python

Build a system of specialized agents that can collaborate:

importasynciofromsemantic_kernel.agentsimportChatCompletionAgent,ChatHistoryAgentThreadfromsemantic_kernel.connectors.ai.open_aiimportAzureChatCompletion,OpenAIChatCompletionbilling_agent=ChatCompletionAgent(service=AzureChatCompletion(),name="BillingAgent",instructions="You handle billing issues like charges, payment methods, cycles, fees, discrepancies, and payment failures.")refund_agent=ChatCompletionAgent(service=AzureChatCompletion(),name="RefundAgent",instructions="Assist users with refund inquiries, including eligibility, policies, processing, and status updates.",)triage_agent=ChatCompletionAgent(service=OpenAIChatCompletion(),name="TriageAgent",instructions="Evaluate user requests and forward them to BillingAgent or RefundAgent for targeted assistance."" Provide the full answer to the user containing any information from the agents",plugins=[billing_agent,refund_agent],)thread:ChatHistoryAgentThread=Noneasyncdefmain()->None:print("Welcome to the chat bot!\n  Type 'exit' to exit.\n  Try to get some billing or refund help.")whileTrue:user_input=input("User:> ")ifuser_input.lower().strip()=="exit":print("\n\nExiting chat...")returnFalseresponse=awaittriage_agent.get_response(messages=user_input,thread=thread,        )ifresponse:print(f"Agent :>{response}")# Agent :> I understand that you were charged twice for your subscription last month, and I'm here to assist you with resolving this issue. Here’s what we need to do next:# 1. **Billing Inquiry**:#    - Please provide the email address or account number associated with your subscription, the date(s) of the charges, and the amount charged. This will allow the billing team to investigate the discrepancy in the charges.# 2. **Refund Process**:#    - For the refund, please confirm your subscription type and the email address associated with your account.#    - Provide the dates and transaction IDs for the charges you believe were duplicated.# Once we have these details, we will be able to:# - Check your billing history for any discrepancies.# - Confirm any duplicate charges.# - Initiate a refund for the duplicate payment if it qualifies. The refund process usually takes 5-10 business days after approval.# Please provide the necessary details so we can proceed with resolving this issue for you.if__name__=="__main__":asyncio.run(main())

Where to Go Next

  1. 📖 Try ourGetting Started Guide or learn aboutBuilding Agents
  2. 🔌 Explore over 100Detailed Samples
  3. 💡 Learn about core Semantic KernelConcepts

API References

Troubleshooting

Common Issues

  • Authentication Errors: Check that your API key environment variables are correctly set
  • Model Availability: Verify your Azure OpenAI deployment or OpenAI model access

Getting Help

  • Check ourGitHub issues for known problems
  • Search theDiscord community for solutions
  • Include your SDK version and full error messages when asking for help

Join the community

We welcome your contributions and suggestions to the SK community! One of the easiest ways to participate is to engage in discussions in the GitHub repository. Bug reports and fixes are welcome!

For new features, components, or extensions, please open an issue and discuss with us before sending a PR. This is to avoid rejection as we might be taking the core in a different direction, but also to consider the impact on the larger ecosystem.

To learn more and get started:

Contributor Wall of Fame

semantic-kernel contributors

Code of Conduct

This project has adopted theMicrosoft Open Source Code of Conduct.For more information, see theCode of Conduct FAQor contactopencode@microsoft.comwith any additional questions or comments.

License

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under theMIT license.


[8]ページ先頭

©2009-2025 Movatter.jp