From 714778bda8430259c92e2a1a659c37a2af010589 Mon Sep 17 00:00:00 2001 From: leekaimao <361204176@qq.com> Date: Mon, 23 Mar 2026 19:53:31 +0800 Subject: [PATCH] fix: place reminder text after tool_result in message content The reminder was incorrectly inserted at the beginning of the results list, which violates Anthropic API's requirement that tool_result must immediately follow tool_use. Changed insert(0, ...) to append(...) to place the reminder after all tool_result blocks. Fixes BadRequestError: tool_use ids were found without tool_result blocks immediately after. --- agents/s03_todo_write.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agents/s03_todo_write.py b/agents/s03_todo_write.py index af0109cba..13ecbf7a3 100644 --- a/agents/s03_todo_write.py +++ b/agents/s03_todo_write.py @@ -187,7 +187,7 @@ def agent_loop(messages: list): used_todo = True rounds_since_todo = 0 if used_todo else rounds_since_todo + 1 if rounds_since_todo >= 3: - results.insert(0, {"type": "text", "text": "Update your todos."}) + results.append({"type": "text", "text": "Update your todos."}) messages.append({"role": "user", "content": results})