Overview
Prolog-World is an open-source project (github.com/coder-brzhang/prolog-world) that engineers Daniel Kahneman's dual-process theory into an AI agent: the LLM is System 1 (fast intuition), while a Prolog engine, knowledge graph, and HTN planner form System 2 (slow, verifiable reasoning).
The problem
LLMs answer logical questions (e.g., the Socrates syllogism) correctly by statistical intuition, but cannot reliably produce formal proofs, and their correctness is non-deterministic. Prolog-World's answer: let the LLM orchestrate, but delegate reasoning itself to symbolic engines.
Architecture
| Module | Role | Capability | |---|---|---| | LLM | System 1 | Language understanding, tool orchestration | | Prolog engine | System 2 | Deterministic logical inference | | Knowledge graph (KG) | System 2 | Structured knowledge storage/query | | HTN planner | System 2 | CLP(FD)-constrained task decomposition | | Vector memory | Bridge | Semantic retrieval | | External world | Extension | Files, bash, web search |
The five engines
1. Prolog inference — a full SWI-Prolog instance via swipl-wasm in Node.js. Facts are loaded with prolog_consult; queries with prolog_query return deterministic proofs, not probabilities. Supports transitive closure and classification rules.
2. Knowledge graph — RDF triple store based on N3.js. Every graph_add automatically syncs into Prolog via assertz(kg_triple(S, P, O)), so both systems share one knowledge base; a graph_bridge.pl provides higher-order predicates (transitive closure, symmetric relations, path finding).
3. HTN planner — hierarchical task network planning with CLP(FD) constraints: steps carry durations and resource requirements, dependencies are encoded, and labeling([min(Makespan)], Starts) finds the provably optimal schedule.
4. Vector memory — hnswlib-node index with 768-dim embeddings from local Ollama (nomic-embed-text). Graceful degradation: if Ollama is unavailable, it falls back to keyword retrieval instead of crashing.
5. World tools — 8 tools (file_read/write/edit/glob/grep, bash, web_search, web_fetch). file_edit requires a unique old_string, erroring on zero or multiple matches to prevent wrong replacements.
Example scenario
A user teaches the agent that the EU Carbon Border Adjustment Mechanism (CBAM) covers steel, aluminum, cement, fertilizer, electricity, and hydrogen. The agent stores triples (graph_add(eu_cbam, covers, steel)), loads Prolog rules, and saves a memory. Asked whether an aluminum producer needs to care about CBAM, it runs semantic memory search, a graph lookup, and a Prolog query — covers(eu_cbam, aluminum) — returning a deterministic Yes.
Why not a pure LLM?
- Reliability: identical premises yield identical conclusions — needed where 99% is not enough (legal, medical, financial).
- Verifiability: every inference step can be traced and audited.
- Composability: accumulated facts keep answering composite questions even when an LLM's context window would run out.
- https://github.com/coder-brzhang/prolog-world
- Kahneman, D. (2011). *Thinking, Fast and Slow*.
- https://www.swi-prolog.org/
- https://github.com/rdfjs/N3.js
- https://github.com/nmslib/hnswlib
Tech choices
SWI-Prolog WASM (industrial Prolog, no external process), N3.js (RDF/Turtle, SPARQL-style queries), hnswlib-node (millisecond retrieval over millions of vectors), native CLP(FD) over external OR-Tools, DuckDuckGo HTML search (no API key), Zod + JSON Schema (auto-generating OpenAI function-calling formats).
18 tools
Symbolic reasoning (prolog_query/consult/list_rules), structured knowledge (graph_add/lookup/remove), semantic memory (memory_store/search/list), planning (plan_create), file system (5 tools), and bash/web access — everything runs locally after npm install.
Conclusion
Prolog-World demonstrates that LLM + symbolic reasoning is an engineering reality, not an academic fantasy. System 1 understands the world, System 2 verifies the reasoning, memory connects them — all locally, no black boxes, because "reasoning doesn't need faith, it needs proof."
References