Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(agent): keep retry directives compatible with Anthropic

Haozhe Wu59244749aeca
diff --git a/agent/src/agent/loop.py b/agent/src/agent/loop.py
index 811525f68..624f18edf 100644
--- a/agent/src/agent/loop.py
+++ b/agent/src/agent/loop.py
@@ -662,7 +662,7 @@ class AgentLoop(ToolCallLifecycle):
"iter": current_iter,
}
)
- messages.append({"role": "system", "content": pending_directive})
+ messages.append({"role": "user", "content": f"<system>{pending_directive}</system>"})
stream = TurnStream(
grounding=self._grounding, emit=self._emit, iteration=current_iter,
@@ -911,11 +911,11 @@ class AgentLoop(ToolCallLifecycle):
consecutive_empty_responses += 1
messages.append(
{
- "role": "system",
+ "role": "user",
"content": (
- "[SYSTEM] Your previous response was empty (no text, no tool "
+ "<system>Your previous response was empty (no text, no tool "
"calls). Respond again with either your next tool call or "
- "your final plain-text answer."
+ "your final plain-text answer.</system>"
),
}
)
@@ -947,11 +947,11 @@ class AgentLoop(ToolCallLifecycle):
messages.append({"role": "assistant", "content": final_content})
messages.append(
{
- "role": "system",
+ "role": "user",
"content": (
- "[SYSTEM] Your previous response was not released: it contained "
+ "<system>Your previous response was not released: it contained "
"tool-call syntax even though tool calling is unavailable now. "
- "Provide the final answer as plain prose only, with no XML/DSML tags."
+ "Provide the final answer as plain prose only, with no XML/DSML tags.</system>"
),
}
)
diff --git a/agent/tests/test_agent_loop_content_filter.py b/agent/tests/test_agent_loop_content_filter.py
index d31f7f4c8..471e427b6 100644
--- a/agent/tests/test_agent_loop_content_filter.py
+++ b/agent/tests/test_agent_loop_content_filter.py
@@ -234,12 +234,18 @@ def test_single_empty_response_recovers_with_nudge(
assert result["status"] == "success"
assert result["content"] == "Finally."
assert llm.calls == 2
- system_msgs = [
+ nudge_msgs = [
m for m in llm.messages_history[1]
- if "[SYSTEM]" in str(m.get("content", ""))
+ if "<system>" in str(m.get("content", ""))
and "empty" in str(m.get("content", "")).casefold()
]
- assert len(system_msgs) == 1
+ assert len(nudge_msgs) == 1
+ # Regression for #2115: the mid-run nudge must not use the system role.
+ # langchain-anthropic rejects a second, non-leading system message with
+ # "Received multiple non-consecutive system messages", so a transient
+ # empty reply must retry through a user message, matching the steering
+ # messages moved in #1109/#1112.
+ assert nudge_msgs[0].get("role") == "user"
def test_auto_compact_summary_hard_deadline(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path