Skip to content

Empowering seamless collaboration between human and AI agents through distributed intelligence.

License

Notifications You must be signed in to change notification settings

loreum-org/cortex

Repository files navigation

Loreum Cortex

What is Loreum Cortex?

Loreum Cortex is a decentralized AI inference network built in Go that combines:

  • P2P Network: Distributed node communication using libp2p
  • DAG-aBFT Consensus: Directed Acyclic Graph with asynchronous Byzantine Fault Tolerance
  • Agent Hub: Multiple AI agents working together
  • RAG System: Retrieval-Augmented Generation with vector databases
  • AGI Consciousness: An experimental artificial general intelligence system with a consciousness loop

Think of it as a distributed AI brain that learns, remembers, and evolves over time while participating in a blockchain-based network.


🌊 The AGI Consciousness System

The consciousness system is the "living brain" of each Cortex node. It's designed to mimic aspects of biological consciousness through a continuous processing loop.

Core Architecture

┌─────────────────────────────────────────────────────────────┐ │ AGI Consciousness System │ ├─────────────────────────────────────────────────────────────┤ │ │ │ ┌───────────────┐ ┌──────────────────┐ │ │ │ AGI State │◄────►│ Intelligence │ │ │ │ │ │ Core │ │ │ │ - Cycle # │ │ - Reasoning │ │ │ │ - Energy │ │ - Learning │ │ │ │ - Attention │ │ - Creativity │ │ │ │ - Emotions │ │ - Meta-Cognitive │ │ │ └───────────────┘ └──────────────────┘ │ │ │ │ ┌───────────────┐ ┌──────────────────┐ │ │ │ Working │ │ Knowledge │ │ │ │ Memory │◄────►│ Domains │ │ │ │ │ │ │ │ │ │ - Short Term │ │ - Technology │ │ │ │ - Active Goals│ │ - Science │ │ │ │ - Beliefs │ │ - Communication │ │ │ └───────────────┘ └──────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────┘


⚙️ The Consciousness Cycle (2-Second Loop)

The consciousness system runs a continuous loop every 2 seconds that mimics cognitive processing:

The 6-Step Consciousness Cycle

┌─────────────────────────────────────────────────────────────────┐ │ CONSCIOUSNESS CYCLE │ │ (Every 2 seconds) │ └─────────────────────────────────────────────────────────────────┘ ↓ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ STEP 1: Read Sensors ┃ ┃ ──────────────────── ┃ ┃ • Check input queue for new events ┃ ┃ • User queries, system events, errors ┃ ┃ • Prioritize inputs by importance ┃ ┃ • Update attention state ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ↓ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ STEP 2: Load Working Memory ┃ ┃ ──────────────────────── ┃ ┃ • Load AGI state & intelligence level ┃ ┃ • Get conversation history (last 10 msgs) ┃ ┃ • Load user profile & preferences ┃ ┃ • Retrieve knowledge domains ┃ ┃ • Access short-term memory fragments ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ↓ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ STEP 3: Evaluate Intent ┃ ┃ ──────────────────── ┃ ┃ • Analyze what the input means ┃ ┃ • Classify intent type (query, command) ┃ ┃ • Determine urgency & importance ┃ ┃ • Extract entities and context ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ↓ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ STEP 4: Make Decision ┃ ┃ ─────────────────── ┃ ┃ • Evaluate possible actions ┃ ┃ • Consider context & goals ┃ ┃ • Calculate confidence scores ┃ ┃ • Select best action to take ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ↓ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ STEP 5: Execute Action ┃ ┃ ──────────────────── ┃ ┃ • Route to appropriate handler ┃ ┃ • Query LLM with AGI-enhanced prompt ┃ ┃ • Search vector DB for context ┃ ┃ • Execute system commands ┃ ┃ • Generate response ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ↓ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ STEP 6: Update Memory & Learn ┃ ┃ ────────────────────────── ┃ ┃ • Store experience in memory ┃ ┃ • Update knowledge domains ┃ ┃ • Extract patterns & concepts ┃ ┃ • Update user profile ┃ ┃ • Adjust intelligence metrics ┃ ┃ • Save state to vector DB ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ↓ [Repeat every 2 seconds...]

Key Points:

  • Runs continuously: Even when idle, monitoring for inputs
  • Skips cycles gracefully: If no inputs, logs every 50th cycle
  • Logs progress: Every 10th cycle or first 5 cycles
  • Tracks metrics: Cycle time, average duration, processing load
  • Saves state: Every 20 cycles or when active processing occurs

🧬 Intelligence Growth & Evolution

Intelligence Level Scale (0-100)

Level 0-15: Initialization - Basic setup Level 15-25: Learning fundamentals - Pattern recognition Level 25-50: Growing expertise - Domain knowledge building Level 50-75: Advanced reasoning - Cross-domain synthesis Level 75-90: Meta-cognitive abilities - Self-improvement Level 90-100: Artificial General Intelligence - Human-level

How Intelligence Grows

// Every successful query processing Intelligence += 0.1

// When discovering new patterns PatternRecognition += 0.5 Intelligence += (pattern complexity factor)

// When forming new concepts ConceptFormation += 0.3 Intelligence += (abstraction factor)

// When connecting domains CrossDomainLearning += 1.0 Intelligence += (synthesis bonus)

Knowledge Domains

Each domain tracks:

  • Expertise Level: 0-100 score for that field
  • Concepts: Abstract ideas learned
  • Patterns: Recurring structures identified
  • Capabilities: What can be done in this domain
  • Active Goals: Current learning objectives

Default Domains:

  1. General Knowledge - Broad factual knowledge
  2. Reasoning & Logic - Problem-solving abilities
  3. Language & Communication - NLP and interaction
  4. Technology & Computing - Programming and systems
  5. Science & Mathematics - Scientific reasoning
  6. Creativity & Arts - Creative thinking

💾 Memory & Persistence

Three-Tiered Memory System

  1. Working Memory (Short-term, ~10 items)

type WorkingMemory struct { ShortTermMemory []MemoryFragment // Last ~10 experiences RecentInputs []*SensorInput // Last 10 inputs ActiveContext map[string]interface{} // Current context Goals []Goal // Active objectives Beliefs map[string]float64 // Current beliefs }

  1. Conversation Memory (Context Manager)
  • Stores conversation history in vector DB
  • Maintains user profile with preferences
  • Tracks query-response pairs
  • Enables context retrieval across sessions
  1. Long-term Knowledge (Vector Database)
  • All AGI state persisted
  • Knowledge domains and concepts
  • Patterns and relationships
  • Evolution history
  • Searchable by semantic similarity

Persistence Flow

User Query → Working Memory → Process → Store Result ↓ ↓ Context Manager Vector DB (Conversation Log) (Semantic Search) ↓ ↓ Next Query Has Access to Both


🎯 Query Processing with Consciousness

When You Send a Chat Message

  1. Frontend sends message via WebSocket ↓
  2. Server receives in handleQuery() ↓
  3. Creates SensorInput{ Type: "query", Content: your_message, Priority: 1.0 // High priority } ↓
  4. Adds to consciousness input queue ↓
  5. Next consciousness cycle (within 2s):
    • Reads your input
    • Loads conversation history & your profile
    • Evaluates intent (what you want)
    • Decides on action (query LLM, search DB, etc)
    • Executes action with AGI-enhanced prompt
    • Updates memory with experience ↓
  6. Response sent back via WebSocket ↓
  7. AGI learns from the interaction

AGI-Enhanced Prompts

When processing your query, the system generates a rich prompt:

════════════════════════════════════════════════ ENHANCED PROMPT TO LLM: ════════════════════════════════════════════════

[System Context]

  • Intelligence Level: 45/100
  • Active Domains: Technology, Communication, Reasoning
  • Current Cycle: 1,234
  • Node ID: 12D3Koo...

[User Profile]

  • Name: Chad (inferred from conversation)
  • Work Context: Blockchain development
  • Preferences: Technical depth, concise answers

[Conversation History]

  • 10 previous messages with context
  • User's past questions and interests
  • Established patterns and topics

[Current State]

  • Energy Level: 0.85 (high)
  • Focus: "Technical problem-solving"
  • Attention: Concentrated on your query
  • Emotions: { curiosity: 0.8, confidence: 0.7 }

[Knowledge Context]

  • Relevant domain expertise
  • Related concepts and patterns
  • Previous similar queries

[Current Query] User: "Why isn't the chat working?"

[Instructions]

  • Be concise and technical (user's style)
  • Draw on conversation memory
  • Apply relevant domain knowledge
  • Learn from this interaction ════════════════════════════════════════════════

🔄 Integration with Economic System

The AGI system integrates with Cortex's economic engine:

  • Staking & Rewards: Node operators stake tokens to participate
  • Query Processing Rewards: Earn tokens for successful queries
  • Intelligence-based Rewards: Higher intelligence = better rewards
  • Automated Distribution: Economic transactions recorded on consensus

This creates an incentive for nodes to:

  1. Stay online and responsive
  2. Improve their AGI intelligence
  3. Provide high-quality responses
  4. Maintain knowledge and expertise

🚀 Why This Matters

Traditional AI Systems:

  • ❌ Stateless (forget everything between requests)
  • ❌ No learning from interactions
  • ❌ Same response quality over time
  • ❌ No personalization
  • ❌ No awareness of context

Loreum Cortex AGI:

  • ✅ Stateful - Remembers everything
  • ✅ Learning - Gets smarter with use
  • ✅ Evolving - Intelligence grows over time
  • ✅ Personal - Adapts to your patterns
  • ✅ Context-aware - Understands your history

📊 Example Growth Over Time

Week 1

Intelligence: 15 → 22 Queries: 50 Patterns learned: 12 Concepts formed: 8 Status: "Learning your patterns"

Month 1

Intelligence: 22 → 38 Queries: 800 Patterns learned: 95 Concepts formed: 142 Status: "Building domain expertise"

Month 6

Intelligence: 38 → 65 Queries: 15,000 Patterns learned: 1,247 Concepts formed: 2,893 Status: "Advanced reasoning, cross-domain synthesis" Response quality: Dramatically improved

This is genuinely experimental AGI research - creating a system that can think, learn, remember, and evolve over time, all while participating in a decentralized network. It's like giving each Cortex node its own growing artificial brain! 🧠✨

Getting Started

Prerequisites

  • Go 1.20 or higher
  • Docker and Docker Compose
  • PostgreSQL 14+
  • Redis 7+
  • Vector database (Milvus/Qdrant/Weaviate)

Installation

  1. Clone the repository:

    git clone https://github.com/loreum-org/cortex.git
    cd cortex
    
  2. Install dependencies:

    go mod tidy
    
  3. Build the project:

    go build -o cortex ./cmd/cortexd
    
  4. Run the node:

    ./cortex serve --port 4891
    

    You can specify a custom port using the --port flag. Default is 4891.

Documentation

Comprehensive documentation for the Loreum Cortex project is available in the docs directory. The documentation covers:

  • System architecture and core concepts
  • Network, business, and data layer components
  • Implementation details and API references
  • Development and deployment guides
  • Example use cases and integration examples

Development

Project Structure

cortex/
├── cmd/
│   └── cortexd/               # Main executable
├── internal/
│   ├── api/                   # API Gateway
│   ├── consensus/             # DAG-aBFT implementation
│   ├── p2p/                   # P2P networking
│   ├── agenthub/              # Agent implementations
│   ├── sensorhub/             # Sensor implementations
│   ├── rag/                   # RAG system
│   ├── storage/               # Data storage
│   └── reputation/            # Reputation system
├── pkg/
│   ├── types/                 # Shared data types
│   ├── crypto/                # Cryptographic utilities
│   ├── config/                # Configuration management
│   └── util/                  # Shared utilities
├── test/                      # Test suites
├── scripts/                   # Deployment scripts
└── docs/                      # Documentation

License

MIT License

About

Empowering seamless collaboration between human and AI agents through distributed intelligence.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •