Bitzsoft.Integrations.AgentFramework 1.0.0-alpha.2

This is a prerelease version of Bitzsoft.Integrations.AgentFramework.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Bitzsoft.Integrations.AgentFramework --version 1.0.0-alpha.2
                    
NuGet\Install-Package Bitzsoft.Integrations.AgentFramework -Version 1.0.0-alpha.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bitzsoft.Integrations.AgentFramework" Version="1.0.0-alpha.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitzsoft.Integrations.AgentFramework" Version="1.0.0-alpha.2" />
                    
Directory.Packages.props
<PackageReference Include="Bitzsoft.Integrations.AgentFramework" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bitzsoft.Integrations.AgentFramework --version 1.0.0-alpha.2
                    
#r "nuget: Bitzsoft.Integrations.AgentFramework, 1.0.0-alpha.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Bitzsoft.Integrations.AgentFramework@1.0.0-alpha.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Bitzsoft.Integrations.AgentFramework&version=1.0.0-alpha.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Bitzsoft.Integrations.AgentFramework&version=1.0.0-alpha.2&prerelease
                    
Install as a Cake Tool

Bitzsoft.Integrations.AgentFramework

AI Agent 框架 -- 基于 Semantic Kernel 的智能对话代理,提供开箱即用的聊天、流式输出和多轮对话能力。

功能特性

  • 基于 Microsoft Semantic Kernel 构建,兼容 OpenAI API 端点
  • 单轮对话与流式响应(IAsyncEnumerable<string>
  • 多轮对话支持,内置 ChatHistory 管理
  • 可自定义系统提示词,内置法律助手、通用助手、文档分析等预设角色
  • 依赖注入友好,一行代码完成服务注册
  • 支持 Options 模式,可通过 appsettings.json 或代码配置

安装

dotnet add package Bitzsoft.Integrations.AgentFramework

或直接在项目文件中添加:

<PackageReference Include="Bitzsoft.Integrations.AgentFramework" Version="*" />

配置

appsettings.json 中添加以下配置节:

{
  "AgentOptions": {
    "Enabled": true,
    "Endpoint": "https://api.openai.com/v1",
    "ApiKey": "sk-your-api-key",
    "DefaultModel": "gpt-4",
    "DefaultSystemPrompt": "你是一个有帮助的 AI 助手。"
  }
}
字段 类型 默认值 说明
Enabled bool false 是否启用 Agent 服务
Endpoint string https://api.openai.com/v1 OpenAI 兼容 API 端点
ApiKey string "" API 密钥
DefaultModel string gpt-4 默认使用的模型标识
DefaultSystemPrompt string "你是一个有帮助的 AI 助手。" 默认系统提示词

注册服务

Program.cs 中注册 Agent 服务:

using Bitzsoft.Integrations.AgentFramework.Dto;
using Microsoft.Extensions.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);

// 方式一:从 appsettings.json 绑定配置
builder.Services.AddAIAgent(options =>
    builder.Configuration.GetSection("AgentOptions").Bind(options));

// 方式二:代码内直接配置
builder.Services.AddAIAgent(options =>
{
    options.Enabled = true;
    options.Endpoint = "https://api.openai.com/v1";
    options.ApiKey = "sk-your-api-key";
    options.DefaultModel = "gpt-4";
});

使用示例

单轮对话

using Bitzsoft.Integrations.AgentFramework.Const;
using Bitzsoft.Integrations.AgentFramework.Interfaces;

public class LegalConsultationService
{
    private readonly IAgentService _agent;

    public LegalConsultationService(IAgentService agent)
    {
        _agent = agent;
    }

    public async Task<string> AskLegalQuestionAsync(string question, CancellationToken ct = default)
    {
        // 使用内置法律助手提示词
        var answer = await _agent.SendMessageAsync(
            message: question,
            systemPrompt: SystemPrompts.LegalAssistant,
            cancellationToken: ct);

        return answer;
    }
}

流式响应

using System.Runtime.CompilerServices;
using Bitzsoft.Integrations.AgentFramework.Const;
using Bitzsoft.Integrations.AgentFramework.Interfaces;

public class ChatStreamingService
{
    private readonly IAgentService _agent;

    public ChatStreamingService(IAgentService agent)
    {
        _agent = agent;
    }

    public async IAsyncEnumerable<string> StreamChatAsync(
        string userMessage,
        [EnumeratorCancellation] CancellationToken ct = default)
    {
        await foreach (var chunk in _agent.SendMessageStreamAsync(
            message: userMessage,
            systemPrompt: SystemPrompts.DocumentAnalyzer,
            cancellationToken: ct))
        {
            yield return chunk;
        }
    }
}

多轮对话(带历史记录)

using Bitzsoft.Integrations.AgentFramework.Const;
using Bitzsoft.Integrations.AgentFramework.Interfaces;

public class ConversationService
{
    private readonly IAgentService _agent;

    public ConversationService(IAgentService agent)
    {
        _agent = agent;
    }

    public async Task RunMultiTurnAsync(CancellationToken ct = default)
    {
        // 创建会话历史,指定系统提示词
        var history = _agent.CreateChatHistory(SystemPrompts.GeneralAssistant);

        // 第一轮
        var reply1 = await _agent.ChatWithHistoryAsync(history, "请介绍一下劳动合同法的基本原则", ct);
        Console.WriteLine($"助手: {reply1}");

        // 第二轮 -- 历史记录自动累积,模型可以理解上下文
        var reply2 = await _agent.ChatWithHistoryAsync(history, "那试用期最长是多少个月?", ct);
        Console.WriteLine($"助手: {reply2}");
    }
}

内置系统提示词

Bitzsoft.Integrations.AgentFramework.Const.SystemPrompts 提供了以下预设角色:

常量 说明
LegalAssistant 法律助手,专注于律师事务所智能支持
GeneralAssistant 通用助手
DocumentAnalyzer 文档分析助手,擅长摘要提取和结构分析

相关包

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.AgentFramework:

Package Downloads
Bitzsoft.Integrations.All

Bitzsoft 第三方集成聚合包 — 包含全部 Integration 模块

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-alpha.7 55 6/16/2026
1.0.0-alpha.6 56 6/16/2026
1.0.0-alpha.5 50 6/14/2026
1.0.0-alpha.4 59 6/14/2026
1.0.0-alpha.3 53 6/7/2026
1.0.0-alpha.2 59 5/29/2026
1.0.0-alpha.1 58 5/28/2026