PyAgentProlog
A Prolog engine in Python with proof tracing, agents based on Python actions, an expert system, and semantic unification on embeddings.
Author
Andrey Vorfolomeev
Features
- Prolog core: parser, iterative solver with TCO (tail-call optimization),
cut (
!),if-then-else, rule indexing by the first argument. - Proof tracing — an inference tree with unifications and rules.
- Numba-accelerated arithmetic — a non-recursive stack machine, runs on ARM/Raspberry Pi.
- Agents — Python functions as built-in predicates (
@simple_action,@effector_action,@generator_action). - Expert system — interactive mode, extraction of conditions from natural language
via
pymorphy3, contradiction resolution, glossary. - Semantic unification — matching atoms via embeddings (Ollama or sentence-transformers).
- Integration with LangChain —
PrologChainasRunnablein LCEL chains. - Gradio sessions — for interactive UIs.
Installation
Basic (core only)
pip install pyagentprolog
With additional features
# Numba acceleration for arithmetic
pip install pyagentprolog[numba]
# Semantic unification
pip install pyagentprolog[embeddings]
# LangChain
pip install pyagentprolog[langchain]
# Expert system (pymorphy2)
pip install pyagentprolog[expert]
# Everything at once
pip install pyagentprolog[all]
Quick start
Simple query
from prolog import Solver
program = """
parent(ivan, alexey).
parent(alexey, petr).
grandfather(D, V) :-
parent(D, R),
parent(R, V).
"""
solver = Solver(program)
solutions = solver.find_solutions("grandfather(ivan, X).")
print(solutions) # [{'X': 'petr'}]
Proof trace
solutions, explanation = solver.find_solutions("grandfather(ivan, X).",
with_explanation=True)
print(solver.get_explanation())
Agent with Python actions
from prolog import Agent, simple_action
@simple_action('add', 3, output_arg=2)
def add(a, b, context=None):
return a + b
agent = Agent(program="run(X) :- add(2, 3, X).")
agent.register_action(add)
print(agent.query_one("run(X).")) # {'X': 5}
### Expert System
Requires pyagentprolog[expert]
```python
from prolog import Expert
expert = Expert(domain_file="knowledge.pl", use_pymorphy=True)
answer = expert.ask("I want to learn programming")
print(answer)
Requirements
- Python 3.9+
- Mandatory:
numpy - Optional:
numba,langchain-core,sentence-transformers,langchain-ollama,gradio,pymorphy2
License
MIT — see the LICENSE file.
Metadata
Release files for pyagentprolog 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyagentprolog-1.0.1.tar.gz | 86.3 kB | Without provenance | Details for pyagentprolog-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyagentprolog-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for pyagentprolog-1.0.1-py3-none-any.whl |
Total release size: 154.2 kB
Release files / pyagentprolog-1.0.1.tar.gz
| Download URL | pyagentprolog-1.0.1.tar.gz |
|---|---|
| Size | 86.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a01855997daa5bc8aa9578257eae24f90fe4bde8bffb2d191481ab1fccc96b73
|
|
BLAKE2b-256 checksum How to use checksums |
dd6772014a0aac826a3e71de9159c684f5f2fb5cb99218600f5e69d5094f3904
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / pyagentprolog-1.0.1-py3-none-any.whl
| Download URL | pyagentprolog-1.0.1-py3-none-any.whl |
|---|---|
| Size | 67.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d22624641a4df0850f1afb61b8d7742b73a75aa186b6cd2dce82b4fefbcf383d
|
|
BLAKE2b-256 checksum How to use checksums |
d2a83a22af7753e1772865179dcd7a8659e0824127a85112517040e11890a08f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for pyagentprolog 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.