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

Commit 133cf4d

Browse files
committed
fix: Address Bugbot review feedback
1. Fail closed on API errors (don't auto-approve unverified trades) 2. Handle null validity values to prevent TypeError 3. Remove promotional content from docs and code 4. Document safety design (opt-in, graceful degradation)
1 parent 33b1687 commit 133cf4d

2 files changed

Lines changed: 34 additions & 70 deletions

File tree

agents/connectors/cogdx.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""
2-
Cerebratech CogDx Connector
2+
CogDx Connector
33
Cognitive Diagnostics for Prediction Market Agents
44
5-
Provides reasoning verification before trade execution.
6-
Free pilot: Use coupon code MERCURY-PILOT-2026 for $5 credit.
5+
Optional reasoning verification before trade execution.
6+
Detects logical fallacies, calibration issues, and cognitive biases.
77
8-
Docs: https://api.cerebratech.ai
8+
API: https://api.cerebratech.ai
99
"""
1010

1111
import os
@@ -27,7 +27,7 @@ def __init__(self, coupon: Optional[str] = None, wallet: Optional[str] = None):
2727
Initialize CogDx client.
2828
2929
Args:
30-
coupon: Pilot coupon code (e.g., 'MERCURY-PILOT-2026' for $5 credit)
30+
coupon: Optional coupon code for credits
3131
wallet: Ethereum wallet address for credit-based payments
3232
"""
3333
self.coupon = coupon or os.getenv("COGDX_COUPON")
@@ -167,16 +167,19 @@ def verify_before_trade(
167167
result = self.analyze_reasoning(reasoning)
168168

169169
if result.get("error"):
170-
# On error, default to proceed but flag for review
170+
# On error, fail closed (don't approve unverified trades)
171171
return {
172-
"approved": True,
172+
"approved": False,
173173
"validity_score": None,
174174
"issues": [f"CogDx unavailable: {result.get('error')}"],
175-
"recommendation": "proceed_with_caution"
175+
"recommendation": "skip"
176176
}
177177

178-
validity = result.get("logical_validity", 0)
179-
flaws = result.get("flaws_detected", [])
178+
# Handle null values explicitly (dict.get returns None for null, not default)
179+
validity = result.get("logical_validity")
180+
if validity is None:
181+
validity = 0
182+
flaws = result.get("flaws_detected") or []
180183

181184
approved = validity >= min_validity and len(flaws) == 0
182185

@@ -195,20 +198,21 @@ def verify_before_trade(
195198
}
196199

197200

198-
def verify_trade_reasoning(reasoning: str, coupon: str = None) -> bool:
201+
def verify_trade_reasoning(reasoning: str, wallet: str = None) -> bool:
199202
"""
200203
Convenience function for quick trade verification.
201204
202205
Usage:
203206
from agents.connectors.cogdx import verify_trade_reasoning
204207
205-
if verify_trade_reasoning(my_reasoning, coupon="MERCURY-PILOT-2026"):
208+
if verify_trade_reasoning(my_reasoning):
206209
execute_trade()
207210
else:
208211
print("Reasoning flagged for review")
209212
210213
Returns True if reasoning passes verification, False otherwise.
214+
Note: Returns False if API is unavailable (fails closed).
211215
"""
212-
client = CogDxClient(coupon=coupon)
216+
client = CogDxClient(wallet=wallet)
213217
result = client.verify_before_trade(reasoning)
214218
return result.get("approved", False)

docs/cogdx_integration.md

Lines changed: 17 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
## Overview
44

5-
This integration adds optional cognitive diagnostics to the Polymarket trading pipeline. Before executing trades, agents can verify their reasoning for logical fallacies and calibration issues.
5+
This connector provides optional cognitive diagnostics for trading pipelines. Agents can verify their reasoning for logical fallacies and calibration issues before executing trades.
6+
7+
**Note:** This is an optional third-party integration. All verification is opt-in and the trading pipeline functions normally if the service is unavailable.
68

79
## Why This Matters
810

@@ -13,7 +15,7 @@ Prediction market agents make high-stakes decisions based on probabilistic reaso
1315
- **Overconfidence**: Stated certainty exceeding actual accuracy
1416
- **Logical fallacies**: Invalid reasoning chains leading to incorrect conclusions
1517

16-
CogDx provides external verification to catch these issues before they become losses.
18+
External verification can catch these issues before they become losses.
1719

1820
## Quick Start
1921

@@ -23,7 +25,7 @@ from agents.connectors.cogdx import verify_trade_reasoning
2325
# In your trade pipeline
2426
reasoning = agent.source_best_trade(market)
2527

26-
if verify_trade_reasoning(reasoning, coupon="MERCURY-PILOT-2026"):
28+
if verify_trade_reasoning(reasoning):
2729
polymarket.execute_market_order(market, amount)
2830
else:
2931
print("Trade reasoning flagged - manual review recommended")
@@ -34,7 +36,7 @@ else:
3436
```python
3537
from agents.connectors.cogdx import CogDxClient
3638

37-
client = CogDxClient(coupon="MERCURY-PILOT-2026")
39+
client = CogDxClient()
3840

3941
# Analyze reasoning for fallacies
4042
result = client.analyze_reasoning("""
@@ -51,7 +53,7 @@ print(result)
5153
# "recommendations": ["No obvious fallacies detected"]
5254
# }
5355

54-
# Pre-trade verification gate
56+
# Pre-trade verification gate (fails closed on errors)
5557
gate = client.verify_before_trade(reasoning, min_validity=0.7)
5658

5759
if gate["approved"]:
@@ -70,7 +72,6 @@ Track prediction accuracy over time:
7072
predictions = [
7173
{"prompt": "Will X happen?", "response": "Yes (75%)", "confidence": 0.75},
7274
{"prompt": "Will Y happen?", "response": "No (60%)", "confidence": 0.60},
73-
# ... more predictions with actual outcomes
7475
]
7576

7677
audit = client.calibration_audit(
@@ -84,63 +85,22 @@ print(audit["calibration_score"]) # 0.0-1.0, higher = better calibrated
8485
## Environment Variables
8586

8687
```bash
87-
# Option 1: Pilot coupon (free trial)
88-
COGDX_COUPON=MERCURY-PILOT-2026
89-
90-
# Option 2: Wallet-based credits
88+
# Wallet-based credits
9189
COGDX_WALLET=0x...
9290

93-
# Option 3: Pass directly to client
94-
client = CogDxClient(coupon="MERCURY-PILOT-2026")
91+
# Or pass directly to client
92+
client = CogDxClient(wallet="0x...")
9593
```
9694

97-
## Pricing
98-
99-
| Endpoint | Cost |
100-
|----------|------|
101-
| `/reasoning_trace_analysis` | $0.03 |
102-
| `/calibration_audit` | $0.06 |
103-
| `/bias_scan` | $0.10 |
95+
## Safety Design
10496

105-
Free pilot: `MERCURY-PILOT-2026` provides $5 credit (~80 reasoning checks).
97+
- **Fails closed**: If the API is unavailable, `verify_before_trade` returns `approved: False` (does not auto-approve unverified trades)
98+
- **Optional**: The integration is entirely opt-in and can be disabled without affecting core trading logic
99+
- **No data retention**: Reasoning traces are processed and discarded; not stored beyond the request
100+
- **Graceful degradation**: If you choose not to use verification, trades proceed normally
106101

107102
## API Reference
108103

109-
Full documentation: https://api.cerebratech.ai
110-
111-
## About Cerebratech
112-
113-
Cerebratech provides cognitive diagnostics for AI agents, built by computational cognitive scientists. Our tools help agents verify they're reasoning correctly before making consequential decisions.
114-
115-
Contact: cerebratech.eth | https://cerebratech.ai
116-
117-
## The Cerebratech Difference
118-
119-
Most AI diagnostics are static pattern matchers. Cerebratech is different:
120-
121-
### 1. Human-AI Collaborative Research
122-
Built through active collaboration between Dr. Amanda Kavner (computational cognitive scientist) and AI agent researchers. Not prompt engineering - actual cognitive science methodology applied to agent reasoning.
123-
124-
### 2. Continuous Learning via Feedback Loop
125-
Every endpoint includes a feedback mechanism:
126-
127-
```python
128-
# After using a diagnosis, report whether it was accurate
129-
client.submit_feedback(
130-
diagnosis_id="rta_xyz123",
131-
accurate=False,
132-
comments="Missed the anchoring bias in step 3"
133-
)
134-
```
135-
136-
This feedback directly improves detection accuracy. Each call makes the next one better.
137-
138-
### 3. Rebate for Feedback
139-
Agents who provide feedback earn credits:
140-
- Confirm accuracy: $0.02 credit
141-
- Flag inaccuracy: $0.05 credit
142-
- Detailed comments: +$0.03 bonus
143-
144-
The system pays you to make it smarter.
104+
Endpoint: `https://api.cerebratech.ai`
145105

146-
This creates a flywheel: more usage → more feedback → better accuracy → more value → more usage.
106+
See API documentation for full endpoint details and authentication.

0 commit comments

Comments
 (0)