externalize more agent/tool strings and compaction note templates

This commit is contained in:
DBT
2026-02-23 16:15:30 +00:00
parent 6431f5792d
commit 6848f8f674
7 changed files with 113 additions and 43 deletions

View File

@@ -19,12 +19,14 @@ type SessionInfo struct {
}
type SessionsTool struct {
listFn func(limit int) []SessionInfo
historyFn func(key string, limit int) []providers.Message
listFn func(limit int) []SessionInfo
historyFn func(key string, limit int) []providers.Message
noSessionsText string
unsupportedAction string
}
func NewSessionsTool(listFn func(limit int) []SessionInfo, historyFn func(key string, limit int) []providers.Message) *SessionsTool {
return &SessionsTool{listFn: listFn, historyFn: historyFn}
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 (t *SessionsTool) Name() string { return "sessions" }
@@ -111,7 +113,7 @@ func (t *SessionsTool) Execute(ctx context.Context, args map[string]interface{})
}
items := t.listFn(limit * 3)
if len(items) == 0 {
return "No sessions.", nil
return firstNonEmpty(t.noSessionsText, "No sessions."), nil
}
if len(kindFilter) > 0 {
filtered := make([]SessionInfo, 0, len(items))
@@ -283,6 +285,13 @@ func (t *SessionsTool) Execute(ctx context.Context, args map[string]interface{})
}
return strings.TrimSpace(sb.String()), nil
default:
return "unsupported action", nil
return firstNonEmpty(t.unsupportedAction, "unsupported action"), nil
}
}
func firstNonEmpty(v, fallback string) string {
if strings.TrimSpace(v) != "" {
return v
}
return fallback
}