diff --git a/cortex-tui/src/runner/event_loop.rs b/cortex-tui/src/runner/event_loop.rs index 49527c0f..14f21a7a 100644 --- a/cortex-tui/src/runner/event_loop.rs +++ b/cortex-tui/src/runner/event_loop.rs @@ -844,6 +844,41 @@ impl EventLoop { tool_calls_executed.join("\n") }; + // CRITICAL: Handle case where LLM produced no text output + // This can happen when the LLM only makes tool calls without explanation + // In this case, provide a meaningful summary so the parent agent gets feedback + let effective_content = if final_content.trim().is_empty() { + if tool_calls_executed.is_empty() { + // No tools and no content - something went wrong + format!( + "The {} subagent completed but produced no output or tool calls. \ + This may indicate an issue with the task or model response.", + subagent_type + ) + } else { + // Tools executed but no text explanation - provide summary + let success_count = tool_calls_executed + .iter() + .filter(|s| s.contains("success")) + .count(); + let error_count = tool_calls_executed + .iter() + .filter(|s| s.contains("error") || s.contains("failed")) + .count(); + format!( + "The {} subagent completed {} tool call(s) ({} successful, {} failed) \ + but did not provide a textual summary. Task: {}", + subagent_type, + tool_calls_executed.len(), + success_count, + error_count, + description + ) + } + } else { + final_content + }; + let output = format!( "{}\n\n\ Tools executed:\n{}\n\n\ @@ -852,7 +887,7 @@ impl EventLoop { agent_type: {}\n\ description: {}\n\ ", - final_content, tools_summary, id, subagent_type, description + effective_content, tools_summary, id, subagent_type, description ); let duration = started_at.elapsed();