What you'll learn: This tutorial walks you through installing AGISystem2, creating your first reasoning session, adding facts, and querying the knowledge base. By the end, you'll understand the basic workflow for symbolic reasoning.

Prerequisites

Step 1: Installation

1 Clone and install dependencies
# Clone the repository
git clone https://github.com/OutfinityResearch/AGISystem2.git
cd AGISystem2

# Install dependencies
npm install

# Verify installation
npm run eval
Running 364 tests across 27 suites...
Configuration: metric(32)+symb
Pass Rate: 100% (364/364)
Time: 318ms

Step 2: Your First Session

2 Create a reasoning session

Create a file called tutorial.mjs:

import { Session } from './src/session.mjs';

// Create a new reasoning session
const session = new Session();

// Add some facts about animals
session.learn('isA Tom Cat');
session.learn('isA Cat Mammal');
session.learn('isA Mammal Animal');

// Query: Is Tom an animal?
const result = session.query('isA Tom Animal');

console.log('Is Tom an animal?', result.success);
// Output: Is Tom an animal? true

console.log('Proof:', result.proof);
// Output: Proof steps showing the transitive chain
# Run it
node tutorial.mjs
What happened? AGISystem2 automatically inferred that Tom is an Animal by following the transitive chain: Tom → Cat → Mammal → Animal.

Step 3: Adding Rules

3 Define inference rules
import { Session } from './src/session.mjs';

const session = new Session();

// Define a rule: All mammals are warm-blooded
session.learn('@ant isA ?x Mammal');
session.learn('@cons hasProperty ?x warm_blooded');
session.learn('Implies $ant $cons');

// Add facts
session.learn('isA Dog Mammal');
session.learn('isA Fido Dog');

// Query: Is Fido warm-blooded?
const result = session.query('hasProperty Fido warm_blooded');

console.log('Is Fido warm-blooded?', result.success);
// Output: Is Fido warm-blooded? true

Step 4: Using Natural Language

4 Translate natural language to DSL
import { Session } from './src/session.mjs';
import { translateContextWithGrammar } from './src/nlp/nl2dsl/grammar.mjs';

// Natural language context
const text = `
  All cats are mammals.
  All mammals are animals.
  Tom is a cat.
  Jerry is a mouse.
  Mice are animals.
`;

// Translate to DSL
const { dsl, errors } = translateContextWithGrammar(text, {
  autoDeclareUnknownOperators: true
});

console.log('Generated DSL:');
console.log(dsl);

// Load into session
const session = new Session();
for (const line of dsl.split('\n')) {
  if (line.trim()) session.learn(line);
}

// Query
console.log('Is Tom an animal?', session.query('isA Tom Animal').success);
console.log('Is Jerry an animal?', session.query('isA Jerry Animal').success);

Step 5: Choosing HDC Strategy

5 Configure HDC geometry

AGISystem2 supports five HDC strategies. Set via environment variables:

# Metric-Affine (fastest, recommended)
SYS2_HDC_STRATEGY=metric-affine SYS2_GEOMETRY=32 node tutorial.mjs

# Metric-Affine Elastic (large KBs)
SYS2_HDC_STRATEGY=metric-affine-elastic SYS2_GEOMETRY=32 node tutorial.mjs

# Dense-Binary (standard VSA)
SYS2_HDC_STRATEGY=dense-binary SYS2_GEOMETRY=256 node tutorial.mjs

# Sparse-Polynomial (memory efficient)
SYS2_HDC_STRATEGY=sparse-polynomial SYS2_GEOMETRY=4 node tutorial.mjs

# EXACT (lossless, session-local atom IDs)
SYS2_HDC_STRATEGY=exact SYS2_GEOMETRY=256 node tutorial.mjs
Strategy Best For Speed
metric-affine Production, fastest performance 318ms (2.6x faster)
metric-affine-elastic Large KBs, stable bundling Similar to metric-affine
dense-binary Standard HDC, similarity search 456ms
sparse-polynomial Memory-constrained environments 349ms (k=2)
exact Lossless experiments, saturation studies Varies (BigInt/KB dependent)

Step 6: Running Tests

6 Verify everything works
# Run core theory tests (364 tests, 27 suites)
npm run eval

# Run with all 16 configurations (includes EMA)
npm run eval -- --full

# Run stress tests
node evals/runStressCheck.js

# Run external benchmarks
node autoDiscovery/bugsAutoDiscovery.mjs --source=prontoqa --batch=20

Quick Reference: DSL Syntax

DSL Statement Meaning
isA Tom Cat Tom is a Cat
hasProperty Ball red Ball has property red
loves John Mary John loves Mary
@ref isA ?x Cat Named reference with variable
Implies $ant $cons If $ant then $cons
Not (isA Tom Dog) Tom is not a Dog
And $a $b $c Conjunction of conditions

Next Steps