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
<PackageReference Include="iTool.AgentKernel.AGUI" Version="4.0.0" />
<PackageVersion Include="iTool.AgentKernel.AGUI" Version="4.0.0" />
<PackageReference Include="iTool.AgentKernel.AGUI" />
paket add iTool.AgentKernel.AGUI --version 4.0.0
#r "nuget: iTool.AgentKernel.AGUI, 4.0.0"
#:package iTool.AgentKernel.AGUI@4.0.0
#addin nuget:?package=iTool.AgentKernel.AGUI&version=4.0.0
#tool nuget:?package=iTool.AgentKernel.AGUI&version=4.0.0
iTool.AgentKernel.AGUI
AG-UI 协议适配层:把 AgentKernel 的持久会话(IAgentBusinessClient)投射为标准
AG-UI SSE 事件流,使 CopilotKit 及任何
AG-UI 前端可以直接对接,替代 Workspace 自研的 AgentUI 跨端契约。
适配层只做协议翻译。会话、授权、工具准入、持久化仍全部属于 Kernel 与业务宿主。
事件源与协议
- 协议类型与序列化来自官方
AGUI.Abstractions1.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匹配;无命中返回 404unknown_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 即幂等键,因此重放安全。
红线
- 不在适配层引入新的授权/工具语义;跨端契约的复杂度只收敛在这一层。
- 协议随
AGUI.Abstractions版本走;升级时事件映射表由测试锁死 (见tests/iTool.AgentKernel.AGUI.Tests)。
| Product | Versions 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. |
-
net10.0
- AGUI.Abstractions (>= 1.0.0)
- AGUI.Formatting (>= 1.0.0)
- iTool.AgentKernel.Orleans (>= 4.0.0)
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 |