Update s04_subagent.py

解决在实际运行过程中会出现 block[type=text]的 text 为空导致空转的情况
This commit is contained in:
miketan 2026-04-15 11:03:01 +08:00 committed by GitHub
parent 4b95969a03
commit a0d2af6712
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -165,6 +165,11 @@ def agent_loop(messages: list):
output = handler(**block.input) if handler else f"Unknown tool: {block.name}"
print(f" {str(output)[:200]}")
results.append({"type": "tool_result", "tool_use_id": block.id, "content": str(output)})
elif block.type == "text":
if block.text.strip():
results.append(block)
if not results:
return
messages.append({"role": "user", "content": results})