This is a complete C/C++ implementation of AIChat as a cognitive kernel system, built on GGML and llama.cpp backends. It implements OpenCog cognitive primitives as high-performance tensor operations following the Echo.Kern architecture.
- Bootstrap: Multi-stage initialization (Stage 0-3)
- Scheduler: Membrane-aware task scheduling (≤5µs/tick target)
- Memory: Tensor-backed memory management (≤100ns/op target)
- HGFS: Hypergraph filesystem using GGML tensors
- AtomSpace: Hypergraph knowledge representation
- ECAN: Economic attention allocation networks
- PLN: Probabilistic logic networks for reasoning
- ESN: Echo state network reservoir computing
- Inference: llama.cpp integration
- Chat: Chat completion API
- Streaming support
- Command-line argument parsing
- REPL mode with readline
- Single-query command mode
# Install dependencies
sudo apt-get install cmake build-essential libreadline-dev
# GGML and llama.cpp are fetched automatically by CMakeIf you use VS Code or GitHub Codespaces, open the repository in the bundled dev container at /.devcontainer/devcontainer.json. It installs the C/C++ toolchain, readline, ninja, and doxygen, then bootstraps cpp/build with a ready-to-build CMake configuration.
cd cpp
mkdir build && cd build
cmake ..
make -j$(nproc)This will build:
aichat- Main executablelibaichat-core.a- Core library- Test executables (if BUILD_TESTS=ON)
cmake -DBUILD_TESTS=OFF .. # Disable tests
cmake -DCMAKE_BUILD_TYPE=Release .. # Release build with optimizations./aichat -m model.gguf "What is the capital of France?"./aichat -r -m model.gguf-m, --model PATH Path to GGUF model file (required)
-c, --config PATH Path to configuration file
-r, --repl Start in REPL mode
-s, --stream Enable streaming output
-t, --temperature T Sampling temperature (default: 0.7)
-n, --max-tokens N Maximum tokens to generate (default: 512)
-h, --help Show help message
# Run all tests
cd build
ctest
# Run specific test
./tests/test_kernel bootstrap
./tests/test_cognitive atomspace- CI:
.github/workflows/aicpp-ci.yamlbuilds and tests thecpp/implementation on Ubuntu and macOS for pull requests, pushes tomain, and manual runs. - Release:
.github/workflows/aicpp-release.yamlrebuilds, tests, installs, and publishes versionedaicpparchives to GitHub Releases forv*tags, while also exposing packaged artifacts for manual workflow runs.
Generate Doxygen documentation:
cd build
make doc
# Open docs/html/index.html- Scheduler tick: ≤5µs per tick
- Memory operations: ≤100ns per operation
- Context switch: Real-time capable
- Tensor operations: Optimized via GGML SIMD kernels
- Bootstrap (Stage 0-3)
- Scheduler (dtesn_sched_*)
- Memory Management (dtesn_mem_*)
- Hypergraph FS (hgfs_*)
- Interrupts
- Syscalls
- I/O
- Sync primitives
- Timers
- Protection/ABI
- AtomSpace (hypergraph tensor)
- ECAN (attention allocation)
- PLN (probabilistic reasoning)
- ESN (reservoir computing)
- CognitiveLoop orchestration
- Model loading (llama.cpp)
- Chat completion
- Streaming
- Multi-model support
- Function calling
- RAG integration
- Argument parsing
- REPL with readline
- Command mode
- Session management
- Role/agent support
- History persistence
All memory is allocated through the tensor-backed allocator (dtesn_mem_alloc), which uses GGML tensors as backing store. This enables:
- Unified memory for CPU and GPU operations
- Automatic quantization support
- Hardware acceleration via GGML kernels
The AtomSpace is implemented as a hypergraph where:
- Nodes are GGML tensors (512-dim embeddings)
- Edges are weighted connections
- Queries traverse tensor graph using GGML operations
ECAN implements economic attention using:
- STI (short-term importance) spreading
- LTI (long-term importance) accumulation
- Decay dynamics for forgetting
PLN implements basic inference rules:
- Deduction: (A→B, B→C) ⇒ (A→C)
- Induction: (A→B, C→B) ⇒ (A→C)
- Abduction: (A→B, A→C) ⇒ (C→B)
Truth values are computed using tensor operations.
cpp/
├── CMakeLists.txt # Build configuration
├── include/
│ ├── aichat.h # Main header
│ └── aichat/
│ ├── kernel.h # Kernel API
│ ├── cognitive.h # Cognitive API
│ ├── llm.h # LLM API
│ └── cli.h # CLI API
├── src/
│ ├── kernel/ # Kernel implementation (C)
│ ├── cognitive/ # Cognitive components (C++)
│ ├── llm/ # LLM integration (C++)
│ ├── cli/ # CLI/REPL (C++)
│ └── main.cpp # Entry point
├── tests/ # Test suite
└── docs/ # Documentation
- C: C99, K&R braces, 4-space indent
- C++: C++17, same style as C
- Comments: Doxygen
/** ... */for all public functions - Alignment: 64-byte for SIMD optimization
- Error handling: Return codes (0 = success, negative = error)
Dual-licensed under MIT or Apache 2.0, same as the Rust version.