Skip to content

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

Description

@zhanghuadi

问题

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

例子

父 Agent 配置了工具确认 hook:

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 实际绕过了它。

Activity

  1. added
    bug
    on Jun 3, 2026
  2. added
    area/harness
    on Jun 4, 2026
  3. moved this from Backlog to In progress in AgentScope Javaon Sep 5, 2026
  4. added a commit that references this issue on Nov 25, 2026
    a716f68
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/harnessbug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions