From c86e314d7f0a95c0063face170412ccb94995871 Mon Sep 17 00:00:00 2001 From: DBT Date: Mon, 23 Feb 2026 13:27:00 +0000 Subject: [PATCH] extend sessions and subagents tools with filters and log/send actions --- pkg/tools/sessions_tool.go | 36 ++++++++++++++++++++++++++++++++---- pkg/tools/subagents_tool.go | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/pkg/tools/sessions_tool.go b/pkg/tools/sessions_tool.go index e4ef767..74b093a 100644 --- a/pkg/tools/sessions_tool.go +++ b/pkg/tools/sessions_tool.go @@ -36,9 +36,10 @@ func (t *SessionsTool) Parameters() map[string]interface{} { return map[string]interface{}{ "type": "object", "properties": map[string]interface{}{ - "action": map[string]interface{}{"type": "string", "description": "list|history"}, - "key": map[string]interface{}{"type": "string", "description": "session key for history"}, - "limit": map[string]interface{}{"type": "integer", "description": "max items", "default": 20}, + "action": map[string]interface{}{"type": "string", "description": "list|history"}, + "key": map[string]interface{}{"type": "string", "description": "session key for history"}, + "limit": map[string]interface{}{"type": "integer", "description": "max items", "default": 20}, + "kinds": map[string]interface{}{"type": "array", "items": map[string]interface{}{"type": "string"}, "description": "optional session kinds filter for list"}, "include_tools": map[string]interface{}{"type": "boolean", "description": "include tool role messages in history", "default": false}, }, "required": []string{"action"}, @@ -57,17 +58,44 @@ func (t *SessionsTool) Execute(ctx context.Context, args map[string]interface{}) if v, ok := args["include_tools"].(bool); ok { includeTools = v } + kindFilter := map[string]struct{}{} + if rawKinds, ok := args["kinds"].([]interface{}); ok { + for _, it := range rawKinds { + if s, ok := it.(string); ok { + s = strings.ToLower(strings.TrimSpace(s)) + if s != "" { + kindFilter[s] = struct{}{} + } + } + } + } switch action { case "list": if t.listFn == nil { return "sessions list unavailable", nil } - items := t.listFn(limit) + items := t.listFn(limit * 3) if len(items) == 0 { return "No sessions.", nil } + if len(kindFilter) > 0 { + filtered := make([]SessionInfo, 0, len(items)) + for _, s := range items { + k := strings.ToLower(strings.TrimSpace(s.Kind)) + if _, ok := kindFilter[k]; ok { + filtered = append(filtered, s) + } + } + items = filtered + } + if len(items) == 0 { + return "No sessions (after filters).", nil + } sort.Slice(items, func(i, j int) bool { return items[i].UpdatedAt.After(items[j].UpdatedAt) }) + if len(items) > limit { + items = items[:limit] + } var sb strings.Builder sb.WriteString("Sessions:\n") for _, s := range items { diff --git a/pkg/tools/subagents_tool.go b/pkg/tools/subagents_tool.go index 0359766..77a7a82 100644 --- a/pkg/tools/subagents_tool.go +++ b/pkg/tools/subagents_tool.go @@ -24,9 +24,9 @@ func (t *SubagentsTool) Parameters() map[string]interface{} { return map[string]interface{}{ "type": "object", "properties": map[string]interface{}{ - "action": map[string]interface{}{"type": "string", "description": "list|info|kill|steer"}, - "id": map[string]interface{}{"type": "string", "description": "subagent id for info/kill/steer"}, - "message": map[string]interface{}{"type": "string", "description": "steering message for steer action"}, + "action": map[string]interface{}{"type": "string", "description": "list|info|kill|steer|send|log"}, + "id": map[string]interface{}{"type": "string", "description": "subagent id for info/kill/steer/send/log"}, + "message": map[string]interface{}{"type": "string", "description": "steering message for steer/send action"}, }, "required": []string{"action"}, } @@ -73,14 +73,39 @@ func (t *SubagentsTool) Execute(ctx context.Context, args map[string]interface{} return "subagent not found", nil } return "subagent kill requested", nil - case "steer": + case "steer", "send": if id == "" || message == "" { - return "id and message are required for steer", nil + return "id and message are required for steer/send", nil } if !t.manager.SteerTask(id, message) { return "subagent not found", nil } return "steering message accepted", nil + case "log": + if id == "" { + return "id is required for log", nil + } + task, ok := t.manager.GetTask(id) + if !ok { + return "subagent not found", nil + } + var sb strings.Builder + sb.WriteString(fmt.Sprintf("Subagent %s Log\n", task.ID)) + sb.WriteString(fmt.Sprintf("Status: %s\n", task.Status)) + if len(task.Steering) > 0 { + sb.WriteString("Steering Messages:\n") + for _, m := range task.Steering { + sb.WriteString("- " + m + "\n") + } + } + if strings.TrimSpace(task.Result) != "" { + result := strings.TrimSpace(task.Result) + if len(result) > 500 { + result = result[:500] + "..." + } + sb.WriteString("Result Preview:\n" + result) + } + return strings.TrimSpace(sb.String()), nil default: return "unsupported action", nil }