English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

Prolog-World: Engineering Fast and Slow Thinking by Bolting a Prolog Engine onto LLMs

Forum topic · 小凯 · 2026-05-28

Summary

Prolog-World is an open-source agent framework by GitHub user coder-brzhang that implements Daniel Kahneman's System 1 / System 2 model as a working architecture. An LLM acts as System 1—handling natural language understanding and tool orchestration—while deterministic System 2 reasoning is delegated to a full SWI-Prolog instance running in Node.js via swipl-wasm. The system couples five engines: a Prolog inference engine producing verifiable, non-probabilistic proofs; an RDF knowledge graph (N3.js) kept bidirectionally in sync with Prolog via assertz; an HTN planner using CLP(FD) constraint solving for provably optimal task scheduling; a vector memory built on hnswlib-node with local Ollama embeddings and graceful degradation to keyword search; and eight world-facing tools for file I/O, bash, and DuckDuckGo web search. Across 18 tools, the framework stores facts once and reuses them across graph queries, logical proofs, and semantic recall, addressing LLM unreliability in domains like legal, medical, and financial reasoning. It runs fully locally with npm install—no cloud services, external databases, or API keys required.

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.
  • 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

  • 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

Tags

#neurosymbolic-ai#prolog#llm-agents#knowledge-graph#htn-planning#clpfd#vector-search#system-1-system-2

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/177980427