fix(media): set result.Media on create_image and add MEDIA: fallback in subagent exec

Root cause: create_image tool only set ForLLM:"MEDIA:path" but never
populated result.Media. The main agent loop parses MEDIA: prefix via
parseMediaResult(), but the subagent exec loop only checked result.Media
— so media paths were silently lost for all subagent/spawn workflows.

This caused the entire downstream pipeline (task.Media → AnnounceQueue →
PublishInbound → ContentSuffix → session) to receive empty media, making
images invisible in WS chat despite Telegram working fine.

Fixes:
- create_image.go: set result.Media = []string{imagePath}
- subagent_exec.go: add MEDIA: prefix fallback parsing as safety net
This commit is contained in:
viettranx committed 2026-03-08 00:06:13 +07:00
1 parent e06b44179c
commit 96845d1e44
2 files changed
+11

No files matched your search

+1
View File
@@ -131,6 +131,7 @@ func (t *CreateImageTool) Execute(ctx context.Context, args map[string]interface
}
result := &Result{ForLLM: fmt.Sprintf("MEDIA:%s", imagePath)}
result.Media = []string{imagePath}
result.Deliverable = fmt.Sprintf("[Generated image: %s]\nPrompt: %s", filepath.Base(imagePath), prompt)
result.Provider = providerName
result.Model = model
+10
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"log/slog"
"strings"
"time"
"github.com/nextlevelbuilder/goclaw/internal/bus"
@@ -229,6 +230,15 @@ func (sm *SubagentManager) executeTask(ctx context.Context, task *SubagentTask)
// Capture media file paths from tool results (e.g. image generation).
if len(result.Media) > 0 {
mediaPaths = append(mediaPaths, result.Media...)
} else if strings.HasPrefix(strings.TrimSpace(result.ForLLM), "MEDIA:") {
// Fallback: parse MEDIA: prefix from ForLLM (same as agent loop's parseMediaResult)
p := strings.TrimSpace(strings.TrimSpace(result.ForLLM)[6:])
if nl := strings.IndexByte(p, '\n'); nl >= 0 {
p = strings.TrimSpace(p[:nl])
}
if p != "" {
mediaPaths = append(mediaPaths, p)
}
}
messages = append(messages, providers.Message{