From 96845d1e442599f517aaffd3154ab1ae765ace7a Mon Sep 17 00:00:00 2001 From: viettranx Date: Sun, 8 Mar 2026 00:06:13 +0700 Subject: [PATCH] fix(media): set result.Media on create_image and add MEDIA: fallback in subagent exec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- internal/tools/create_image.go | 1 + internal/tools/subagent_exec.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/internal/tools/create_image.go b/internal/tools/create_image.go index 96467d13..d4dd07c4 100644 --- a/internal/tools/create_image.go +++ b/internal/tools/create_image.go @@ -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 diff --git a/internal/tools/subagent_exec.go b/internal/tools/subagent_exec.go index 67763c1e..0ebf6b56 100644 --- a/internal/tools/subagent_exec.go +++ b/internal/tools/subagent_exec.go @@ -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{