You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Guard against empty response — covers both iteration 0 and post-tool cycles
526
+
// Use accumulated_text from intermediate tool_use iterations as fallback.
521
527
let text = if text.trim().is_empty(){
522
-
warn!(
523
-
agent = %manifest.name,
524
-
iteration,
525
-
input_tokens = total_usage.input_tokens,
526
-
output_tokens = total_usage.output_tokens,
527
-
messages_count = messages.len(),
528
-
"Empty response from LLM — guard activated"
529
-
);
530
-
if any_tools_executed {
531
-
"[Task completed — the agent executed tools but did not produce a text summary.]".to_string()
528
+
if !accumulated_text.is_empty(){
529
+
debug!(
530
+
agent = %manifest.name,
531
+
accumulated_len = accumulated_text.len(),
532
+
"Using accumulated text from intermediate tool_use iterations"
533
+
);
534
+
accumulated_text.clone()
532
535
}else{
533
-
"[The model returned an empty response. This usually means the model is overloaded, the context is too large, or the API key lacks credits. Try again or check /status.]".to_string()
536
+
warn!(
537
+
agent = %manifest.name,
538
+
iteration,
539
+
input_tokens = total_usage.input_tokens,
540
+
output_tokens = total_usage.output_tokens,
541
+
messages_count = messages.len(),
542
+
"Empty response from LLM — guard activated"
543
+
);
544
+
if any_tools_executed {
545
+
"[Task completed — the agent executed tools but did not produce a text summary.]".to_string()
546
+
}else{
547
+
"[The model returned an empty response. This usually means the model is overloaded, the context is too large, or the API key lacks credits. Try again or check /status.]".to_string()
548
+
}
534
549
}
535
550
}else{
536
551
text
@@ -651,6 +666,18 @@ pub async fn run_agent_loop(
651
666
consecutive_max_tokens = 0;
652
667
any_tools_executed = true;
653
668
669
+
// Capture any text content from this tool_use turn — the LLM may
670
+
// produce text alongside tool calls (e.g., a message to the user
671
+
// before calling memory_store). Without this, the text is lost if
672
+
// the next iteration returns EndTurn with empty text.
// Guard against empty response — covers both iteration 0 and post-tool cycles
1580
+
// Guard against empty response — use accumulated text as fallback (streaming).
1553
1581
let text = if text.trim().is_empty(){
1554
-
warn!(
1555
-
agent = %manifest.name,
1556
-
iteration,
1557
-
input_tokens = total_usage.input_tokens,
1558
-
output_tokens = total_usage.output_tokens,
1559
-
messages_count = messages.len(),
1560
-
"Empty response from LLM (streaming) — guard activated"
1561
-
);
1562
-
if any_tools_executed {
1563
-
"[Task completed — the agent executed tools but did not produce a text summary.]".to_string()
1582
+
if !accumulated_text.is_empty(){
1583
+
debug!(
1584
+
agent = %manifest.name,
1585
+
accumulated_len = accumulated_text.len(),
1586
+
"Using accumulated text from intermediate tool_use iterations (streaming)"
1587
+
);
1588
+
accumulated_text.clone()
1564
1589
}else{
1565
-
"[The model returned an empty response. This usually means the model is overloaded, the context is too large, or the API key lacks credits. Try again or check /status.]".to_string()
1590
+
warn!(
1591
+
agent = %manifest.name,
1592
+
iteration,
1593
+
input_tokens = total_usage.input_tokens,
1594
+
output_tokens = total_usage.output_tokens,
1595
+
messages_count = messages.len(),
1596
+
"Empty response from LLM (streaming) — guard activated"
1597
+
);
1598
+
if any_tools_executed {
1599
+
"[Task completed — the agent executed tools but did not produce a text summary.]".to_string()
1600
+
}else{
1601
+
"[The model returned an empty response. This usually means the model is overloaded, the context is too large, or the API key lacks credits. Try again or check /status.]".to_string()
0 commit comments