Skip to content

CMLKevin/ORACLE

Repository files navigation

ORACLE

Orchestrated Reasoning for Accurate Calibrated Likelihood Estimation

ORACLE is an advanced AI-powered forecasting system that generates well-calibrated probability estimates for future events. It uses a multi-layered pipeline with multiple AI agents that research, deliberate, debate, and synthesize their estimates to produce accurate and reliable forecasts.

Features

  • 5-Layer Forecasting Pipeline: Systematic approach combining research, estimation, debate, risk analysis, and calibration
  • Multi-Agent Architecture: 8 diverse AI agents with different analytical perspectives
  • Real-Time Web Research: Perplexity and OpenAI deep research integration for up-to-date information
  • Adversarial Debate: Agents argue opposing positions to stress-test forecasts
  • Black Swan Detection: Identifies low-probability, high-impact tail risks (optional)
  • Calibrated Confidence Intervals: Statistical methods for reliable uncertainty quantification
  • Multiple Model Support: Choose from Claude, GPT-4, Gemini, DeepSeek, and more via OpenRouter
  • Modern Web Interface: Real-time progress tracking, interactive visualizations, dark mode

Quick Start

Prerequisites

  • Node.js 18+
  • npm or yarn
  • OpenRouter API key (get one at openrouter.ai)

Installation

# Clone the repository git clone <repository-url> cd oracle # Install dependencies npm install # Set up environment variables cp .env.example .env.local # Edit .env.local and add your OPENROUTER_API_KEY # Initialize the database npx prisma db push # Start the development server npm run dev

Open http://localhost:3000 to use the application.

Environment Variables

Create a .env.local file with:

# Required OPENROUTER_API_KEY=your_openrouter_api_key_here # Optional DATABASE_URL="file:./dev.db" DEBUG=false

How It Works

ORACLE processes forecasting questions through 5 specialized layers:

Layer 1: Decomposition & Research

  • Parses the forecasting question into key components
  • Identifies relevant reference classes and historical precedents
  • Conducts web research to gather current information
  • Synthesizes a base rate estimate from historical data

Layer 2: Estimation Swarm

8 diverse AI agents independently analyze the question:

  • Base Analyst: Neutral, balanced analysis
  • Skeptical Analyst: Focuses on why predictions fail
  • Constructive Analyst: Focuses on theories of change
  • Historical Analyst: Heavy emphasis on base rates
  • Quantitative Analyst: Explicit probability calculations
  • Plus 3 additional specialized perspectives

Layer 3: Adversarial Debate

  • Agents are paired to argue opposing positions
  • Multi-round debates stress-test assumptions
  • Convergence analysis measures agreement
  • Post-debate estimates incorporate new insights

Layer 4: Black Swan Detection (Optional)

  • Generates tail risk scenarios
  • Researches each scenario for plausibility
  • Calculates aggregate tail risk adjustments
  • Identifies high-impact scenarios that could invalidate forecasts

Layer 5: Calibration & Synthesis

  • Applies temperature scaling for calibration
  • Uses extremization based on agent agreement
  • Generates final probability distribution
  • Produces confidence intervals (50% and 90%)
  • Creates quality metrics and methodology summary

Project Structure

oracle/ β”œβ”€β”€ app/ # Next.js App Router pages β”‚ β”œβ”€β”€ api/ # API routes β”‚ β”‚ └── forecast/ # Forecast CRUD endpoints β”‚ β”œβ”€β”€ forecast/[id]/ # Forecast detail page β”‚ β”œβ”€β”€ history/ # Forecast history page β”‚ β”œβ”€β”€ guide/ # User guide page β”‚ β”œβ”€β”€ methodology/ # Methodology documentation β”‚ └── settings/ # User settings page β”œβ”€β”€ components/ # React components β”‚ β”œβ”€β”€ forecast/ # Forecast-specific components β”‚ β”œβ”€β”€ ui/ # Reusable UI components β”‚ β”œβ”€β”€ layout/ # Layout components β”‚ └── settings/ # Settings components β”œβ”€β”€ lib/ # Core libraries β”‚ β”œβ”€β”€ oracle/ # Forecasting pipeline β”‚ β”‚ β”œβ”€β”€ pipeline.ts # Main orchestration β”‚ β”‚ β”œβ”€β”€ layer1-decomposition.ts β”‚ β”‚ β”œβ”€β”€ layer2-swarm.ts β”‚ β”‚ β”œβ”€β”€ layer3-debate.ts β”‚ β”‚ β”œβ”€β”€ layer4-blackswan.ts β”‚ β”‚ β”œβ”€β”€ layer5-calibration.ts β”‚ β”‚ β”œβ”€β”€ prompts.ts # AI prompts β”‚ β”‚ β”œβ”€β”€ config.ts # Runtime configuration β”‚ β”‚ β”œβ”€β”€ cache.ts # Response caching β”‚ β”‚ └── error-recovery.ts β”‚ β”œβ”€β”€ openrouter.ts # OpenRouter API client β”‚ β”œβ”€β”€ models.ts # Model configurations β”‚ β”œβ”€β”€ types.ts # TypeScript types β”‚ β”œβ”€β”€ validations.ts # Zod schemas β”‚ β”œβ”€β”€ db.ts # Database client β”‚ └── store.ts # Zustand store β”œβ”€β”€ prisma/ # Database schema β”‚ └── schema.prisma β”œβ”€β”€ hooks/ # Custom React hooks └── docs/ # Documentation 

Available Models

Web Research Models

Model Provider Description Speed Cost
perplexity/sonar-reasoning-pro Perplexity Search with reasoning (Default) Medium High
perplexity/sonar-deep-research Perplexity Deep research Slow High
perplexity/sonar-pro-search Perplexity Fast professional search Fast Medium
openai/o3-deep-research OpenAI Most comprehensive research Slow High

Reasoning Models

Model Provider Description Speed Cost
google/gemini-3-flash-preview Google Fast, cost-effective (Default) Fast Low
anthropic/claude-opus-4.5 Anthropic Highest capability Medium High
google/gemini-3-pro-preview Google Excellent quantitative analysis Fast Medium
deepseek/deepseek-v3.2-speciale DeepSeek Strong reasoning, low cost Fast Low

API Reference

Create Forecast

POST /api/forecast Content-Type: application/json { "statusQuo": "Current state description (50-5000 chars)", "resolutionConditions": "How the question resolves (20-2000 chars)", "webResearchModel": "perplexity/sonar-reasoning-pro", "reasoningModel": "google/gemini-3-flash-preview", "enableBlackSwan": true }

Get Forecast

GET /api/forecast/{id}

Start Forecast Processing

POST /api/forecast/{id}/run

List Forecasts

GET /api/forecast?limit=10&offset=0&status=COMPLETED

Delete Forecast

DELETE /api/forecast/{id}

See docs/API.md for complete API documentation.

Configuration

Pipeline Configuration

The pipeline can be configured via lib/oracle/config.ts:

// Search limits layer1MaxSearches: 24, // Max searches in Layer 1 layer4MaxSearches: 40, // Max searches in Layer 4 // Caching enableWebSearchCache: true, enableLLMCache: true, // Timeouts webSearchTimeoutMs: 30000, llmCallTimeoutMs: 120000, forecastTimeoutMs: 600000, // Retry configuration maxRetries: 3, retryBaseDelayMs: 1000,

Presets

import { applyFastPreset, applyThoroughPreset, applyBalancedPreset } from '@/lib/oracle/config'; applyFastPreset(); // Faster, fewer searches applyThoroughPreset(); // More comprehensive, slower applyBalancedPreset(); // Default configuration

Development

Scripts

npm run dev # Start development server npm run build # Build for production npm run start # Start production server npm run lint # Run ESLint npm run db:push # Push schema to database npm run db:studio # Open Prisma Studio npm run db:generate # Generate Prisma client

Database

ORACLE uses SQLite by default with Prisma ORM. To use PostgreSQL:

  1. Update prisma/schema.prisma:
datasource db {  provider = "postgresql"  url = env("DATABASE_URL") }
  1. Update .env.local:
DATABASE_URL="postgresql://user:password@localhost:5432/oracle"
  1. Run migrations:
npx prisma migrate dev

Best Practices for Forecasting

Good Questions

  • Specific, time-bound, and objectively verifiable
  • Clear resolution criteria
  • Sufficient context for research

Examples:

  • "Will the Federal Reserve cut interest rates before June 2025?"
  • "Will SpaceX successfully launch Starship to orbit by Q2 2025?"

Avoid

  • Vague questions without timeframes
  • Subjective or opinion-based questions
  • Questions that can't be verified

Examples to avoid:

  • "Will the stock market go up?" (no timeframe)
  • "Is AI good for society?" (subjective)

Performance Considerations

  • Typical forecast time: 3-8 minutes depending on models
  • Token usage: ~50,000-100,000 tokens per forecast
  • Caching: Web searches and LLM calls are cached to reduce costs
  • Black Swan toggle: Disable to reduce time by ~20%

Troubleshooting

Common Issues

"OPENROUTER_API_KEY not set"

  • Ensure .env.local exists with your API key
  • Restart the development server after adding the key

"Forecast stuck in RUNNING"

  • Check server logs for errors
  • The forecast may have timed out (10 min limit)
  • Delete and retry the forecast

"Rate limit exceeded"

  • OpenRouter has rate limits per API key
  • Wait a few minutes before retrying
  • Consider using a paid plan for higher limits

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

About

advanced AI-powered forecasting system that generates well-calibrated probability estimates for future events

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages