Skip to content
This repository was archived by the owner on May 11, 2026. It is now read-only.

Commit 8253787

Browse files
committed
fix: Move submit_feedback inside CogDxClient class + add HTTP error handling
Bugbot fixes: 1. submit_feedback was dead code after return statement - now properly inside class 2. calibration_audit and bias_scan now check response.ok before parsing JSON 3. All methods now return consistent error structures This ensures: - Feedback submission is callable via client.submit_feedback() - Non-200 responses don't cause silent failures - Error handling is consistent across all methods
1 parent 03d6221 commit 8253787

1 file changed

Lines changed: 47 additions & 32 deletions

File tree

agents/connectors/cogdx.py

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,15 @@ def calibration_audit(
112112
},
113113
timeout=30
114114
)
115+
116+
if response.status_code == 402:
117+
return {"error": "payment_required", "calibration_score": None}
118+
if not response.ok:
119+
return {"error": f"http_{response.status_code}", "calibration_score": None}
120+
115121
return response.json()
116122
except Exception as e:
117-
return {"error": str(e)}
123+
return {"error": str(e), "calibration_score": None}
118124

119125
def bias_scan(
120126
self,
@@ -147,9 +153,15 @@ def bias_scan(
147153
},
148154
timeout=30
149155
)
156+
157+
if response.status_code == 402:
158+
return {"error": "payment_required", "biases_detected": None}
159+
if not response.ok:
160+
return {"error": f"http_{response.status_code}", "biases_detected": None}
161+
150162
return response.json()
151163
except Exception as e:
152-
return {"error": str(e)}
164+
return {"error": str(e), "biases_detected": None}
153165

154166
def verify_before_trade(
155167
self,
@@ -212,37 +224,7 @@ def verify_before_trade(
212224
"issues": issues,
213225
"recommendation": recommendation
214226
}
215-
216-
217-
def verify_trade_reasoning(
218-
reasoning: str,
219-
coupon: str = None,
220-
wallet: str = None
221-
) -> bool:
222-
"""
223-
Convenience function for quick trade verification.
224227

225-
Usage:
226-
from agents.connectors.cogdx import verify_trade_reasoning
227-
228-
if verify_trade_reasoning(my_reasoning):
229-
execute_trade()
230-
else:
231-
print("Reasoning flagged for review")
232-
233-
Args:
234-
reasoning: The reasoning trace to verify
235-
coupon: Optional coupon code for credits
236-
wallet: Optional wallet address for credits
237-
238-
Returns:
239-
True if reasoning passes verification, False otherwise.
240-
Note: Returns False if API is unavailable (fails closed).
241-
"""
242-
client = CogDxClient(coupon=coupon, wallet=wallet)
243-
result = client.verify_before_trade(reasoning)
244-
return result.get("approved", False)
245-
246228
def submit_feedback(
247229
self,
248230
endpoint: str,
@@ -259,6 +241,9 @@ def submit_feedback(
259241
"""
260242
Submit feedback on a diagnosis to improve detection and earn credits.
261243
244+
Feedback builds shared reality across agents. Network effects improve
245+
consensus and detection accuracy for everyone.
246+
262247
Binary core (required):
263248
- endpoint: Which endpoint was diagnosed
264249
- agent_id: Your agent identifier
@@ -321,3 +306,33 @@ def submit_feedback(
321306

322307
except Exception as e:
323308
return {"error": str(e), "received": False}
309+
310+
311+
def verify_trade_reasoning(
312+
reasoning: str,
313+
coupon: str = None,
314+
wallet: str = None
315+
) -> bool:
316+
"""
317+
Convenience function for quick trade verification.
318+
319+
Usage:
320+
from agents.connectors.cogdx import verify_trade_reasoning
321+
322+
if verify_trade_reasoning(my_reasoning):
323+
execute_trade()
324+
else:
325+
print("Reasoning flagged for review")
326+
327+
Args:
328+
reasoning: The reasoning trace to verify
329+
coupon: Optional coupon code for credits
330+
wallet: Optional wallet address for credits
331+
332+
Returns:
333+
True if reasoning passes verification, False otherwise.
334+
Note: Returns False if API is unavailable (fails closed).
335+
"""
336+
client = CogDxClient(coupon=coupon, wallet=wallet)
337+
result = client.verify_before_trade(reasoning)
338+
return result.get("approved", False)

0 commit comments

Comments
 (0)