mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-28 04:57:29 +08:00
fix
This commit is contained in:
@@ -19,14 +19,12 @@ type SessionInfo struct {
|
||||
}
|
||||
|
||||
type SessionsTool struct {
|
||||
listFn func(limit int) []SessionInfo
|
||||
historyFn func(key string, limit int) []providers.Message
|
||||
noSessionsText string
|
||||
unsupportedAction string
|
||||
listFn func(limit int) []SessionInfo
|
||||
historyFn func(key string, limit int) []providers.Message
|
||||
}
|
||||
|
||||
func NewSessionsTool(listFn func(limit int) []SessionInfo, historyFn func(key string, limit int) []providers.Message, noSessionsText, unsupportedAction string) *SessionsTool {
|
||||
return &SessionsTool{listFn: listFn, historyFn: historyFn, noSessionsText: noSessionsText, unsupportedAction: unsupportedAction}
|
||||
func NewSessionsTool(listFn func(limit int) []SessionInfo, historyFn func(key string, limit int) []providers.Message) *SessionsTool {
|
||||
return &SessionsTool{listFn: listFn, historyFn: historyFn}
|
||||
}
|
||||
|
||||
func (t *SessionsTool) Name() string { return "sessions" }
|
||||
@@ -113,7 +111,7 @@ func (t *SessionsTool) Execute(ctx context.Context, args map[string]interface{})
|
||||
}
|
||||
items := t.listFn(limit * 3)
|
||||
if len(items) == 0 {
|
||||
return firstNonEmpty(t.noSessionsText, "No sessions."), nil
|
||||
return "No sessions.", nil
|
||||
}
|
||||
if len(kindFilter) > 0 {
|
||||
filtered := make([]SessionInfo, 0, len(items))
|
||||
@@ -284,13 +282,6 @@ func (t *SessionsTool) Execute(ctx context.Context, args map[string]interface{})
|
||||
}
|
||||
return sb.String(), nil
|
||||
default:
|
||||
return firstNonEmpty(t.unsupportedAction, "unsupported action"), nil
|
||||
return "unsupported action", nil
|
||||
}
|
||||
}
|
||||
|
||||
func firstNonEmpty(v, fallback string) string {
|
||||
if v != "" {
|
||||
return v
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package tools
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -133,10 +135,19 @@ func (sm *SubagentManager) runTask(ctx context.Context, task *SubagentTask) {
|
||||
sm.mu.Unlock()
|
||||
} else {
|
||||
// Original one-shot logic
|
||||
systemPrompt := "You are a subagent. Follow workspace AGENTS.md and complete the task independently."
|
||||
if ws := strings.TrimSpace(sm.workspace); ws != "" {
|
||||
if data, err := os.ReadFile(filepath.Join(ws, "AGENTS.md")); err == nil {
|
||||
txt := strings.TrimSpace(string(data))
|
||||
if txt != "" {
|
||||
systemPrompt = "Workspace policy (AGENTS.md):\n" + txt + "\n\nComplete the given task independently and report the result."
|
||||
}
|
||||
}
|
||||
}
|
||||
messages := []providers.Message{
|
||||
{
|
||||
Role: "system",
|
||||
Content: "You are a subagent. Complete the given task independently and report the result.",
|
||||
Content: systemPrompt,
|
||||
},
|
||||
{
|
||||
Role: "user",
|
||||
@@ -184,7 +195,7 @@ func (sm *SubagentManager) runTask(ctx context.Context, task *SubagentTask) {
|
||||
SessionKey: fmt.Sprintf("subagent:%s", task.ID),
|
||||
Content: announceContent,
|
||||
Metadata: map[string]string{
|
||||
"trigger": "subagent",
|
||||
"trigger": "subagent",
|
||||
"subagent_id": task.ID,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -10,13 +10,11 @@ import (
|
||||
)
|
||||
|
||||
type SubagentsTool struct {
|
||||
manager *SubagentManager
|
||||
noSubagentsText string
|
||||
unsupportedAction string
|
||||
manager *SubagentManager
|
||||
}
|
||||
|
||||
func NewSubagentsTool(m *SubagentManager, noSubagentsText, unsupportedAction string) *SubagentsTool {
|
||||
return &SubagentsTool{manager: m, noSubagentsText: noSubagentsText, unsupportedAction: unsupportedAction}
|
||||
func NewSubagentsTool(m *SubagentManager) *SubagentsTool {
|
||||
return &SubagentsTool{manager: m}
|
||||
}
|
||||
|
||||
func (t *SubagentsTool) Name() string { return "subagents" }
|
||||
@@ -58,7 +56,7 @@ func (t *SubagentsTool) Execute(ctx context.Context, args map[string]interface{}
|
||||
case "list":
|
||||
tasks := t.filterRecent(t.manager.ListTasks(), recentMinutes)
|
||||
if len(tasks) == 0 {
|
||||
return firstNonEmpty(t.noSubagentsText, "No subagents."), nil
|
||||
return "No subagents.", nil
|
||||
}
|
||||
var sb strings.Builder
|
||||
sb.WriteString("Subagents:\n")
|
||||
@@ -71,7 +69,7 @@ func (t *SubagentsTool) Execute(ctx context.Context, args map[string]interface{}
|
||||
if strings.EqualFold(strings.TrimSpace(id), "all") {
|
||||
tasks := t.filterRecent(t.manager.ListTasks(), recentMinutes)
|
||||
if len(tasks) == 0 {
|
||||
return firstNonEmpty(t.noSubagentsText, "No subagents."), nil
|
||||
return "No subagents.", nil
|
||||
}
|
||||
sort.Slice(tasks, func(i, j int) bool { return tasks[i].Created > tasks[j].Created })
|
||||
var sb strings.Builder
|
||||
@@ -94,7 +92,7 @@ func (t *SubagentsTool) Execute(ctx context.Context, args map[string]interface{}
|
||||
if strings.EqualFold(strings.TrimSpace(id), "all") {
|
||||
tasks := t.filterRecent(t.manager.ListTasks(), recentMinutes)
|
||||
if len(tasks) == 0 {
|
||||
return firstNonEmpty(t.noSubagentsText, "No subagents."), nil
|
||||
return "No subagents.", nil
|
||||
}
|
||||
killed := 0
|
||||
for _, task := range tasks {
|
||||
@@ -161,7 +159,7 @@ func (t *SubagentsTool) Execute(ctx context.Context, args map[string]interface{}
|
||||
}
|
||||
return fmt.Sprintf("subagent resumed as %s", label), nil
|
||||
default:
|
||||
return firstNonEmpty(t.unsupportedAction, "unsupported action"), nil
|
||||
return "unsupported action", nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user