Remove heuristic subagent config shortcut

This commit is contained in:
lpf
2026-03-13 16:06:30 +08:00
parent 029676b375
commit 60eee65fec
5 changed files with 1 additions and 311 deletions

View File

@@ -1201,25 +1201,6 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage)
} else {
specTaskRef = normalizeSpecCodingTaskRef(taskRef)
}
if configAction, handled, configErr := al.maybeHandleSubagentConfigIntent(ctx, msg); handled {
if configErr != nil && specTaskRef.Summary != "" {
if err := al.maybeReopenSpecCodingTask(specTaskRef, msg.Content, configErr.Error()); err != nil {
logger.WarnCF("agent", logger.C0172, map[string]interface{}{
"session_key": msg.SessionKey,
"error": err.Error(),
})
}
}
if configErr == nil && specTaskRef.Summary != "" {
if err := al.maybeCompleteSpecCodingTask(specTaskRef, configAction); err != nil {
logger.WarnCF("agent", logger.C0172, map[string]interface{}{
"session_key": msg.SessionKey,
"error": err.Error(),
})
}
}
return configAction, configErr
}
if routed, ok, routeErr := al.maybeAutoRoute(ctx, msg); ok {
if routeErr != nil && specTaskRef.Summary != "" {
if err := al.maybeReopenSpecCodingTask(specTaskRef, msg.Content, routeErr.Error()); err != nil {

View File

@@ -1,106 +0,0 @@
package agent
import (
"context"
"fmt"
"path/filepath"
"strings"
"github.com/YspCoder/clawgo/pkg/bus"
"github.com/YspCoder/clawgo/pkg/tools"
)
func (al *AgentLoop) maybeHandleSubagentConfigIntent(ctx context.Context, msg bus.InboundMessage) (string, bool, error) {
_ = ctx
if al == nil {
return "", false, nil
}
if msg.Channel == "system" || msg.Channel == "internal" {
return "", false, nil
}
content := strings.TrimSpace(msg.Content)
if content == "" {
return "", false, nil
}
if !looksLikeSubagentCreateRequest(content) {
return "", false, nil
}
description := extractSubagentDescription(content)
if description == "" {
return "", false, nil
}
draft := tools.DraftConfigSubagent(description, "")
result, err := tools.UpsertConfigSubagent(al.configPath, draft)
if err != nil {
return "", true, fmt.Errorf("persist subagent config to %s failed: %w", al.displayConfigPath(), err)
}
return formatCreatedSubagentForUser(result, al.displayConfigPath()), true, nil
}
func looksLikeSubagentCreateRequest(content string) bool {
lower := strings.ToLower(strings.TrimSpace(content))
if lower == "" {
return false
}
createMarkers := []string{
"创建", "新建", "增加", "添加", "配置一个", "生成一个",
"create", "add", "new",
}
subagentMarkers := []string{
"subagent", "sub-agent", "agent", "子代理", "子 agent", "工作代理",
}
hasCreate := false
for _, item := range createMarkers {
if strings.Contains(lower, item) {
hasCreate = true
break
}
}
if !hasCreate {
return false
}
for _, item := range subagentMarkers {
if strings.Contains(lower, item) {
return true
}
}
return false
}
func extractSubagentDescription(content string) string {
content = strings.TrimSpace(content)
replacers := []string{
"请", "帮我", "给我", "创建", "新建", "增加", "添加", "配置", "生成",
"a ", "an ", "new ", "create ", "add ",
}
out := content
for _, item := range replacers {
out = strings.ReplaceAll(out, item, "")
}
out = strings.ReplaceAll(out, "子代理", "")
out = strings.ReplaceAll(out, "subagent", "")
out = strings.ReplaceAll(out, "sub-agent", "")
out = strings.TrimSpace(out)
if out == "" {
return strings.TrimSpace(content)
}
return out
}
func formatCreatedSubagentForUser(result map[string]interface{}, configPath string) string {
return fmt.Sprintf(
"subagent 已写入 config.json。\npath: %s\nagent_id: %v",
configPath,
result["agent_id"],
)
}
func (al *AgentLoop) displayConfigPath() string {
if al == nil || strings.TrimSpace(al.configPath) == "" {
return "config path not configured"
}
if abs, err := filepath.Abs(al.configPath); err == nil {
return abs
}
return strings.TrimSpace(al.configPath)
}

View File

@@ -1,50 +0,0 @@
package agent
import (
"strings"
"testing"
)
func TestFormatCreatedSubagentForUserReadsNestedFields(t *testing.T) {
t.Parallel()
out := formatCreatedSubagentForUser(map[string]interface{}{
"agent_id": "coder",
"subagent": map[string]interface{}{
"role": "coding",
"display_name": "Code Agent",
"system_prompt_file": "agents/coder/AGENT.md",
"tools": map[string]interface{}{
"allowlist": []interface{}{"filesystem", "shell"},
},
},
"rules": []interface{}{
map[string]interface{}{
"agent_id": "coder",
"keywords": []interface{}{"code", "fix"},
},
},
}, "/tmp/config.json")
for _, want := range []string{
"subagent 已写入 config.json。",
"path: /tmp/config.json",
"agent_id: coder",
} {
if !strings.Contains(out, want) {
t.Fatalf("expected output to contain %q, got:\n%s", want, out)
}
}
for _, unwanted := range []string{
"role:",
"display_name:",
"tool_allowlist:",
"routing_keywords:",
"system_prompt_file:",
"<nil>",
} {
if strings.Contains(out, unwanted) {
t.Fatalf("did not expect %q in output, got:\n%s", unwanted, out)
}
}
}