CrystalCog is a Crystal implementation of a symbolic AI stack centered on a hypergraph knowledge base. It provides AtomSpace-style atoms and links, truth values, probabilistic and rule-based reasoning, pattern matching, persistence adapters, language processing, and network interfaces.
The repository is a broad and evolving implementation rather than a proven
drop-in replacement for every OpenCog project. Its strongest entry points and
most directly testable behavior are in atomspace, pln, ure, cogserver,
and nlp. Other modules provide additional domain, learning, integration, and
experimental functionality; consult the corresponding specs before relying on
a specific feature.
Install Crystal 1.10.1 or newer, the Crystal package manager (shards), and
the native libraries required by the storage backends you intend to build.
scripts/install-crystal.sh can install Crystal on supported systems.
- Clone the repository:
git clone https://github.com/cogpy/crystalcog.git
cd crystalcog
shards install- Run the test suite:
./scripts/test-runner.sh --all- Install Crystal manually (optional):
./scripts/install-crystal.sh --help
./scripts/install-crystal.sh # Auto-install| Path | Purpose |
|---|---|
src/crystalcog.cr |
Main library facade; assembles the major components and dispatches CLI commands. |
src/bin/ |
Executable launchers, including crystalcog, CogServer, and CogShell. |
src/atomspace/ |
Atoms, links, truth values, AtomSpace operations, storage, and distributed cluster support. |
src/pln/, src/ure/, src/opencog/ |
Probabilistic reasoning, forward/backward rule chaining, and higher-level OpenCog-style integration. |
src/cogserver/ |
HTTP, Telnet, and WebSocket-facing server implementation. |
src/pattern_matching/, src/pattern_mining/ |
Pattern queries, matching, and discovery. |
src/nlp/ |
Tokenization, text processing, and linguistic/semantic representations. |
src/attention/, src/learning/, src/moses/ |
Attention allocation and symbolic/evolutionary learning components. |
src/robotics/, src/spatial/, src/temporal/, src/behavior/ |
Embodied, geometric, temporal, and behavior-oriented modules. |
src/multi_agent/, src/agent-zero/, src/simulation/ |
Multi-agent, Agent-Zero, and simulation facilities. |
src/neural_symbolic/, src/ai_integration/, src/integrations/ |
Neural-symbolic and external-system integration code. |
spec/ |
Component and integration specs. |
examples/, benchmarks/ |
Demos, diagnostics, and performance programs. |
scripts/, docs/ |
Build/test/deployment automation and detailed documentation. |
shard.yml is the authoritative list of executable targets. Some targets
compile component demonstrations or entry modules and are not full standalone
applications.
| Entry point | Role |
|---|---|
src/bin/crystalcog.cr |
Primary crystalcog executable wrapper. |
src/crystalcog.cr |
Top-level library composition and command dispatch. |
src/bin/cogserver.cr |
CogServer executable. |
src/bin/cogshell.cr |
CogShell command-line client. |
src/atomspace/atomspace.cr |
AtomSpace library and component entry. |
src/nlp/nlp_main.cr |
NLP component entry. |
src/moses/moses_main.cr |
MOSES component entry. |
src/attention/attention_main.cr |
Attention component entry. |
src/pattern_matching/pattern_matching_main.cr |
Pattern-matching component entry. |
Build and run the main executable with:
crystal build src/bin/crystalcog.cr
./crystalcog --helpshard.yml also declares targets for PLN, URE, NLP, MOSES, attention, learning,
pattern matching/mining, CogServer, CogShell, spatial, temporal, behavior, and
other modules.
- Read
shard.ymlto see dependencies and executable targets. - Read
src/crystalcog.crto understand how the major modules are composed. - Read
src/atomspace/atomspace.crand the specs inspec/atomspace/for the core knowledge representation and persistence model. - Follow
src/pln/pln.crandsrc/ure/ure.crwith their corresponding specs to understand probabilistic and rule-driven inference. - Read
src/cogserver/cogserver.crandspec/cogserver/for the server and API boundary. - Branch into
src/nlp/,src/pattern_matching/,src/attention/, or another subsystem based on your use case, starting with its*_main.crfile. - Use
examples/README.mdandbenchmarks/for concrete programs after the core architecture is clear.
CrystalCog includes robust Crystal installation methods for environments where standard installation may not work:
- Automatic Installation: Scripts automatically install Crystal when needed
- Multiple Methods: Snap, APT, binary, and source installation options
- Offline Support: Works without internet access using bundled resources
- Development Mode: Fallback wrappers for development environments
For detailed installation instructions, see: docs/CRYSTAL_INSTALLATION.md
crystalcog/
├── src/ # Crystal source code
│ ├── cogutil/ # Core utilities (logging, config, random)
│ ├── atomspace/ # AtomSpace hypergraph knowledge representation
│ ├── pln/ # Probabilistic Logic Networks
│ ├── ure/ # Unified Rule Engine
│ ├── opencog/ # Main OpenCog reasoning interface
│ ├── cogserver/ # Network server with REST API
│ ├── pattern_matching/ # Advanced pattern matching engine
│ ├── nlp/ # Natural language processing
│ ├── moses/ # Evolutionary optimization
│ ├── agent-zero/ # Distributed agent networks
│ └── ... # Additional components
├── spec/ # Formal test specifications (Crystal spec framework)
├── examples/ # Example programs and demos
│ ├── demos/ # Interactive demonstrations
│ └── tests/ # Test programs and debugging utilities
├── benchmarks/ # Performance benchmarking programs
├── scripts/ # Build, deployment, and development scripts
│ ├── validation/ # Validation and integration test scripts
│ └── production/ # Production deployment scripts
├── docs/ # Comprehensive documentation
│ └── INDEX.md # Documentation index
└── crystal-lang/ # Crystal installation resources
The test runner script provides comprehensive testing capabilities with automatic Crystal installation:
# Run all tests
./scripts/test-runner.sh --all
# Run specific component tests
./scripts/test-runner.sh --component atomspace
# Run with linting and formatting
./scripts/test-runner.sh --lint
# Run benchmarks
./scripts/test-runner.sh --benchmarks
# Show all available options
./scripts/test-runner.sh --helpNote: The test runner has been validated and approved for production use. See Test Runner Validation Report for detailed validation results.
# Build main executable
crystal build src/bin/crystalcog.cr
# Build specific components
crystal build src/cogutil/cogutil.cr
crystal build src/atomspace/atomspace.crshards install# Run all formal specifications
crystal spec
# Run specific component specs
crystal spec spec/atomspace/
crystal spec spec/pln/
crystal spec spec/cogutil/# Run basic examples
crystal run examples/tests/test_basic.cr
crystal run examples/tests/test_pln.cr
# Run demonstrations
crystal run examples/demos/demo.cr
crystal run examples/demos/demo_advanced_reasoning.cr
# See examples/README.md for complete catalogThe CogServer includes a comprehensive integration test that validates all network API functionality:
# Build the CogServer
crystal build src/bin/cogserver.cr -o cogserver_bin
# Start CogServer for testing
crystal run examples/tests/start_test_cogserver.cr &
# Run integration test script
./scripts/validation/test_cogserver_integration.shThe integration test validates:
- HTTP REST API endpoints (7 endpoints)
- Telnet command interface (4 commands)
- WebSocket protocol upgrade
- Atom CRUD operations
- Error handling and validation
# Run all Crystal specs
crystal spec
# Run example test programs
crystal run examples/tests/test_cogserver_api.cr
crystal run examples/tests/test_enhanced_api.cr
crystal run examples/tests/test_persistence.cr
# See examples/README.md for all available test programsCrystalCog implements the complete OpenCog stack:
- CogUtil: Core utilities and logging
- AtomSpace: Hypergraph knowledge representation with comprehensive persistence
- PLN: Probabilistic Logic Networks for reasoning
- URE: Unified Rule Engine for inference
- CogServer: Network server for distributed processing with REST API
- Pattern Matching: Advanced pattern matching and query engine with recursive composition, temporal analysis, machine learning, and statistical inference
- Persistence: Multiple storage backends (File, SQLite, Network)
- Cognitive Kernels: Agent-Zero Genesis cognitive processing units with hypergraph state persistence
- Tensor Field Encoding: Mathematical sequence generators for cognitive state representation
- RocksDB Storage: High-performance key-value storage (0.9ms store, 0.5ms load)
- PostgreSQL Storage: Enterprise-grade database for production and multi-user access
- SQLite Storage: Relational database with indexing for medium datasets
- File Storage: Human-readable Scheme format for small datasets and debugging
- Network Storage: Distributed AtomSpace access via CogServer
- Multiple Storage: Attach multiple backends for redundancy and performance
- Hypergraph State Persistence: Complete cognitive kernel state management
- Cognitive Kernels: Complete cognitive processing units with state persistence
- Tensor Field Encoding: Mathematical sequence generators (prime, fibonacci, harmonic, factorial, powers of two)
- Attention Allocation: Adaptive priority management across multiple kernels
- Meta-Cognitive Processing: Recursive self-description and meta-level tracking
- Operation-Specific Encodings: Specialized tensor configurations for reasoning, learning, memory, attention
- REST Endpoints: Complete HTTP API for AtomSpace operations
- Storage Management: Attach/detach storage via REST API
- WebSocket Support: Real-time communication capabilities
- Session Management: Track client connections and state
# Create AtomSpace with persistence
atomspace = AtomSpace::AtomSpace.new
# Add some knowledge
dog = atomspace.add_concept_node("dog")
animal = atomspace.add_concept_node("animal")
atomspace.add_inheritance_link(dog, animal)
# Save to high-performance RocksDB storage
rocksdb_storage = atomspace.create_rocksdb_storage("main", "knowledge.rocks")
rocksdb_storage.open
rocksdb_storage.store_atomspace(atomspace)
# Or use PostgreSQL for production/enterprise
postgres_storage = atomspace.create_postgres_storage("prod", "user:pass@localhost/opencog")
# Or traditional file storage for debugging
file_storage = atomspace.create_file_storage("debug", "knowledge.scm")
file_storage.open
file_storage.store_atomspace(atomspace)
# Create cognitive kernel with hypergraph state persistence
kernel = AtomSpace::CognitiveKernel.new([128, 64], 0.8, 1, "reasoning")
kernel.add_concept_node("agent-zero")
# Store complete cognitive state
hypergraph_storage = kernel.atomspace.create_hypergraph_storage("cognitive", "state.scm")
hypergraph_storage.open
kernel.store_hypergraph_state(hypergraph_storage)
# Generate tensor field encodings
prime_encoding = kernel.tensor_field_encoding("prime", include_attention: true)
hypergraph_encoding = kernel.hypergraph_tensor_encoding
# Save via REST API
curl -X POST http://localhost:18080/storage/saveCrystalCog includes comprehensive validation scripts to ensure your environment is correctly configured:
Validate that all performance profiling tools are correctly installed and functional:
# Run the profiling tools validation
./scripts/validation/validate_profiling_tools.shThis validates:
- All 9 profiling tool files exist
- Executable permissions are correct
- Script execution and output format
- Dependency compatibility via
scripts/validation/check_dependencies.sh - Guix package/environment validation via
scripts/validation/validate-guix-packages.sh - Documentation completeness
- Test suite coverage
- Optional Crystal syntax validation (when Crystal is installed)
Check that all required dependencies are installed and compatible:
# Run the dependency compatibility check
./scripts/validation/check_dependencies.shThis checks:
- Crystal compiler and version compatibility
- Database dependencies (SQLite3, PostgreSQL)
- Shard dependencies from shard.yml
- Profiling tool component files
- Guix environment (if available)
For Guix users, validate the Guix package definitions:
# Run Guix package validation
./scripts/validation/validate-guix-packages.shThis validates:
- Package definition files exist (gnu/packages/opencog.scm)
- Guix manifest exists (guix.scm)
- Channel definition exists (.guix-channel)
- Optional Scheme syntax validation (when Guile is installed)
Run all validation checks at once:
# Run profiling tools validation
./scripts/validation/validate_profiling_tools.sh
# Run demo profiling tools validation
./scripts/validation/validate-demo-profiling-tools.sh
# Run dependency compatibility check
./scripts/validation/check_dependencies.sh
# Run Guix package validation
./scripts/validation/validate-guix-packages.shFor detailed validation reports, see:
CrystalCog includes comprehensive production deployment scripts for enterprise-ready environments:
# Run the production environment setup (requires root)
sudo ./scripts/production/setup-production.sh
# Or with custom configuration
sudo ./scripts/production/setup-production.sh \
--install-dir /opt/crystalcog \
--service-user crystalcog \
--backup-dir /backup/crystalcogThe production setup script automatically configures:
- Docker & Docker Compose: Containerized deployment
- System Security: UFW firewall, fail2ban intrusion detection
- SSL Certificates: Automated certificate management
- Service Management: Systemd service for auto-start
- Monitoring Stack: Prometheus, Grafana, and ELK stack
- Backup System: Automated backup cron jobs
- Log Rotation: Automatic log management
- High Availability: Multi-container architecture with health checks
- Security Hardened: Minimal attack surface, non-root containers
- Monitoring Ready: Complete observability stack included
- Backup & Recovery: Automated data protection
- Scalable: Resource limits and scaling configuration
Validate your production setup:
# Comprehensive validation
./validate-setup-production.sh
# Docker Compose validation
docker-compose -f docker-compose.production.yml config
# Health check
./scripts/production/healthcheck.sh- Container Deployment:
docker-compose.production.yml - Kubernetes Deployment:
deployments/k8s/ - Guix System:
guix environment -m guix.scm - Manual Installation: Traditional system installation
If you encounter database linking errors during build or test, you can disable specific database backends using environment variables:
# Disable RocksDB (requires librocksdb-dev)
export DISABLE_ROCKSDB=1
# Disable SQLite3 (requires libsqlite3-dev)
export DISABLE_SQLITE3=1
# Disable PostgreSQL (requires libpq-dev)
export DISABLE_POSTGRES=1
# You can combine multiple flags:
DISABLE_ROCKSDB=1 DISABLE_SQLITE3=1 DISABLE_POSTGRES=1 crystal spec
# Or set them all in your shell profile for Windows builds:
export DISABLE_ROCKSDB=1 DISABLE_SQLITE3=1 DISABLE_POSTGRES=1When all database backends are disabled, use MemoryStorageNode or FileStorageNode for persistence.
If you encounter RocksDB linking errors during build or test:
# Error: cannot find -lrocksdb
# Solution: Use the DISABLE_ROCKSDB environment variable
export DISABLE_ROCKSDB=1
./scripts/test-runner.sh --all
# Or for individual commands:
DISABLE_ROCKSDB=1 crystal spec spec/atomspace/
DISABLE_ROCKSDB=1 crystal build src/bin/crystalcog.crRocksDB is an optional high-performance storage backend. The system will use SQLite and PostgreSQL backends when RocksDB is disabled.
The test runner automatically installs Crystal if it's not found. If automatic installation fails:
# Manual installation
./scripts/install-crystal.sh --help
./scripts/install-crystal.sh
# Or use system package manager
# Ubuntu/Debian:
curl -fsSL https://crystal-lang.org/install.sh | sudo bash
# macOS:
brew install crystalIf tests fail unexpectedly:
# 1. Ensure dependencies are installed
shards install
# 2. Try with verbose output
./scripts/test-runner.sh --component atomspace --verbose
# 3. Run specific test file
crystal spec spec/atomspace/atomspace_spec.cr --verbose
# 4. Check formatting issues
crystal tool format --check src/ spec/For more troubleshooting information, see the Test Runner Validation Report.
CrystalCog is a complete Crystal language implementation with all functionality.
For complete documentation, see the Documentation Index.
Key Documents:
- Development Roadmap - Project roadmap and implementation plan
- Crystal Installation Guide - Installation instructions
- API Documentation - Complete API reference
- Examples Guide - Example programs and usage
- Persistence API - Storage backend documentation
- Advanced Pattern Matching - Pattern matching guide
- PLN Reasoning - Probabilistic Logic Networks
- Production Deployment - Deployment guide
- Integration Test Validation - Integration test validation
- Security Policy - Security and vulnerability reporting
- Install Crystal using the provided scripts
- Run the test suite to verify your environment
- Make changes and test thoroughly
- Submit pull requests with comprehensive tests
This repository is licensed under the AGPL-3.0 License. See the LICENSE file for more information.
Note: CrystalCog represents a next-generation implementation of OpenCog, providing improved performance and safety while maintaining full compatibility with OpenCog concepts and APIs.