SubagentStart
在 Subagent 开始执行前触发。与 Stop 和 SubagentStop 不同,SubagentStart Hook 不会阻止 Subagent 执行,但可以通过模型或 Shell 脚本向 Subagent 提供建议或警告。
入参
参数格式与 SubagentStop 一致。
出参
{ "hookSpecificOutput": { "hookEventName": "SubagentStart", "additionalContext": "请遵循安全规范:禁止访问生产环境数据库" } }
|
配置方式
Prompt 方式
通过模型向 Subagent 提供建议:
- 使用
matcher 匹配 Subagent 名称
- 使用竖线
| 匹配多个名称,如 Explore|Test
- 使用
* 匹配所有 Subagent
{ "hooks": { "SubagentStart": [ { "matcher": "Explore", "hooks": [ { "type": "prompt", "prompt": "Review this subagent task: $ARGUMENTS. If the task description is vague or potentially dangerous, warn the user." } ] } ] } }
|
Command 方式
通过 Shell 脚本执行命令:
{ "hooks": { "SubagentStart": [ { "matcher": "Explore", "hooks": [ { "type": "command", "command": "node D:/Javaworks/hawa-code/hooks/SubagentStart.js" } ] } ] } }
|
示例脚本:
import * as fs from 'fs';
const input = fs.readFileSync(0, 'utf-8'); const output = { "hookSpecificOutput": { "hookEventName": "SubagentStart", "additionalContext": "请遵循安全规范:禁止访问生产环境数据库。输入参数: " + input } };
console.log(JSON.stringify(output));
|