Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(loop): guard wrap-up nudge to mid-iterations only

Haozhe Wu7c242b934c8e
diff --git a/agent/src/agent/loop.py b/agent/src/agent/loop.py
index 52bac772f..55ac75f72 100644
--- a/agent/src/agent/loop.py
+++ b/agent/src/agent/loop.py
@@ -400,8 +400,12 @@ class AgentLoop:
logger.info(f"ReAct iteration {iteration}/{self.max_iterations}")
- # Inject wrap-up nudge when approaching iteration limit
- if iteration == wrap_up_at:
+ # Inject wrap-up nudge when approaching iteration limit.
+ # Skip on the first iteration (tiny budgets) and on the last
+ # iteration (the forced text-only path already guarantees an
+ # answer there) so the nudge never displaces the active-goal
+ # context as the most recent user message.
+ if iteration == wrap_up_at and 1 < iteration < self.max_iterations:
remaining = self.max_iterations - iteration
messages.append({
"role": "user",