agentscope-ai / agentscope-ai/agentscope-java

[Bug]:声明的子 Agent 不会继承父 Agent hooks

未关闭
#1,578 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
area/harness bug
主要语言
Java
星标
5.6k
派生
1.3k
平均合并
4 天 12 小时
30 天内合并 PR
77

描述

## 问题
当前 AgentScope Harness 中,`general-purpose` 子 Agent 会继承父 Agent 的 hooks,但通过 `workspace/subagents/*.md` 声明的子 Agent 不会继承父 Agent hooks。
这会导致父 Agent 上配置的工具治理、HITL 人工确认、审计、预算等 hook 只对父 Agent 生效,对声明式子 Agent 不生效。

## 例子

父 Agent 配置了工具确认 hook:

```java
HarnessAgent.builder()
.hook(new ToolGovernanceHook())
.toolkit(toolkit)
.workspace(workspace)
.build();

子 Agent 声明了受控工具:

---
description: API 排错专家
tools: [query_logs]
---

预期:query_logs 在子 Agent 中调用时,也会触发父 Agent 的 ToolGovernanceHook。

实际:声明式子 Agent 没继承 hook,query_logs 可能直接执行。

## 期望

声明式子 Agent 应该像 general-purpose 子 Agent 一样继承父 Agent hooks,同时继续保留 tools allowlist。

也就是:

- 父 Agent hooks 继续作为全局治理能力
- 子 Agent 仍然只能使用自己声明的工具
- 工具调用、HITL、审计、预算等逻辑在父 Agent 和子 Agent 中行为一致

## 可能的修复方向

在构建声明式子 Agent 时,把父 Agent hooks 传入子 Agent builder:

.hooks(List.copyOf(parentHooks))

另外,子 Agent 执行时的 RuntimeContext 也最好继承父上下文中的必要字段,否则 hook 即使继承了,也可能拿不到租户、权限、runId 等信息。

## 影响

这应该是更安全的默认行为。否则用户以为 hook 是全局治理,但声明式子 Agent 实际绕过了它。

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。