semantic kernel

2025-12-11 0 272

semantic kernel

使用此企业准备的编排框架来构建智能的AI代理和多代理系统

什么是semantic kernel ?

semantic kernel是一种模型不可替代的SDK,它使开发人员能够构建,协调和部署AI代理和多代理系统。无论您是构建简单的聊天机器人还是复杂的多代理工作流程, semantic kernel可以通过企业级可靠性和灵活性提供所需的工具。

系统要求

  • Python :3.10+
  • .NET :.NET 8.0+
  • Java :JDK 17+
  • 操作系统支持:Windows,MacOS,Linux

关键功能

  • 模型灵活性:连接到任何对Openai,Azure Openai,拥抱脸,NVIDIA等的内置支持的LLM
  • 代理框架:构建具有访问工具/插件,内存和计划功能的模块化AI代理
  • 多代理系统:与合作专家协调复杂的工作流程
  • 插件生态系统:使用本机代码功能,提示模板,OpenAPI规格或模型上下文协议(MCP)扩展
  • 向量数据库支持:与Azure AI搜索,Elasticsearch,Chroma等无缝集成
  • 多模式支持:过程文本,视觉和音频输入
  • 本地部署:与Ollama,Lmstudio或ONNX一起运行
  • 流程框架:使用结构化工作流程方法建模复杂的业务流程
  • 企业准备:构建供可观察性,安全性和稳定的API

安装

首先,为您的AI服务设置环境变量:

Azure Openai:

 export AZURE_OPENAI_API_KEY=AAA....

或直接Openai:

 export OPENAI_API_KEY=sk-...

Python

pip install semantic-kernel

。网

dotnet add package Microsoft.SemanticKernel
dotnet add package Microsoft.SemanticKernel.Agents.Core

爪哇

有关说明,请参见Smantic-Kernel-Java构建。

Quickstart

基本代理-Python

创建一个响应用户提示的简单助手:

semantic kernel.")
print(response.content)

asyncio.run(main())

# Output:
# Language\’s essence,
# Semantic threads intertwine,
# Meaning\’s core revealed.\”>

 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.

基本代理 – .NET

semantic kernel."))
{
Console.WriteLine(response.Message);
}

// 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.

插件的代理-Python

使用自定义工具(插件)和结构化输出来增强您的代理:

 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 ()) 

插件的代理 – .net

 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\" ;
}

多代理系统-Python

建立一个可以协作的专业代理系统:

 import asyncio
from semantic_kernel . agents import ChatCompletionAgent , ChatHistoryAgentThread
from semantic_kernel . connectors . ai . open_ai import AzureChatCompletion , OpenAIChatCompletion

billing_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 = None

async def main () -> None :
    print ( \"Welcome to the chat bot! \\n  Type \'exit\' to exit. \\n  Try to get some billing or refund help.\" )
    while True :
        user_input = input ( \"User:> \" )

        if user_input . lower (). strip () == \"exit\" :
            print ( \" \\n \\n Exiting chat...\" )
            return False

        response = await triage_agent . get_response (
            messages = user_input ,
            thread = thread ,
        )

        if response :
            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 ())

接下来去哪里

  1. 尝试我们的入门指南或了解建筑物的代理商
  2. ?探索超过100个详细样品
  3. 了解核心semantic kernel概念

API参考

  • C#API参考
  • Python API参考

故障排除

常见问题

  • 身份验证错误:检查您的API密钥环境变量是否正确设置
  • 模型可用性:验证您的Azure OpenAI部署或OpenAI模型访问

得到帮助

  • 检查我们的GitHub问题是否已知问题
  • 搜索Discord社区以寻找解决方案
  • 在寻求帮助时包括您的SDK版本和完整错误消息

加入社区

我们欢迎您对SK社区的贡献和建议!参与的最简单方法之一是在GitHub存储库中进行讨论。欢迎错误报告和修复程序!

对于新功能,组件或扩展程序,请在发送PR之前与我们讨论问题。这是为了避免拒绝,因为我们可能会朝着不同的方向发展核心,同时也考虑对更大生态系统的影响。

了解更多并开始:

  • 阅读文档

  • 了解如何为该项目做出贡献

  • 在GitHub讨论中提出问题

  • 在不和谐社区中提出问题

  • 参加正常的办公时间和SK社区活动

  • 在我们的博客上关注团队

贡献者的名声墙

行为守则

该项目采用了Microsoft开源的行为代码。有关更多信息,请参阅《行为代码常见问题》或与OpenCode@microsoft.com联系,并提供任何其他问题或评论。

执照

版权(C)Microsoft Corporation。版权所有。

根据MIT许可获得许可。

下载源码

通过命令行克隆项目:

git clone https://github.com/microsoft/semantic-kernel.git

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

申明:本文由第三方发布,内容仅代表作者观点,与本网站无关。对本文以及其中全部或者部分内容的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。本网发布或转载文章出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,也不代表本网对其真实性负责。

左子网 编程相关 semantic kernel https://www.zuozi.net/33894.html

ArduinoJson
上一篇: ArduinoJson
常见问题
  • 1、自动:拍下后,点击(下载)链接即可下载;2、手动:拍下后,联系卖家发放即可或者联系官方找开发者发货。
查看详情
  • 1、源码默认交易周期:手动发货商品为1-3天,并且用户付款金额将会进入平台担保直到交易完成或者3-7天即可发放,如遇纠纷无限期延长收款金额直至纠纷解决或者退款!;
查看详情
  • 1、描述:源码描述(含标题)与实际源码不一致的(例:货不对板); 2、演示:有演示站时,与实际源码小于95%一致的(但描述中有”不保证完全一样、有变化的可能性”类似显著声明的除外); 3、发货:不发货可无理由退款; 4、安装:免费提供安装服务的源码但卖家不履行的; 5、收费:价格虚标,额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外); 6、其他:如质量方面的硬性常规问题BUG等。 注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。
查看详情
  • 1、左子会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全! 2、左子无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别; 3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外); 4、在没有”无任何正当退款依据”的前提下,商品写有”一旦售出,概不支持退款”等类似的声明,视为无效声明; 5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准); 6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在左子上所留的QQ、手机号沟通,以防对方不承认自我承诺。 7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于左子介入快速处理。
查看详情

相关文章

猜你喜欢
发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务