Skip to content

[Bug]:AG-UI 协议缺少 metadata 支持,导致无法完成权限确认流程 #1726

Closed

Description

@Jisprincess

当使用 AgentScope 的权限确认功能(HITL - Human-in-the-Loop)时,前端无法通过 AG-UI 协议传递用户确认结果,导致后端抛出错误:

Agent is waiting for ConfirmResult(s) on ASKING tool calls but the incoming call did not supply any.
Attach a List under Msg metadata key agentscope_confirm_results
根本原因:AguiMessage 类缺少 metadata 字段,导致前端无法将 ConfirmResult 传递到后端。

重现步骤
使用 PermissionHITLExample 或任何配置了 PermissionBehavior.ASK 规则的 Agent
前端通过 AG-UI 协议发送触发工具调用的消息
后端返回需要用户确认的请求
前端尝试发送确认结果,但无法传递 ConfirmResult
当前前端请求格式(无效)
{
"threadId": "xxx",
"runId": "xxx",
"messages": [
{
"id": "msg-id",
"role": "user",
"content": "确认删除"
// ❌ 无法传递 ConfirmResult
}
]
}
后端期望的格式(当前 AG-UI 协议不支持)
AgentScope 核心框架期望在 Msg 的 metadata 中接收 ConfirmResult 列表:

// 后端期望的数据结构
Msg metadata: {
"agentscope_confirm_results": [
{
"confirmed": true,
"toolCall": {
"id": "call_xxx",
"name": "dangerous_delete",
"input": {...}
}
}
]
}
期望行为
前端应该能够通过 AG-UI 协议传递 ConfirmResult,协议应该支持以下格式:

{
"threadId": "xxx",
"runId": "xxx",
"messages": [
{
"id": "msg-id",
"role": "user",
"content": "确认删除",
"metadata": {
"agentscope_confirm_results": [
{
"confirmed": true,
"toolCall": {
"id": "call_xxx",
"name": "dangerous_delete",
"input": {"path": "/tmp/file.txt"}
}
}
]
}
}
]
}
实际行为
前端发送消息后,后端抛出错误
Agent 无法继续执行
整个 HITL 流程中断
环境信息
AgentScope Java 版本:agentscope-java (最新)
模块:agentscope-extensions-agui
涉及文件:
AguiMessage.java
AguiMessageConverter.java
AguiAgentAdapter.java
影响范围
所有使用 AG-UI 协议且需要权限确认功能的场景都无法正常工作,包括但不限于:

文件删除操作确认
敏感系统命令确认
数据修改操作确认
任何配置了 PermissionBehavior.ASK 的工具
建议的解决方案
方案 1:扩展 AguiMessage 添加 metadata 字段(推荐)
修改文件:AguiMessage.java

public class AguiMessage {
private final String id;
private final String role;
private final String content;
private final List toolCalls;
private final String toolCallId;
private final Map<String, Object> metadata; // 新增字段

@JsonCreator
public AguiMessage(
        @JsonProperty("id") String id,
        @JsonProperty("role") String role,
        @JsonProperty("content") String content,
        @JsonProperty("toolCalls") List<AguiToolCall> toolCalls,
        @JsonProperty("toolCallId") String toolCallId,
        @JsonProperty("metadata") Map<String, Object> metadata) {  // 新增参数
    // ... 现有代码
    this.metadata = metadata != null 
        ? Collections.unmodifiableMap(new HashMap<>(metadata)) 
        : Collections.emptyMap();
}

public Map<String, Object> getMetadata() {
    return metadata;
}

}
修改文件:AguiMessageConverter.java

public Msg toMsg(AguiMessage aguiMessage) {
MsgRole role = convertRole(aguiMessage.getRole());
List blocks = new ArrayList<>();

// ... 现有的 content 和 toolCalls 处理逻辑 ...

Msg.Builder builder = Msg.builder()
        .id(aguiMessage.getId())
        .role(role)
        .content(blocks);

// 新增:传递 metadata 到 Msg
if (aguiMessage.getMetadata() != null && !aguiMessage.getMetadata().isEmpty()) {
    builder.metadata(aguiMessage.getMetadata());
}

return builder.build();

}
方案 2:通过 forwardedProps 传递(备选)
如果不想修改 AguiMessage,可以在 RunAgentInput.forwardedProps 中传递,然后在 AguiAgentAdapter 中提取并注入到 Msg 的 metadata 中。

但这个方案不够优雅,因为 ConfirmResult 是消息级别的数据,不应该放在请求级别的 forwardedProps 中。

额外信息
相关代码位置
AgentScope 核心框架对 ConfirmResult 的期望:

文件:agentscope-core/src/main/java/io/agentscope/core/message/Msg.java
常量:METADATA_CONFIRM_RESULTS = "agentscope_confirm_results"
ConfirmResult 数据结构:

文件:agentscope-core/src/main/java/io/agentscope/core/event/ConfirmResult.java
字段:
confirmed: boolean
toolCall: ToolUseBlock
rules: List (可选)
当前 AG-UI 协议定义:

文件:agentscope-extensions-agui/src/main/java/io/agentscope/core/agui/model/AguiMessage.java
缺少:metadata 字段

Activity

  1. added
    bug
    on Jun 12, 2026
  2. added
    area/ext/integration
    on Jun 13, 2026
  3. Blue-Berrys commented on Jul 28, 2026

    @Blue-Berrys
    Contributor

    I'd like to work on this. Plan: add optional metadata to AguiMessage, map it through AguiMessageConverter to/from Msg.metadata, and add unit tests so ConfirmResult can be delivered over AG-UI.

  4. moved this from Backlog to In progress in AgentScope Javaon Jul 28, 2026
  5. added a commit that references this issue on Jul 28, 2026
    bc4a46e
  6. moved this from In progress to Done in AgentScope Javaon Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/ext/integrationbug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions