Skip to main content

A Logic Harness for abductive inference. Anomaly in → Hypothesis out.

Project description

Peircean Abduction

CI PyPI Python 3.10+ License: MIT

A Logic Harness for Abductive Inference - Provider-Agnostic Configuration

Peircean Abduction forces LLMs to stop guessing and start investigating. It implements Charles Sanders Peirce's logical framework to make uncertainty visible and hypotheses testable, with seamless support for multiple LLM providers.

Anomaly in → Hypothesis out.

"The surprising fact, C, is observed.
But if A were true, C would be a matter of course.
Hence, there is reason to suspect that A is true."
— Charles Sanders Peirce, Collected Papers 5.189

🚀 Quick Start

Installation

# Install with optional dependencies for your preferred provider
pip install peircean-abduction[all]  # All providers
# OR
pip install peircean-abduction           # Core only, add providers as needed

# Optional: Install specific providers
pip install peircean-abduction[anthropic]  # Anthropic Claude
pip install peircean-abduction[openai]      # OpenAI GPT
pip install peircean-abduction[gemini]     # Google Gemini
pip install peircean-abduction[ollama]     # Local Ollama

Verify Installation

# Comprehensive system check
peircean --verify

First Run

# Interactive configuration wizard
peircean config wizard

# Or start with prompt generation (no API key required)
peircean "The stock market dropped 5% on good economic news"

🔌 MCP Integration

Peircean Abduction works best with Model Context Protocol (MCP) integration in Claude Desktop, Cursor, and other IDEs.

Automatic Setup

# Automatically configure Claude Desktop / Cursor
peircean --install

Manual Setup

# View current configuration
peircean config show

# List available providers
peircean config providers

# Validate setup
peircean config validate

Usage in Claude Desktop

  1. After installation, restart Claude Desktop
  2. Look for the 🔌 icon indicating active tools
  3. Try it out:

    "Analyze this anomaly: Server latency spiked 10x but CPU usage is flat"


🤖 Provider Configuration

Peircean Abduction supports multiple LLM providers with seamless switching via environment variables.

Quick Configuration

# Interactive setup (recommended)
peircean config wizard

# Manual setup - create .env file
cp .env.example .env
# Edit .env with your provider settings

Supported Providers

Provider Environment Variable Models Installation
Anthropic Claude PEIRCEAN_PROVIDER=anthropic claude-3-sonnet-20241022, claude-3-haiku-20241022 [anthropic]
OpenAI GPT PEIRCEAN_PROVIDER=openai gpt-4, gpt-4-turbo, gpt-3.5-turbo [openai]
Google Gemini PEIRCEAN_PROVIDER=gemini gemini-pro, gemini-pro-vision [gemini]
Ollama (Local) PEIRCEAN_PROVIDER=ollama llama2, codellama, mistral [ollama]

Environment Variables

# Provider selection
export PEIRCEAN_PROVIDER=anthropic
export PEIRCEAN_MODEL=claude-3-sonnet-20241022

# API keys (or use provider-specific env vars)
export PEIRCEAN_API_KEY=your_api_key_here
# OR
export ANTHROPIC_API_KEY=your_anthropic_key

# Feature toggles
export PEIRCEAN_ENABLE_COUNCIL=true
export PEIRCEAN_INTERACTIVE_MODE=false  # Default: prompt-only like Hegelion
export PEIRCEAN_DEBUG_MODE=false

# Performance settings
export PEIRCEAN_TEMPERATURE=0.7
export PEIRCEAN_TIMEOUT_SECONDS=60

🐍 Python API

Basic Usage

from peircean import PeirceanAbduction

# Initialize with default configuration
abduction = PeirceanAbduction()

# Analyze an observation
result = abduction.analyze(
    observation="Server latency spiked 10x but CPU usage is flat",
    domain="technical",
    num_hypotheses=5
)

print(result.best_hypothesis)
print(result.recommended_actions)

Advanced Configuration

from peircean import PeirceanAbduction, Provider
from peircean.config import PeirceanConfig

# Custom configuration
config = PeirceanConfig(
    provider=Provider.OPENAI,
    model="gpt-4",
    temperature=0.8,
    enable_council=True
)

abduction = PeirceanAbduction(config=config)
result = abduction.analyze("Customer churn doubled while NPS remained stable")

Prompt Generation (Hegelion-style)

from peircean import generate_prompt

# Generate prompt for external LLM use
prompt = generate_prompt(
    observation="Sales increased while customer satisfaction decreased",
    domain="business",
    use_council=True
)

print(prompt)  # Copy to any LLM

📚 CLI Reference

Core Commands

# Abductive analysis (default: prompt-only)
peircean "Your observation here"

# Specify domain and options
peircean --domain financial "Market anomaly detected"
peircean --num-hypotheses 3 --council "System behavior unexpected"

# Output formats
peircean --format json "Observation" | jq .
peircean --prompt "Generate abductive prompt"

Configuration Commands

# View current configuration
peircean config show

# Validate setup
peircean config validate

# List available providers
peircean config providers

# Interactive configuration wizard
peircean config wizard

Management Commands

# System verification
peircean --verify

# MCP integration setup
peircean --install

# JSON output for automation
peircean --install --json

Benchmark Commands

# Run all benchmark scenarios
peircean-bench

# Run quick scenarios for fast testing
peircean-bench --quick

# Test specific domain scenarios
peircean-bench --domain financial

# Test provider availability and configuration
peircean-bench --providers

# Export benchmark results to JSON
peircean-bench --export-json results.json

# Test specific scenario
peircean-bench --scenario simple_financial

🧠 How It Works

Peircean Abduction implements Charles Sanders Peirce's three-phase logical framework:

Phase 1: Observe (peircean_observe_anomaly)

  • Input: Raw observation (e.g., "Server latency spiked 10x but CPU is normal")
  • Output: Structured analysis defining why this is surprising and expected baseline

Phase 2: Hypothesize (peircean_generate_hypotheses)

  • Input: Anomaly analysis from Phase 1
  • Output: Distinct, falsifiable hypotheses with testable predictions

Phase 3: Evaluate (peircean_evaluate_via_ibe)

  • Input: Hypotheses from Phase 2
  • Output: Best explanation selected via Inference to Best Explanation (IBE)
  • Optional: Council of Critics evaluation (5 specialist perspectives)

Single-Shot Mode

# Complete analysis in one step
peircean --council "Anomalous system behavior detected"

⚙️ Configuration

Configuration Files

Peircean Abduction automatically loads configuration from:

  1. Environment variables (highest priority)
  2. .env file (current directory and parent directories)
  3. Default values (lowest priority)

Configuration Wizard

# Interactive setup for new users
peircean config wizard

The wizard guides you through:

  • Provider selection and setup
  • API key configuration
  • Feature toggle preferences
  • MCP integration setup

Feature Toggles

Feature Environment Variable Default Description
Council of Critics PEIRCEAN_ENABLE_COUNCIL true Enable multi-perspective evaluation
Interactive Mode PEIRCEAN_INTERACTIVE_MODE false Direct LLM API calls (vs prompt-only)
Debug Mode PEIRCEAN_DEBUG_MODE false Verbose logging and output
Default Domain PEIRCEAN_DEFAULT_DOMAIN general Domain for abductive analysis
Hypotheses Count PEIRCEAN_DEFAULT_NUM_HYPOTHESES 5 Number of hypotheses to generate

🎯 Use Cases

Software Engineering

# Debugging performance anomalies
peircean --domain technical "Database queries slowed down after deployment"

# Investigating system behavior
peircean "User engagement metrics dropped after feature release"

Business Analysis

# Market analysis
peircean --domain financial "Stock price moved opposite to earnings news"

# Customer behavior
peircean --domain general "Customer retention improved while support tickets increased"

Research & Investigation

# Scientific anomalies
peircean --domain scientific "Experimental results contradict established theory"

# Legal analysis
peircean --domain legal "Contract terms seem to create unintended obligations"

📖 Documentation

User Guides

Technical Documentation

Concepts

Examples

Benchmarking


🤝 Contributing

We welcome contributions! See Contributing Guidelines for details.

Development Setup

# Clone repository
git clone https://github.com/Hmbown/peircean-abduction.git
cd peircean-abduction

# Install in development mode
pip install -e .[dev]

# Run tests
pytest

# Run linting
ruff check
ruff format

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

peircean_abduction-1.2.1.tar.gz (126.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

peircean_abduction-1.2.1-py3-none-any.whl (74.1 kB view details)

Uploaded Python 3

File details

Details for the file peircean_abduction-1.2.1.tar.gz.

File metadata

  • Download URL: peircean_abduction-1.2.1.tar.gz
  • Upload date:
  • Size: 126.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for peircean_abduction-1.2.1.tar.gz
Algorithm Hash digest
SHA256 200b35bd3a5b9bebb5f65f2cdecc3ee1d6a655dd3978f31ce6ac7100910d5f7c
MD5 8d29ee1bc4160cc055e252e44bea7082
BLAKE2b-256 8bd1517bc62da2148b913ba72f6d5a5a662c4710004f8c4d26ce2b1e8edf3c94

See more details on using hashes here.

Provenance

The following attestation bundles were made for peircean_abduction-1.2.1.tar.gz:

Publisher: publish.yml on Hmbown/peircean-abduction

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file peircean_abduction-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for peircean_abduction-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 00cba4211799024dd6f931250737f59daf9d3d9a5b4cf48680aae327c977983e
MD5 1c5004ede93f768facd273fa141c8dce
BLAKE2b-256 608f167a68a6a1e54f612636e6649769e86aa126d8568890cb19bda4cf90204d

See more details on using hashes here.

Provenance

The following attestation bundles were made for peircean_abduction-1.2.1-py3-none-any.whl:

Publisher: publish.yml on Hmbown/peircean-abduction

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page