iTool.AgentKernel.AGUI 4.0.0

dotnet add package iTool.AgentKernel.AGUI --version 4.0.0
                    
NuGet\Install-Package iTool.AgentKernel.AGUI -Version 4.0.0
                    
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="iTool.AgentKernel.AGUI" Version="4.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="iTool.AgentKernel.AGUI" Version="4.0.0" />
                    
Directory.Packages.props
<PackageReference Include="iTool.AgentKernel.AGUI" />
                    
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 iTool.AgentKernel.AGUI --version 4.0.0
                    
#r "nuget: iTool.AgentKernel.AGUI, 4.0.0"
                    
#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 iTool.AgentKernel.AGUI@4.0.0
                    
#: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=iTool.AgentKernel.AGUI&version=4.0.0
                    
Install as a Cake Addin
#tool nuget:?package=iTool.AgentKernel.AGUI&version=4.0.0
                    
Install as a Cake Tool

iTool.AgentKernel.AGUI

AG-UI 协议适配层:把 AgentKernel 的持久会话(IAgentBusinessClient)投射为标准 AG-UI SSE 事件流,使 CopilotKit 及任何 AG-UI 前端可以直接对接,替代 Workspace 自研的 AgentUI 跨端契约。

适配层只做协议翻译。会话、授权、工具准入、持久化仍全部属于 Kernel 与业务宿主。

事件源与协议

  • 协议类型与序列化来自官方 AGUI.Abstractions 1.0.0(不从 0 发明协议)。
  • 事件源是 durable 事件账本:每个 AG-UI 事件携带 Kernel journal 的 sequence, 断线可用 Last-Event-ID 头重连续传(标准 AG-UI 前端不具备该能力,此处为附加收益)。
  • 前端重试发送同一 message.id 的用户消息时,由 Kernel 的 AgentInputReceipt 输入幂等去重,不会产生重复 run。

事件映射

AgentKernel(业务投影 kind) AG-UI 事件
text_delta TEXT_MESSAGE_START → TEXT_MESSAGE_CONTENT → TEXT_MESSAGE_END
tool_call / tool_execution_started TOOL_CALL_START + TOOL_CALL_ARGS + TOOL_CALL_END
tool_result / tool_execution_completed TOOL_CALL_RESULT
user_input_requested ask_user 投射为前端工具调用三元组 + CUSTOM agentkernel.waiting_for_input,run 以 RUN_FINISHED(outcome=interrupt) 收束
completed RUN_FINISHED(outcome=success)
canceled RUN_ERROR(code=canceled)
其余(state_changed/usage/compaction/recovering/balance_required/agent_*…) CUSTOM(name=agentkernel.<kind>)

运行编排

  • 首次出现且 Kernel 中无注册 → CreateAsync 后 RunMessageStreamingAsync; 已存在的 thread → FollowUpStreamingAsync(受会话的 FollowUpMode 约束)。
  • RunAgentInput.resume(AG-UI interrupt 恢复)→ 有 pending 交互时经 AnswerQuestionAsync 绑定原 interaction id 提交,再从 LastSequence 续流; 无交互的中断(余额等待等)直接续流重入。
  • Last-Event-ID 头 → 仅 WatchAsync(afterSequence),不重复发起业务 run。

扩展点(客户端预留接口)

接口 默认实现 用途
IAGUISessionResolver threadId = sessionId,静态 ConfigurationReference 租户/配置映射,forwardedProps → AgentExecutionContext
IAGUIEventCustomizer 原样透传 过滤/替换/追加事件(业务投影 → CUSTOM)
IAGUIFrontendToolPolicy Ignore(前端声明工具不进 Kernel) 预留:将来把前端工具注册为交互式客户端工具
IAGUICapabilitiesProvider 不发事件 能力发现:在 RUN_STARTED 后发 CUSTOM agentkernel.capabilities(团队/工具/命令/模型)
IAGUICommandHandler 无 宿主控制命令(如 switch-model);原生命令只有 cancel

前端声明的工具(RunAgentInput.tools)当前一律不进入 Kernel:Kernel 工具由宿主 预授权(见生产验收 AK-M3/AK-M5)。Admit 语义为预留扩展位。

接入

builder.Services.AddAgentKernelOrleans(...);      // 已有
builder.Services.AddAgentKernelAGUI(o => o.DefaultConfigurationReference = "workspace-default");

app.MapAgentKernelAGUI("/agui")
   .RequireAuthorization();                        // 认证归属宿主,适配层不设身份
app.MapAgentKernelAGUICommand("/agui/command");     // cancel 原生;其余路由到 IAGUICommandHandler

控制命令(POST /agui/command)

{threadId, command, payload}:

  • cancel:原生映射 CancelAsync;Kernel 稳定异常翻译为 {status:"rejected", reason:稳定码}。 会话配置按 Kernel 契约冻结(配置身份哈希),switch-model 只对新建会话生效。
  • 其余命令按 IAGUICommandHandler.Commands 匹配;无命中返回 404 unknown_command。

跨 run 命令(forwardedProps)

  • {"command":"edit-last","targetMessageId":"..."} → EditLastMessageStreamingAsync, 取最后一条 user 消息为修订文本。
  • {"model":"..."} → 透传给 IAGUISessionResolver,会话创建时绑定模型。

断线重连

SSE 帧携带 Kernel journal 序列;断线后带 Last-Event-ID: <sequence> 重发即从该游标 回放/续播,不重复发起业务 run。run 边界按事件 kind 判定 (completed/canceled/failed/user_input_requested/balance_required)——重放事件上的 status 是实时值,不作为边界依据。

CopilotKit 前端

import { CopilotKit } from "@copilotkit/react-core";

<CopilotKit runtimeUrl="https://host/agui">
  {/* CopilotChat / useCoAgent ... */}
</CopilotKit>

注意:CopilotKit 前端重试会重发全量 messages;适配层只取最后一条 user 消息, 历史以 Kernel/DASP 为准,消息 id 即幂等键,因此重放安全。

红线

  1. 不在适配层引入新的授权/工具语义;跨端契约的复杂度只收敛在这一层。
  2. 协议随 AGUI.Abstractions 版本走;升级时事件映射表由测试锁死 (见 tests/iTool.AgentKernel.AGUI.Tests)。
Product Compatible and additional computed target framework versions.
.NET 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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.0 52 10/14/2026