Prolog 自省 + LLM 调用,驱动知识库自我进化。
自省 introspection ──→ LLM ──→ 解析 parse ──→ 验证 validate ──→ 采纳 adopt ──→ 保存 save
分析 KB 状态 生成新规则 Prolog 代码 格式/语义检查 assert 到 KB evolved.pl
config.pl DeepSeek API 配置(key / url / model)
engine/
load.pl 模块加载
runner.pl 入口(main / demo)
introspection.pl 自省:谓词统计、类别、缺口、依赖
llm_interface.pl DeepSeek API 调用
evolution.pl 进化循环 + 验证 + 持久化
knowledge/
base.pl 种子知识(59 个 Prolog 谓词 + LLM 领域知识)
evolved.pl 进化成果(自动生成,下次启动自动加载)
tests/
run_tests.pl TDD 测试套件(plunit)
test_introspection.pl 自省测试
test_evolution.pl 进化引擎测试
./test.sh # 运行 16 个 TDD 测试
./run.sh # 启动进化引擎(3 轮循环)
swipl -l engine/load.pl -g "runner:demo" -t halt # 查看 KB 状态- Prolog 语言:list / meta / introspection / dynamic_database / term / type / io / control 共 59 个核心谓词
- LLM:DeepSeek / OpenAI 模型、API 端点、能力描述
- 元规则:知识缺口检测、分类统计、进化前提
| 层 | 职责 |
|---|---|
knowledge/base.pl |
领域实体 + 值对象 + 聚合根 |
introspection.pl |
领域服务:自省分析 |
llm_interface.pl |
领域服务:外部 API 通信 |
evolution.pl |
领域服务:进化流程编排 + 仓储(持久化) |
- SWI-Prolog 9.0.4(推理引擎 + HTTP client + JSON)
- DeepSeek API(deepseek-v4-flash)
- 零外部依赖,纯 Prolog 实现