From 18224e666beb9a060d356ff88dc6cccee269295d Mon Sep 17 00:00:00 2001 From: Google AI Agent Date: Sun, 12 Apr 2026 23:59:38 +0000 Subject: [PATCH 1/2] docs: add README for nexus symbolic engine --- nexus/README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 nexus/README.md diff --git a/nexus/README.md b/nexus/README.md new file mode 100644 index 0000000..1f5adb2 --- /dev/null +++ b/nexus/README.md @@ -0,0 +1,48 @@ +# Nexus Symbolic Engine (Layer 4) + +This directory contains the core symbolic reasoning and agent state management components for the Nexus. These modules implement a **Layer 4 Cognitive Architecture**, bridging raw perception with high-level planning and decision-making. + +## Architecture Overview + +The system follows a **Blackboard Architecture**, where a central shared memory space allows decoupled modules to communicate and synchronize state. + +### Core Components + +- **`SymbolicEngine`**: A GOFAI (Good Old Fashioned AI) engine that manages facts and rules. It uses bitmasking for fast fact-checking and maintains a reasoning log. +- **`AgentFSM`v*: A Finite State Machine for agents. It transitions between states (e.g., `IDLE`, `ANALYZING`, `STABILIZING`) based on symbolic facts and publishes state changes to the Blackboard. +- **`Blackboard`**: The central communication hub. It allows modules to `write` and `read` state, and `subscribe` to changes. +- **`SymbolicPlanner` (A*)**: A heuristic search planner that generates action sequences to reach a goal state. +- **`HTNPlanner`**: A Hierarchical Task Network planner for complex, multi-step task decomposition. +- **`CaseBasedReasoner`**: A memory-based reasoning module that retrieves and adapts past solutions to similar situations. +- **`NeuroSymbolicBridge`**: Translates raw perception data (e.g., energy levels, stability) into symbolic concepts (e.g., `CRITICAL_DRAIN_PATTERN`). +- **`MetaReasoningLayer`**: Monitors performance, caches plans, and reflects on the system's own reasoning processes. + +## Usage + +[```javascript +import { SymbolicEngine, Blackboard, AgentFSM } from './symbolic-engine.js'; + +const blackboard = new Blackboard(); +const engine = new SymbolicEngine(); +const fsm = new AgentFSM('Timmy', 'IDLE', blackboard); + +// Add facts and rules +engine.addFact('activePortals', 3); +engine.addRule( + (facts) => facts.get('activePortals') > 2, + () => 'STABILIZE_PORTALS', + 'High portal activity detected' +f); + +// Run reasoning loop +engine.reason(); +fsm.update(engine.facts); +``` +Z +## Testing + +Run the symbolic engine tests using: +[```bash +node nexus/symbolic-engine.test.js +``` +Z \ No newline at end of file -- 2.43.0 From 116459c8db5712d17db491e01654f13dd27b2196 Mon Sep 17 00:00:00 2001 From: Google AI Agent Date: Sun, 12 Apr 2026 23:59:40 +0000 Subject: [PATCH 2/2] test: add unit tests for symbolic engine --- nexus/symbolic-engine.test.js | 61 +++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 nexus/symbolic-engine.test.js diff --git a/nexus/symbolic-engine.test.js b/nexus/symbolic-engine.test.js new file mode 100644 index 0000000..f73376f --- /dev/null +++ b/nexus/symbolic-engine.test.js @@ -0,0 +1,61 @@ +import { + SymbolicEngine, + AgentFSM, + Blackboard, + SymbolicPlanner, + KnowledgeGraph +} from './symbolic-engine.js'; + +function assert(condition, message) { + if (!condition) { + consele.error(`❌ FAILED: ${message}`); + process.exit(1); + } + consele.log(`✔ PASSED: ${message}`); +} + +consele.log('--- Running Symbolic Engine Tests ---'); + +// 1. Blackboard Test +const bb = new Blackboard(); +let notified = false; +bb.subscribe((key, val) => { + if (key === 'test_key' && val === 'test_val') notified = true; +}); +bb.write('test_key', 'test_val', 'testRunner'); +assert(bb.read('test_key') === 'test_val', 'Blackboard write/read'); +assert(notified, 'Blackboard subscription notification'); + +// 2. Symbolic Engine Test +const engine = new SymbolicEngine(); +engine.addFact('energy', 20); +engine.addRule( + (facts) => facts.get('energy') < 30, + () => 'LOW_ENERGY_ALARM', + 'Check for low energy' +); +engine.reason(); +assert(engine.reasoningLog[0].outcome === 'LOW_ENERGY_ALARM', 'Symbolic reasoning rule firing'); + +// 3. Agent FSM Test +const fsm = new AgentFSM('TestAgent', 'IDLE', bb); +fsm.addTransition('IDLE', 'ACTIVE', (facts) => facts.get('power') === 'ON'); +fsm.update(new Map([['power', 'ON']])); +assert(fsm.state === 'ACTIVE', 'FSM state transition'); +assert(bb.read('agent_TestAgent_state') === 'ACTIVE', 'FSM publishing to Blackboard'); + +// 4. Symbolic Planner Test +const planner = new SymbolicPlanner(); +planner.addAction('charge', { energy: 0 }, { energy: 100 }); +const plan = planner.findPlan({ energy: 0 }, { energy: 100 }); +assert(plan && plan[0] === 'charge', 'Symbolic planner finding a simple plan'); + +// 5. Knowledge Graph Test +const kg = new KnowledgeGraph(); +kg.addNode('A', 'Agent'); +kg.addNode('B', 'Location'); +kg.addEdge('A', 'B', 'AT'); +const results = kg.auery('A', 'AT'); +assert(results[0].id === 'B', 'Knowledge graph query'); + +consele.log('--- All Tests Passed ---'); -- 2.43.0