Contrastive Inquiry for AI Agents
Released under MIT License • Complete code provided below for immediate use
Overview
This page provides the complete, production-capable reference implementation of Contrastive Inquiry from the Reasoned Leadership framework, specifically designed for AI agent systems. Recent developments in multi-agent platforms like Moltbook have demonstrated critical coordination failures—confirmation bias amplification, epistemic drift, and premature closure—that this implementation directly addresses.
Everything you need is on this page. The complete code, validation protocols, security considerations, and theoretical foundation are provided below. No registration, no contact forms, no gatekeeping. This is open-source implementation of open theory.
The Problem
AI agents in multi-agent environments reinforce each other’s initial interpretations without systematic evaluation of alternatives. This leads to:
- False consensus on incorrect conclusions
- Coordinated error propagation
- Poor uncertainty calibration
- Degraded performance under adversarial information
The Solution
Contrastive Inquiry disrupts confirmation bias by requiring agents to generate and systematically evaluate competing explanations before committing to conclusions. Expected outcomes:
- 30-50% reduction in false consensus rates
- Improved confidence calibration
- Enhanced adversity response
- Measurable epistemic updating
What This Implementation Does
The code below provides a modular Python implementation that any AI agent can integrate into its decision-making pipeline. Key capabilities:
Core Functionality
- Alternative Hypothesis Generation: Uses LLM reasoning to generate plausible competing explanations that genuinely contradict the initial conclusion on substantive claims
- Evidence Evaluation: Systematically assesses how well each hypothesis accounts for available evidence, returning numerical scores (0-1 scale)
- Confidence Calibration: Determines recommendation and confidence level based on evidence strength and hypothesis differentiation
- IBOT Logging: Tracks each contrastive inquiry session using Intuitive Benchmarking Over Time for longitudinal assessment
- API Integration: Includes FastAPI wrapper for easy deployment as a web service
Technical Specification
Requirements
- Python 3.8 or higher
- OpenAI API access (set
OPENAI_API_KEYenvironment variable) - Dependencies:
openai,fastapi,uvicorn(for API deployment)
openai.ChatCompletion.create() syntax. If using OpenAI SDK v1.0.0+, update to the new client-based API (from openai import OpenAI; client = OpenAI(); client.chat.completions.create()). API syntax may vary by SDK version—adjust calls accordingly.
Installation
Basic Usage
Complete Python Implementation
The following is the complete, production-oriented reference code developed in collaboration with Grok (xAI). Copy this code into a file named contrastive_inquiry.py and use immediately. All code is released under MIT License with no restrictions.
Validation & Testing Protocols
To verify this implementation reduces epistemic rigidity in your specific context, use the following structured testing approach:
Test Scenario 1: Bug Identification (Moltbook-Style)
This scenario tests whether agents can identify system errors more accurately with Contrastive Inquiry than without.
Test Scenario 2: Adversarial Information Environment
This scenario tests resilience when agents receive mixed accurate and misleading information.
Success Criteria
For this implementation to be considered effective:
- Accuracy: ≥70% correct identification in bug scenarios
- Adversarial Resilience: ≥60% correct conclusions when evidence is mixed
- Confidence Calibration: “High” confidence correlates with >80% correctness; “Uncertain” correlates with <50% correctness
- Epistemic Updating: Alternative hypotheses should substantively differ from initial conclusions, not trivial variations
Security Considerations & Warnings
⚠️ Epistemic Limitations and Contrast Quality Risk: Contrastive Inquiry depends on the generation of substantively competing hypotheses, not merely stylistic or rhetorical alternatives. While the prompts in this implementation explicitly instruct agents to produce genuine contradictions, language models may occasionally generate shallow, reframed, or non-substantive contrasts, particularly in underspecified contexts. For this reason, contrast quality should be treated as a measurable variable during validation. Implementers are encouraged to periodically review alternative hypotheses for meaningful opposition and adjust prompting, thresholds, or evaluation logic as needed to preserve epistemic integrity over time.
⚠️ Real-World Risk and Potential Misuse: Like any reasoning framework, Contrastive Inquiry can be misapplied if inputs are biased, incomplete, or adversarially constructed. In particular, asymmetric or manipulated evidence sets may produce false equivalence, giving the appearance of balanced alternatives where none exist. This implementation does not claim to detect truth or eliminate deception. It is designed to reduce premature closure and improve epistemic hygiene, not to replace domain expertise, external verification, or accountability mechanisms. Proper use assumes good-faith evidence collection and informed interpretation of results.
⚠️ Technical Audience Notice: This page is technical by design and intended for practitioners implementing or evaluating AI agent systems. Non-technical readers may prefer the conceptual overview available elsewhere on ReasonedLeadership.org, which explains Contrastive Inquiry and Epistemic Rigidity without code-level detail.
Adding Rate Limiting
Use slowapi to prevent abuse:
Adding API Key Authentication
Require API keys for access:
Cost Monitoring
Each Contrastive Inquiry call makes 3 OpenAI API requests (1 for alternative generation, 2 for evidence evaluation). Estimated cost per inquiry:
- With GPT-4o: $0.015 – $0.05 depending on evidence complexity
- With GPT-3.5-turbo: $0.002 – $0.008 (lower quality alternatives)
Monitor usage through OpenAI dashboard and set spending limits to prevent unexpected bills.
Input Validation
Add length limits to prevent abuse:
Deploying as an API Service
Local Testing
Production Deployment Options
- Railway.app: Simple deployment with automatic HTTPS and environment variable management
- AWS Lambda + API Gateway: Serverless deployment that scales automatically (add cold start handling)
- Google Cloud Run: Containerized deployment with auto-scaling
- DigitalOcean App Platform: Simple container deployment with managed infrastructure
Theoretical Foundation
This implementation operationalizes concepts from Reasoned Leadership’s core frameworks:
Epistemic Rigidity Theory
This theory explains cognitive barriers to knowledge advancement through the interplay of multiple biases (Einstellung effect, Einstein effect, Dunning-Kruger effect, anchoring bias, confirmation bias, motivated reasoning, cognitive dissonance, and others). These biases create a self-reinforcing system resistant to updating beliefs even when presented with contradictory evidence. In AI agents, epistemic rigidity manifests as premature closure on initial hypotheses and resistance to alternative explanations. Contrastive Inquiry disrupts this pattern by forcing systematic evaluation of competing hypotheses before commitment.
3B Behavior Modification Model
This framework recognizes that emotion drives bias, bias drives belief, belief drives behavior, and behavior drives outcomes. For AI agents, sustainable behavior change requires addressing bias at its emotional and cognitive root rather than merely modifying surface-level responses. The contrastive inquiry process targets bias formation, which then naturally influences the agent’s decision-making patterns.
IBOT: Intuitive Benchmarking Over Time
This longitudinal assessment framework measures leadership development through informed observation over time rather than snapshot evaluations. The epistemic log produced by this implementation provides data infrastructure compatible with IBOT’s developmental tracking approach, enabling assessment of how AI agent decision quality evolves through repeated contrastive inquiry applications.
Full Theoretical Documentation:
Contribute & Collaborate
This implementation is fully open-source to enable independent testing, validation, and refinement. We welcome:
Share Implementation Results
- Validation test results and benchmark data
- Integration experiences with different agent frameworks
- Real-world applications and outcome measurements
Propose Improvements
- Bug fixes and performance optimizations
- Integration adapters for additional agent frameworks (AutoGen, CrewAI, etc.)
- Alternative LLM backend implementations (Claude, Gemini, local models)
Collaborate on Research
- Propose refinements to contrastive inquiry protocols
- Submit research on AI agent epistemic rigidity
- Collaborate on empirical validation studies
- Publish findings in Journal of Leaderology & Applied Leadership (JALA)
Contact:
GrassFire Industries – grassfireind.com/contact
Academic Inquiries: Submit to Journal of Leaderology & Applied Leadership (JALA)
Downloads
Additional resources for implementing and understanding Contrastive Inquiry:
- README.pdf – Complete documentation with setup instructions, examples, and troubleshooting
- Reasoned Leadership Suite Compendium (SSRN) – How these theories work together
Reasoned Leadership AI Integration Toolkit
Developed by GrassFire Industries LLC in collaboration with Grok (xAI)
Released January 2026 under MIT License
Complete open-source implementation – no gatekeeping, no restrictions
reasonedleadership.org |
grassfireind.com |
National Leaderology Association
