Axiomatization of graphs for RDFLib
Project description
rdflib-reasoning
rdflib-reasoning is the metapackage for a family of Python libraries used to study how tool-grounded Research Agents interact with RDF graphs and formal reasoning systems.
The source repository is organized as a multi-package workspace with supporting notebooks and development documentation.
The repository is organized around one practical research question:
When do tool-grounded Research Agent harnesses outperform direct prompting on multi-step formal reasoning tasks that require external knowledge retrieval, knowledge-base updates, and verifiable inference?
Reviewer Guide
If you are reviewing this repository quickly, start here:
- Read this file for the repository layout and install paths.
- Read docs/dev/architecture.md for the current technical direction.
- Inspect rdflib-reasoning-engine for the reasoning core.
- Inspect rdflib-reasoning-middleware for Research Agent integration.
- Inspect notebooks for the research surface and experiments.
Repository Roles
This repository distinguishes between two agent types. Canonical definitions are in AGENTS.md.
- Research Agent: The deployed or runtime agent that is the subject of research. It sees middleware, tools, system prompts, and generated schema; it does not see the repository or design documentation.
- Development Agent: The code agent that reads repository documentation, modifies code and docs, and develops code for the Research Agent.
Repository Layout
| Path | Purpose |
|---|---|
| notebooks | Analysis notebooks and research experiments |
| rdflib-reasoning-axioms | Graph axiomatization primitives |
| rdflib-reasoning-engine | RETE-based RDFS and OWL 2 RL entailment |
| rdflib-reasoning-middleware | Middleware and Research Agent-facing data interchange |
| docs/dev | Architecture notes, decision records, and development guidance |
| docs/specs | Cached specifications optimized for development work |
API and developer documentation can be generated locally with make docs and served from the
generated HTML output with make docs-serve.
Quickstart
If you want to see the repository's RDFS inference capabilities quickly, start with these checked-in notebooks:
- notebooks/demo-rdfs-inference.ipynb: shortest end-to-end walkthrough of RDFLib-backed RDFS materialization plus a proof view showing which rule applications justify one inferred triple
- notebooks/demo-rdfs-retraction.ipynb: update-aware companion showing that ordinary statement removal retracts dependent RDFS inferences
- notebooks/demo-contradiction-rules.ipynb: OWL 2 RL contradiction diagnostics when contradiction rules are included in the active ruleset
- notebooks/demo-proof-reconstructor.ipynb: proof-focused companion notebook covering Mermaid rendering, markdown rendering, and raw
DirectProofinspection - notebooks/README.md: notebook index with suggested reading order for demos and experiments
If you prefer a minimal code-first example before opening a notebook, the basic RDFS inference path looks like this:
from rdflib import Dataset, Namespace
from rdflib.namespace import RDF, RDFS
from rdflib.plugins.stores.memory import Memory
from rdflib_reasoning.engine import PRODUCTION_RDFS_RULES, RETEEngineFactory
from rdflib_reasoning.engine.rete_store import RETEStore
EX = Namespace("urn:example:")
store = RETEStore(Memory(), RETEEngineFactory(rules=PRODUCTION_RDFS_RULES))
dataset = Dataset(store=store)
graph = dataset.default_graph
alice = EX.alice
person = EX.Person
mammal = EX.Mammal
animal = EX.Animal
graph.add((alice, RDF.type, person))
graph.add((person, RDFS.subClassOf, mammal))
graph.add((mammal, RDFS.subClassOf, animal))
assert (alice, RDF.type, animal) in graph
Because the reasoning store is wired through ordinary RDFLib graph events, statement
retraction uses the normal graph.remove(...) API:
graph.remove((alice, RDF.type, person))
assert (alice, RDF.type, animal) not in graph
Contradiction detection is also available through the same engine path: include the
appropriate contradiction rules in RETEEngineFactory(rules=...), and the default
recorder records the diagnostic before raising ContradictionDetectedError. The
contradiction notebook shows how to choose recorder policy and inspect the resulting
records.
Component Overview
Research on agents takes place in Analysis Notebooks, uses the LangChain ecosystem, and depends on packages defined in this repository. Those packages build on RDFLib for semantic-web support and on Pydantic for Research Agent-friendly schemas.
---
config:
theme: 'base'
---
block-beta
columns 3
Notebooks("Analysis Notebooks"):3
Deepagents:1 ReasoningMiddleware["rdflib-reasoning-middleware"]:2
LangGraph:2
block:RdflibAbstraction:1
columns 1
Reasoning["rdflib-reasoning-engine"]:1
Axioms["rdflib-reasoning-axioms"]:1
end
LangChain:2 RDFLib:1
%% Agent Note: The remainder of this block is styling for humans and can be ignored
classDef Research fill:#fdb462,stroke:black
class Notebooks Research
classDef LangChainEcosystem fill:#80b1d3,stroke:blue
class Deepagents,LangGraph,LangChain LangChainEcosystem
classDef SupportingPackage fill:#b3de69,stroke:black
class ReasoningMiddleware,Reasoning,Axioms SupportingPackage
classDef SemanticWeb fill:#ccebc5,stroke:darkgreen
class RDFLib SemanticWeb
Installation
Use the Published Packages
If you want to use the packaged system from another project, install the published metapackage:
pip install rdflib-reasoning
That install pulls in the repository's published component packages:
rdflib-reasoningrdflib-reasoning-axiomsrdflib-reasoning-enginerdflib-reasoning-middleware
If you only need part of the system, you can also install the component packages directly from PyPI.
Work on This Repository Locally
Clone the repository and install the local workspace in editable mode:
pip install -e .
Add developer tooling:
pip install -e .[dev]
Add notebook and research dependencies:
pip install -e .[research]
Install the full local workspace:
pip install -e .[dev,research]
If you use uv, the equivalent commands are:
uv sync
uv sync --extra dev
uv sync --extra research
uv sync --extra dev --extra research
The root Makefile wraps those commands with install, install-dev, install-research, install-all, and notebook.
Add or Review Research Notebooks
If you want to contribute notebooks to this repository, or inspect the notebooks that already exist, install the repository locally with the research extra and work from the notebooks directory. The notebooks are part of the repository's research record rather than a separate published package.
For the current demo/tutorial entry points, see notebooks/README.md.
Develop Against These Packages Elsewhere
If you are building another system on top of this work, the usual path is:
- Install the published packages from PyPI in your own project.
- Read docs/dev/architecture.md for the intended package boundaries.
- Use the monorepo checkout only when you need to modify package code, contribute notebooks, or inspect unpublished changes.
Why This Repository Exists
RDFLib does not by itself provide a clean path for graph axiomatization, Research Agent-oriented schema exposure, and inspectable reasoning workflows. This repository packages those concerns into reusable libraries and research notebooks so that formal-logic experiments with agents are easier to build, evaluate, and explain.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rdflib_reasoning-0.4.0.tar.gz.
File metadata
- Download URL: rdflib_reasoning-0.4.0.tar.gz
- Upload date:
- Size: 595.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca4d940aa4d23213b8522d311be2f53ceaa8bfe1e0000c9e8b113a1bb6c6f23c
|
|
| MD5 |
aaea70d16acebee521a48410868d283a
|
|
| BLAKE2b-256 |
d43069eddd41224af6887f6479556ffdcc619ff5c8666c86809c809883fb46d6
|
Provenance
The following attestation bundles were made for rdflib_reasoning-0.4.0.tar.gz:
Publisher:
release.yml on kvjrhall/rdflib-reasoning
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rdflib_reasoning-0.4.0.tar.gz -
Subject digest:
ca4d940aa4d23213b8522d311be2f53ceaa8bfe1e0000c9e8b113a1bb6c6f23c - Sigstore transparency entry: 1413448810
- Sigstore integration time:
-
Permalink:
kvjrhall/rdflib-reasoning@64698ecbbe152dc96cfe606bf26372ccf8b2a7d5 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/kvjrhall
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@64698ecbbe152dc96cfe606bf26372ccf8b2a7d5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file rdflib_reasoning-0.4.0-py3-none-any.whl.
File metadata
- Download URL: rdflib_reasoning-0.4.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04f6dd70c6074aac557006e18b2bf783e26758391371446a1212a35fc50b7057
|
|
| MD5 |
b31d801b6f917e2a6b12ec09c15dc99a
|
|
| BLAKE2b-256 |
411eaf339896bc48b9b2eb177099b3b448a8cc3166f59515b08c89f444126f12
|
Provenance
The following attestation bundles were made for rdflib_reasoning-0.4.0-py3-none-any.whl:
Publisher:
release.yml on kvjrhall/rdflib-reasoning
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rdflib_reasoning-0.4.0-py3-none-any.whl -
Subject digest:
04f6dd70c6074aac557006e18b2bf783e26758391371446a1212a35fc50b7057 - Sigstore transparency entry: 1413448867
- Sigstore integration time:
-
Permalink:
kvjrhall/rdflib-reasoning@64698ecbbe152dc96cfe606bf26372ccf8b2a7d5 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/kvjrhall
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@64698ecbbe152dc96cfe606bf26372ccf8b2a7d5 -
Trigger Event:
release
-
Statement type: