Beliefs
Beliefs are tracked knowledge with confidence scores. They are not just variables -- the language records them in a knowledge graph.
belief weather = "sunny" confidence 0.8
belief temperature = "warm" confidence 0.7
belief sky = "clear" confidence 0.9 evidence "visual observation"
Confidence ranges from 0.0 to 1.0. The optional evidence field records provenance.
Beliefs also create variables in scope, so weather is usable as a normal variable:
belief score = 85 confidence 0.9
print(score) # 85
Observations
Record new data and create nodes in the knowledge graph:
observe "thermometer reads 35C"
observe {source: "weather_api", temp: 35, humidity: 80} as weather_data
print(weather_data.temp) # 35
Use as name to bind the observation to a variable.
Revising Beliefs
Update beliefs based on accumulated evidence:
revise weather = "cloudy" confidence 0.6
revise temperature confidence 0.9 # update confidence only
revise sky = "overcast" evidence "radar data" # update value and evidence
Causal Operators
NSL has four causal operators that build queryable cause-effect relationships:
"deforestation" causes "soil erosion"
"soil erosion" causes "flooding"
"flooding" causes "property damage"
"exercise" because "health benefits"
"alarm" triggers "wake up"
"training" leads_to "skill improvement"
Each statement creates two Causal nodes and a typed edge in the knowledge graph.
Knowledge Graph
Every cognitive statement auto-populates a knowledge graph with 15 node types and 17 edge types.
Querying
# All beliefs with confidence > 0.5
let strong_beliefs = kg.beliefs(0.5)
for each b in strong_beliefs
print(f"{b.name}: {b.value} (conf: {b.confidence})")
# Find a specific node
let node = kg.find("weather")
print(node.confidence)
# Causal chains
let start = kg.find("deforestation")
let effects = kg.effects(start.id)
print(effects)
# Shortest path between nodes
let path = kg.path(kg.find("deforestation").id, kg.find("property damage").id)
print(path)
# Graph statistics
let stats = kg.stats()
print(f"Nodes: {stats.nodes}, Edges: {stats.edges}")
Node Types
Belief, Fact, Goal, Intent, Constraint, Observation, Episode, Entity, Causal, Temporal, Hypothesis, Skill, Capability, Pursuit, Invariant
Edge Types
Causes, Because, Triggers, LeadsTo, Requires, Satisfies, Contradicts, Supports, Contains, DependsOn, Before, After, During, Achieves, Pursues, Monitors, Produces
Monitors
Watch knowledge graph nodes and react to violations:
belief altitude = 150 confidence 0.9
# Safety monitor -- throws immediately if violated
monitor alt_check safety altitude where value > 100 "Altitude too low!"
# Hard monitor -- throws on kg.check_monitors()
monitor temp_check hard temperature where confidence > 0.5 "Temperature uncertain"
# Soft monitor -- returns warnings
monitor quality_check soft data_quality where value > 0.7 "Quality degraded"
# Check monitors
kg.check_monitors() # throws if any hard/safety violated
let warnings = kg.check_soft() # returns list of warning strings
The checker expression has value, confidence, evidence, and name in scope from the watched node.
Goals and Intentions
goal reduce_emissions
observe "solar panels installed"
belief carbon = "decreasing" confidence 0.7
revise carbon confidence 0.9
intent improve_efficiency
observe "new algorithm deployed"
revise processing_time = "fast" confidence 0.8
Goals and intents wrap their body in a knowledge graph episode.
Hypotheticals
Execute code conditionally and register hypothesis nodes:
assuming temperature > 40
print("Heat wave protocol activated")
belief risk = "high" confidence 0.9
were budget > 1000000
print("Expansion possible")
otherwise_actual
print("Stay conservative")
suppose market_stable
belief investment = "recommended" confidence 0.7
Constraints and Invariants
# Define a constraint
constraint min_altitude(alt) = alt > 100
# Use it
print(min_altitude(150)) # true
print(120 satisfies min_altitude) # true
# Require (throws on failure)
require altitude > 0 else "Altitude must be positive"
# Invariant (enforced in scope)
invariant safe_range: temperature > -40 and temperature < 60
# code here runs with the invariant enforced
Negation and Prevention
undo last_action
prevent dangerous_operation
revoke admin_access
forbid unsafe_mode
Temporal Blocks
after initialization
print("System started")
before shutdown
print("Saving state...")
during operation
monitor_health()
Temporal blocks register nodes in the knowledge graph, queryable with kg.query("temporal").
Crystallize
Extract learned patterns from accumulated experience:
crystallize "weather_prediction" where confidence > 0.8
Creates a Skill node in the knowledge graph from recorded episodes.
Capabilities
Set and check permissions in a capability sandbox:
capability file_write = true "Needs to save data"
capability network = false "Offline mode"
if kg.capability("file_write")
file.write("output.txt", data)
