Skip to content

cogpy/cogdiod

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

37 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CogDiod

CogDiod is an experimental cognitive architecture where each OpenCog AtomSpace Atom is an Inferno Dis VM isolate β€” a live, concurrent execution context β€” rather than a passive data record.

"The knowledge is the program. Each Atom is simultaneously a datum and a process."


Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    CogDiod Kernel                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”‚
β”‚  β”‚ConceptNodeβ”‚  β”‚Implicationβ”‚  β”‚Evaluationβ”‚  ...         β”‚
β”‚  β”‚ Dis VM   β”‚  β”‚  Dis VM  β”‚  β”‚  Dis VM  β”‚              β”‚
β”‚  β”‚ isolate  β”‚  β”‚ isolate  β”‚  β”‚ isolate  β”‚              β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜              β”‚
β”‚       β”‚  Limbo typed channels      β”‚                     β”‚
β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β”‚
β”‚              DisTyx / 9P                                  β”‚
β”‚         /ai/atoms/{uuid}/tv                               β”‚
β”‚         /ai/atoms/{uuid}/sti                              β”‚
β”‚         /ai/stats                                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The Isolate Model

CogDiod follows the same pattern as V8 Isolates (Node.js/Cloudflare Workers), ATen execution contexts (PyTorch), and Erlang processes β€” shared bytecode, isolated state:

Runtime Isolate Unit Shared Resource Protocol
Node.js / workerd V8 Isolate JS bytecode snapshots HTTP / fetch
PyTorch ATen context CUDA/CPU kernels Tensor dispatch
CogDiod Dis VM Isolate Limbo .dis bytecode 9P / DisTyx

Each Atom type (ConceptNode, ImplicationLink, etc.) is an Elbo .elm package β€” a Limbo bytecode module loaded once and instantiated per Atom. The Atom's execution frame, register state, and local value store are per-instance; the bytecode is shared.


Repository Structure

cogdiod/                    # Core C kernel
β”œβ”€β”€ include/
β”‚   β”œβ”€β”€ cogdiod.h           # Core types: AtomIsolate, ElmPackage, CogDiodKernel
β”‚   β”œβ”€β”€ elm_types.h         # Dis VM opcodes, ElmStubDef
β”‚   └── distyx.h            # DisTyx 9P protocol types
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ kernel/
β”‚   β”‚   └── cogdiod_kernel.c  # Kernel: spawn, link, set_tv, PLN deduction
β”‚   β”œβ”€β”€ p9/
β”‚   β”‚   └── distyx.c          # DisTyx: 9P filesystem over UNIX socket
β”‚   └── elbo/
β”‚       └── elm_loader.c      # Elbo package loader and builder
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ concept_node/         # ConceptNode .elm package
β”‚   β”œβ”€β”€ evaluation_link/      # EvaluationLink .elm package
β”‚   └── implication_link/     # ImplicationLink .elm package
└── tests/
    └── test_cogdiod.c        # Integration test suite (22 assertions, all PASS)

cogdiod-lang/               # C bridge server for language integrations
└── bridge/
    β”œβ”€β”€ cogdiod_bridge.h
    └── cogdiod_bridge.c      # UNIX socket JSON bridge

cogdiod-native/             # Five native language integrations
β”œβ”€β”€ maude/
β”‚   β”œβ”€β”€ cogdiod.maude         # β˜… Native Maude source (reflective term rewriting)
β”‚   └── run_maude.clj         # Clojure executor (Maude semantics)
β”œβ”€β”€ perl/
β”‚   └── cogdiod.pl            # β˜… Native Perl 5.34 (context overloading + AUTOLOAD)
β”œβ”€β”€ racket/
β”‚   β”œβ”€β”€ cogdiod.rkt           # β˜… Native Racket source (#lang elbo dialect tower)
β”‚   └── cogdiod_hy.hy         # Hy executor (Racket macro semantics)
β”œβ”€β”€ clojure/
β”‚   └── cogdiod.clj           # β˜… Native Clojure (defprotocol + persistent AtomSpace)
└── guile/
    β”œβ”€β”€ cogdiod.scm           # β˜… Native Guile Scheme (first-class environments)
    └── cogdiod_hy.hy         # Hy executor (Scheme environment semantics)

Five Language Superpowers

1. Maude β€” Reflective Term Rewriting (cogdiod.maude)

Maude's META-LEVEL module allows rules to rewrite other rules. In CogDiod, this means PLN inference rules can learn and rewrite themselves based on observed performance:

mod COGDIOD-META is
  protecting COGDIOD-PLN .

  --- Meta-rule: if deduction has been applied 5+ times with stable results,
  --- boost the formula (learning as differential term rewriting)
  crl [boost-deduction] :
    rule(N, pln-deduction, K, TV) => rule(N, pln-boosted(1.15), K, TV)
    if K >= 5 .
endm

Result: After 5 applications, pln-deduction β†’ pln-boosted(1.15), lifting P(animal) from TV(0.760, 0.648) to TV(0.874, 0.648).

2. Perl β€” Context-Sensitive Atoms + AUTOLOAD (cogdiod.pl)

Perl's use overload and AUTOLOAD make every Atom context-polymorphic and open to runtime extension:

use overload
    '""'  => \&as_string,   # "ConceptNode('cat') TV=(0.80,0.90)"
    '0+'  => \&as_number,   # STI value (numeric context)
    '@{}' => \&as_list,     # linked atom UUIDs (array context)
    'bool'=> \&as_bool;     # strength > 0.5 (boolean context)

# ecan_spread was never defined β€” AUTOLOAD generates it from the name
$cat->ecan_spread(2.5);     # works: STI 0.72 -> 3.22

3. Racket β€” #lang elbo Dialect Tower (cogdiod.rkt)

Racket's #lang system lets you define entire new languages as macro towers. CogDiod gets domain-specific cognitive languages with zero runtime overhead:

#lang elbo/temporal

; This is NOT a function call β€” it is a syntax transformation.
; (before A B c) compiles at read time to a bridge spawn call.
(before cat-eats animal-runs 0.75)   ; => ImplicationLink TV=(0.750, 0.712)
(during cat-eats feeding-time 0.90)  ; => EvaluationLink  TV=(0.900, 0.810)

4. Clojure β€” Protocols + Persistent AtomSpace (cogdiod.clj)

Clojure's defprotocol / extend-protocol solves the Expression Problem for Atoms. Persistent data structures give episodic memory for free:

; Add Visualizable to AtomRecord WITHOUT modifying AtomRecord
(extend-protocol Visualizable
  AtomRecord
  (visualize [atom]
    (let [bar (Math/round (* (:s (get-tv atom)) 20))]
      (str (:type atom) " [" (apply str (repeat bar "β–ˆ")) "] s=" (:s (get-tv atom))))))

; Episodic memory: every version costs O(log n), not O(n)
; v0 β†’ v1 β†’ v2 β†’ v3 β€” all queryable, none mutated

5. Guile Scheme β€” First-Class Environments (cogdiod.scm)

Guile's first-class environments enable hypothetical reasoning without mutating the global AtomSpace:

; Hypothetical: "What if the cat is sick?"
(define child-env (make-child-env global-env '((sick . (TV 0.95 0.90)))))
(eval '(deduce "sick->vet" "sick") child-env)
; => TV(0.855, 0.689)  β€” vs baseline TV(0.180, 0.306)

; Global AtomSpace is UNCHANGED
(lookup global-env "sick") ; => TV(0.200, 0.400)  βœ“

LLM Coprocessor β€” cogpy/llama.limbo

CogDiod integrates with cogpy/llama.limbo, a pure-Limbo LLaMA inference engine, as the canonical local-LLM coprocessor for AtomSpace isolates. Atoms of type llm-coprocessor are bound to a Limbo Llama module instance and respond to MSG_LLM_INFER messages by streaming MSG_LLM_TOKEN replies.

Full GGUF support (F32 / F16 / BF16 / Q4_0 / Q4_1 / Q5_0 / Q5_1 / Q8_0 / Q8_1), GQA + KV cache + RoPE frequency scaling for LLaMA 3.1+, and the complete sampling suite (greedy, temperature, top-k, top-p, min-p, Mirostat v1+v2) are inherited from llama.limbo.

Two transport modes are supported automatically:

  • In-process β€” when CogDiod runs under emu, inference dispatches directly through cogdiod_spawn() onto the appl/cogllama.b Limbo wrapper which imports llama.limbo's modules. Zero serialisation overhead.
  • Subprocess β€” when CogDiod runs natively on POSIX, the bridge forks emu /dis/llama.dis -i for each attached Atom and proxies prompts / tokens over a pipe pair.

9P namespace (DisTyx):

/ai/llm/<atom-uuid>/model      W   one-shot model path at attach
/ai/llm/<atom-uuid>/prompt     W   triggers inference
/ai/llm/<atom-uuid>/response   R   streaming token output
/ai/llm/<atom-uuid>/params     RW  JSON CogLlmParams (temp, top-k, etc.)
/ai/llm/<atom-uuid>/stats      R   tokens/sec, total tokens, model meta

See cogdiod-llama/README.md for the full integration contract, build instructions, and a quickstart.


File Extension Convention

CogDiod uses explicit extensions to avoid the historic .pl Perl/Prolog collision:

Language Extension Role
Elbo (Limbo/Lisp) .elm Dis VM bytecode packages (execution substrate)
Maude .maude Meta-level rule rewriting
Perl .pl Procedural glue, AUTOLOAD, system integration
Prolog .pro Declarative knowledge, Horn clause pattern matching
Guile Scheme .scm First-class environments, hypothetical reasoning
Racket .rkt #lang dialect tower, compile-time macros
Clojure .clj Persistent AtomSpace, protocols, STM

Building

Requires zig cc (or any C11 compiler) and pthreads:

cd cogdiod && make
./cogdiod_test   # 22 assertions, all PASS

For language integrations:

cd cogdiod-native && bash run_all.sh

Requires: perl, clojure (Java 11+), hy (pip install hy).


Formal Specification

See CogDiod_Formal_Specification.md for the complete type system, protocol definition, and lifecycle model.


Related Work


License

MIT

About

CogDiod: OpenCog AtomSpace where each Atom is an Inferno Dis VM isolate. Cognitive daemons served over 9P/DisTyx with Elbo (.elm) packages. Native integrations: Maude, Perl, Racket, Clojure, Guile.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors