enhance sessions history filters and subagent steer lifecycle

This commit is contained in:
DBT
2026-02-23 13:20:09 +00:00
parent 5f8678f091
commit 68afec08d0
3 changed files with 63 additions and 25 deletions

View File

@@ -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},
"include_tools": map[string]interface{}{"type": "boolean", "description": "include tool role messages in history", "default": false},
},
"required": []string{"action"},
}
@@ -52,6 +53,10 @@ func (t *SessionsTool) Execute(ctx context.Context, args map[string]interface{})
if v, ok := args["limit"].(float64); ok && int(v) > 0 {
limit = int(v)
}
includeTools := false
if v, ok := args["include_tools"].(bool); ok {
includeTools = v
}
switch action {
case "list":
@@ -78,10 +83,23 @@ func (t *SessionsTool) Execute(ctx context.Context, args map[string]interface{})
if key == "" {
return "key is required for history", nil
}
h := t.historyFn(key, limit)
h := t.historyFn(key, limit*3)
if len(h) == 0 {
return "No history.", nil
}
if !includeTools {
filtered := make([]providers.Message, 0, len(h))
for _, m := range h {
if strings.TrimSpace(strings.ToLower(m.Role)) == "tool" {
continue
}
filtered = append(filtered, m)
}
h = filtered
}
if len(h) == 0 {
return "No history (after filters).", nil
}
if len(h) > limit {
h = h[len(h)-limit:]
}