"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(swarm): detect ok/success:false tool failures, not just status:error
Lanre Shittu62b1763b01c1
diff --git a/agent/src/swarm/worker.py b/agent/src/swarm/worker.pyindex a62451448..e4303bd52 100644--- a/agent/src/swarm/worker.py+++ b/agent/src/swarm/worker.py@@ -866,6 +866,9 @@ def _is_error_result(result: str) -> bool:"""Did a tool call return a top-level error envelope?Parses the result as JSON and checks for a top-level ``status == "error"``.+ Also treats ``ok`` / ``success`` explicitly set to ``False`` as an error,+ since some tools (e.g. ``get_stock_news``) report failure only through+ those fields, with no ``status`` key at all.A nested ``status`` (e.g. inside ``data``) is intentionally ignored — onlythe envelope matters for the deliverable contract.@@ -883,7 +886,11 @@ def _is_error_result(result: str) -> bool:# never raise from a classifier on the worker hot path.head = text[:160].lower()return '"status": "error"' in head or '"status":"error"' in head- return isinstance(parsed, dict) and parsed.get("status") == "error"+ if not isinstance(parsed, dict):+ return False+ if parsed.get("status") == "error":+ return True+ return parsed.get("ok") is False or parsed.get("success") is Falsedef _classify_deliverable(diff --git a/agent/tests/test_swarm_output_contract.py b/agent/tests/test_swarm_output_contract.pyindex 12b764779..6e9f9e44f 100644--- a/agent/tests/test_swarm_output_contract.py+++ b/agent/tests/test_swarm_output_contract.py@@ -216,6 +216,33 @@ def test_is_error_result_other_status_values():assert _is_error_result('{"status": "warning"}') is False+def test_is_error_result_ok_false_envelope_no_status_key():+ """A failure reported only via ``ok: false`` (no top-level ``status``,+ e.g. get_stock_news's real failure shape) must count as an error. This+ is the exact envelope that let a failed tool call be silently credited+ as a completed data tool call before this fix."""+ assert (+ _is_error_result('{"ok": false, "error": "eastmoney news fetch failed"}')+ is True+ )+++def test_is_error_result_success_false_envelope_no_status_key():+ assert _is_error_result('{"success": false, "error": "boom"}') is True+++def test_is_error_result_ok_true_is_not_an_error():+ assert _is_error_result('{"ok": true, "data": []}') is False+++def test_is_error_result_nested_ok_false_no_false_positive():+ """A nested ``ok: false`` (e.g. inside ``data``) must NOT count. Only+ the envelope's own ``ok``/``success`` matters, mirroring the existing+ nested-``status`` guarantee."""+ nested = '{"status": "ok", "data": {"ok": false, "detail": "x"}}'+ assert _is_error_result(nested) is False++class _ResultTool(BaseTool):"""Return one canned result or raise to exercise ToolRegistry normalization."""@@ -260,6 +287,12 @@ class _ScriptedLLM:('{"status": "ok", "data": [1]}', False, "ok", "completed"),('{"status": "error", "trace": "...', False, "error", "incomplete"),("", True, "error", "incomplete"),+ (+ '{"ok": false, "error": "eastmoney news fetch failed"}',+ False,+ "error",+ "incomplete",+ ),],)def test_tool_result_event_status_and_evidence_credit_agree(