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

@@ -49,11 +49,18 @@ func UpsertConfigSubagent(configPath string, args map[string]interface{}) (map[s
if err != nil {
return nil, err
}
mainID := strings.TrimSpace(cfg.Agents.Router.MainAgentID)
if mainID == "" {
mainID = "main"
}
if cfg.Agents.Subagents == nil {
cfg.Agents.Subagents = map[string]config.SubagentConfig{}
}
subcfg := cfg.Agents.Subagents[agentID]
if enabled, ok := boolArgFromMap(args, "enabled"); ok {
if agentID == mainID && !enabled {
return nil, fmt.Errorf("main agent %q cannot be disabled", agentID)
}
subcfg.Enabled = enabled
} else if !subcfg.Enabled {
subcfg.Enabled = true
@@ -84,6 +91,9 @@ func UpsertConfigSubagent(configPath string, args map[string]interface{}) (map[s
} else if strings.TrimSpace(subcfg.Type) == "" {
subcfg.Type = "worker"
}
if subcfg.Enabled && strings.TrimSpace(subcfg.SystemPromptFile) == "" {
return nil, fmt.Errorf("system_prompt_file is required for enabled agent %q", agentID)
}
cfg.Agents.Subagents[agentID] = subcfg
if kws := stringListArgFromMap(args, "routing_keywords"); len(kws) > 0 {
cfg.Agents.Router.Rules = upsertRouteRuleConfig(cfg.Agents.Router.Rules, config.AgentRouteRule{
@@ -123,6 +133,13 @@ func DeleteConfigSubagent(configPath, agentID string) (map[string]interface{}, e
if err != nil {
return nil, err
}
mainID := strings.TrimSpace(cfg.Agents.Router.MainAgentID)
if mainID == "" {
mainID = "main"
}
if agentID == mainID {
return nil, fmt.Errorf("main agent %q cannot be deleted", agentID)
}
if cfg.Agents.Subagents == nil {
return map[string]interface{}{"ok": false, "found": false, "agent_id": agentID}, nil
}

View File

@@ -38,9 +38,10 @@ func TestSubagentConfigToolUpsert(t *testing.T) {
cfg := config.DefaultConfig()
cfg.Agents.Router.Enabled = true
cfg.Agents.Subagents["main"] = config.SubagentConfig{
Enabled: true,
Type: "router",
Role: "orchestrator",
Enabled: true,
Type: "router",
Role: "orchestrator",
SystemPromptFile: "agents/main/AGENT.md",
}
if err := config.SaveConfig(configPath, cfg); err != nil {
t.Fatalf("save config failed: %v", err)
@@ -50,14 +51,15 @@ func TestSubagentConfigToolUpsert(t *testing.T) {
tool := NewSubagentConfigTool(configPath)
out, err := tool.Execute(context.Background(), map[string]interface{}{
"action": "upsert",
"agent_id": "reviewer",
"role": "testing",
"display_name": "Review Agent",
"description": "负责回归与评审",
"system_prompt": "review changes",
"routing_keywords": []interface{}{"review", "regression"},
"tool_allowlist": []interface{}{"shell", "sessions"},
"action": "upsert",
"agent_id": "reviewer",
"role": "testing",
"display_name": "Review Agent",
"description": "负责回归与评审",
"system_prompt": "review changes",
"system_prompt_file": "agents/reviewer/AGENT.md",
"routing_keywords": []interface{}{"review", "regression"},
"tool_allowlist": []interface{}{"shell", "sessions"},
})
if err != nil {
t.Fatalf("upsert failed: %v", err)

View File

@@ -171,8 +171,9 @@ func TestSubagentProfileStoreRejectsWritesForConfigManagedProfiles(t *testing.T)
cfg := config.DefaultConfig()
cfg.Agents.Subagents["tester"] = config.SubagentConfig{
Enabled: true,
Role: "test",
Enabled: true,
Role: "test",
SystemPromptFile: "agents/tester/AGENT.md",
}
runtimecfg.Set(cfg)