pyke
Use when building, reviewing, or debugging Pyke (Python Knowledge Engine, scitools-pyke) expert-system / logic-programming code — writing .krb/.kfb/.kqb source files, using the knowledge_engine.engine API, pattern matching, rules, plans, the special knowledge base, or question bases. Triggers on: "Pyke", "scitools-pyke", ".krb", ".kfb", ".kqb", "knowledge_engine", "backward chaining", "expert system", "forward chaining".
- License 许可
- Unlicense
- 最近更新
- 2026-10-28
- Stars
- ★ 4
- Forks
- 0
01 前言 Front Matter
- name
- pyke
- scope
- pyke
- description
- Use when building, reviewing, or debugging Pyke (Python Knowledge Engine, scitools-pyke) expert-system / logic-programming code — writing .krb/.kfb/.kqb source files, using the knowledge_engine.engine API, pattern matching, rules, plans, the special knowledge base, or question bases. Triggers on: "Pyke", "scitools-pyke", ".krb", ".kfb", ".kqb", "knowledge_engine", "backward chaining", "expert system", "forward chaining".
- source_basis
- official docs (pyke.sourceforge.net) + PyPI source tree
- last_verified
- 1786147200000
- target_versions
- Pyke 1.1.1
02 资源文件 11
- 参考文档evals/evals.json5.1 KB
- 参考文档evals/trigger-evals.json3.3 KB
- 参考文档references/api-engine.md3.1 KB
- 参考文档references/examples.md1.8 KB
- 参考文档references/facts-kb.md3.3 KB
- 参考文档references/pattern-matching.md2.7 KB
- 参考文档references/pyke-syntax.md2.8 KB
- 参考文档references/REFERENCE.md1.6 KB
- 参考文档references/rules-syntax.md5.8 KB
- 参考文档references/special-qbase.md2.7 KB
- 参考文档references/using-pyke.md2.6 KB
03 SKILL.md 正文
Pyke (Python Knowledge Engine) Reference
Use this skill for Pyke work. Pyke introduces logic programming (inspired by Prolog) to Python via a knowledge-based inference engine written in 100% Python. You write Python functions and Pyke rules that assemble them into customized call graphs ("plans") for specific use cases.
Read only the reference file(s) needed for the task.
Critical Gotchas
- Rule base activation runs forward-chaining rules —
engine.activate()fires all forward-chaining rules in the activated rule bases. Assert your facts before activating, or use universal facts /.kfbfiles loaded at engine creation. reset()erases case-specific facts and deactivates rule bases — callengine.reset()between cases, then re-assert facts and re-activate.- Goals are strings with
$pattern variables — e.g.family.how_related($p1, $p2, $rel). Pattern variables start with$. prove_1_goalreturns(vars, plan)—varsis a dict (without$) of pattern-variable bindings;planis a callable (orNone). Plans can be pickled.prove_goalreturns a context-manager generator — usewithand iterate to get all solutions. Raises no exception when there are no solutions.CanNotProveis raised only byprove_1_goal—prove_goalreturns an empty generator instead.IDENTIFIERin patterns is a literal — to use a variable, write$name.- Duplicate facts are silently ignored — a fact with the same name and arguments cannot be asserted twice.
assert_is case-specific — useadd_universal_factfor persistent facts, or put facts in.kfbfiles.engineconstructor scans recursively —.kfb/.krb/.kqbfiles are found anywhere under the search path; the knowledge-base name is the filename minus its suffix.
Routing
| File | Use for |
|---|---|
references/api-engine.md |
knowledge_engine.engine API, lifecycle, asserting facts, proving goals, tracing, stats |
references/rules-syntax.md |
.krb syntax: fc_rule, bc_rule, use/when/with/taking, plan_spec, first/forall/notany, compound premises, Python premises |
references/facts-kb.md |
facts, fact bases, knowledge bases, special KB, question bases |
references/pyke-syntax.md |
KFB/KRB/KQB source-file syntax, lexical rules, data types |
references/pattern-matching.md |
pattern syntax, pattern/anonymous/rest variables, matching semantics, context API |
references/using-pyke.md |
operational workflow: create engine, assert facts, activate, prove goals, plans, tracing, compiled goals |
references/special-qbase.md |
special.claim_goal/check_command/command/general_command, question-base details |
references/examples.md |
concrete examples mirroring the shipped examples/ |
references/REFERENCE.md |
cross-file routing (this is it) |
When NOT to Use This Skill
- Prolog itself — this skill is Pyke-specific (Python integration).
- Generic rule-engine libraries (e.g.
rules_engine,jsonrules) — only Pyke'sscitools-pykepackage. - Pyke 0.x / legacy 0.6 — the 1.1.1 API differs (e.g.
engineconstructor,prove_goal/prove_1_goal).
Output Expectations
- Name the source file(s) and knowledge-base name(s) used.
- State which rule base must be activated and in what order facts are asserted.
- If a plan is involved, explain how it is produced (
with/plan_spec/taking) and how it is called/pickled. - State the minimum verification: create an engine, activate, and run a
prove_1_goalsmoke test against a tiny.kfb/.krbpair.
04 同仓库更多 Skills
wizard
Generate an interactive bash wizard that walks a human through a manual procedure — third-party setup, credential provisioning, a one-off migration — opening URLs, capturing values, confirming each step, and writing .env files and CI secrets (GitHub and Gitea/Forgejo Actions).
restore-test-pyramid
Analyze the project's E2E suite and push every assertion that doesn't need a real browser down to a faster integration or unit test, proving each migration honest before thinning E2E.
ponytail-debt
Harvest SHORTCUT markers from the codebase and report them grouped by file, flagging any missing upgrade paths.
humanify
Repair an inherited or human-blocked ticket for agent implementation, or finish its explicit human-only outcome.
fix-pr
Repair an existing pull request's review findings and target-branch conflicts, verify the result, and update the same open PR.
feature-milestones
Reconstruct a fragmented backlog as finishable feature milestones with explicit delivery boundaries and an approval-gated tracker update.