Tighten subagent prompt file workflow

This commit is contained in:
lpf
2026-03-06 14:12:01 +08:00
parent 49352612ea
commit 5e421bb730
15 changed files with 542 additions and 58 deletions

View File

@@ -322,6 +322,9 @@ func validateSubagents(cfg *Config) []error {
if raw.Tools.MaxParallelCalls < 0 {
errs = append(errs, fmt.Errorf("agents.subagents.%s.tools.max_parallel_calls must be >= 0", id))
}
if raw.Enabled && strings.TrimSpace(raw.SystemPromptFile) == "" {
errs = append(errs, fmt.Errorf("agents.subagents.%s.system_prompt_file is required when enabled=true", id))
}
if promptFile := strings.TrimSpace(raw.SystemPromptFile); promptFile != "" {
if filepath.IsAbs(promptFile) {
errs = append(errs, fmt.Errorf("agents.subagents.%s.system_prompt_file must be relative", id))

View File

@@ -9,16 +9,18 @@ func TestValidateSubagentsAllowsKnownPeers(t *testing.T) {
cfg.Agents.Router.Enabled = true
cfg.Agents.Router.MainAgentID = "main"
cfg.Agents.Subagents["main"] = SubagentConfig{
Enabled: true,
Type: "router",
AcceptFrom: []string{"user", "coder"},
CanTalkTo: []string{"coder"},
Enabled: true,
Type: "router",
SystemPromptFile: "agents/main/AGENT.md",
AcceptFrom: []string{"user", "coder"},
CanTalkTo: []string{"coder"},
}
cfg.Agents.Subagents["coder"] = SubagentConfig{
Enabled: true,
Type: "worker",
AcceptFrom: []string{"main"},
CanTalkTo: []string{"main"},
Enabled: true,
Type: "worker",
SystemPromptFile: "agents/coder/AGENT.md",
AcceptFrom: []string{"main"},
CanTalkTo: []string{"main"},
Runtime: SubagentRuntimeConfig{
Proxy: "proxy",
},
@@ -34,8 +36,9 @@ func TestValidateSubagentsRejectsUnknownPeer(t *testing.T) {
cfg := DefaultConfig()
cfg.Agents.Subagents["coder"] = SubagentConfig{
Enabled: true,
AcceptFrom: []string{"main"},
Enabled: true,
SystemPromptFile: "agents/coder/AGENT.md",
AcceptFrom: []string{"main"},
}
if errs := Validate(cfg); len(errs) == 0 {
@@ -59,3 +62,19 @@ func TestValidateSubagentsRejectsAbsolutePromptFile(t *testing.T) {
t.Fatalf("expected validation errors")
}
}
func TestValidateSubagentsRequiresPromptFileWhenEnabled(t *testing.T) {
t.Parallel()
cfg := DefaultConfig()
cfg.Agents.Subagents["coder"] = SubagentConfig{
Enabled: true,
Runtime: SubagentRuntimeConfig{
Proxy: "proxy",
},
}
if errs := Validate(cfg); len(errs) == 0 {
t.Fatalf("expected validation errors")
}
}