Gaia Lang โ Python DSL for knowledge authoring, compilation, and inference
Project description
Gaia Lang
A Python DSL for authoring machine-readable scientific knowledge. Gaia Lang lets researchers declare propositions, logical constraints, and reasoning strategies as Python objects, then compiles them into a canonical intermediate representation (Gaia IR) for inference via belief propagation.
Quick Example
Galileo's thought experiment: tie a heavy stone ๐ชจ to a light stone ๐ชถ. Does the composite fall faster or slower?
from gaia.lang import claim, contradiction, deduction, abduction
# ๐ The observation everyone agrees on
obs_daily = claim("Heavy objects fall faster than light ones in air.")
# ๐๏ธ Two competing explanations
aristotle = claim("๐๏ธ Speed is proportional to weight โ heavier = faster.")
air_resistance = claim("๐ฌ๏ธ The speed difference is caused by air resistance, not weight.")
# ๐ Abduction: which explanation better accounts for the observation?
abduction(observation=obs_daily, hypothesis=air_resistance, alternative=aristotle,
reason="Both explain why heavy objects fall faster in air.")
# ๐ค Meanwhile, Aristotle's doctrine implies contradictory predictions
composite_slower = claim("๐ชจ๐ชถ The composite falls SLOWER than the heavy stone alone.")
composite_faster = claim("๐ชจ๐ชถ The composite falls FASTER than either stone alone.")
deduction(premises=[aristotle], conclusion=composite_slower,
reason="If heavier = faster, the light stone drags the heavy one back.")
deduction(premises=[aristotle], conclusion=composite_faster,
reason="If heavier = faster, the heavier composite must fall faster.")
# โ๏ธ Same premise, opposite conclusions โ that's a contradiction!
paradox = contradiction(composite_slower, composite_faster,
reason="Aristotle's own logic predicts both faster AND slower")
# ๐ก Remove the air, remove the difference
vacuum_law = claim("๐ก In vacuum, all bodies fall at the same rate.")
deduction(premises=[air_resistance], conclusion=vacuum_law,
reason="If air resistance is the sole cause, removing it means all fall equally.")
gaia compile . && gaia infer . compiles this into a factor graph and runs belief propagation:
graph TD
obs_daily["๐ Daily observation (0.90 โ 1.00 ๐)"]:::premise
aristotle["๐๏ธ Aristotle: heavier = faster (0.90 โ 0.07 ๐)"]:::premise
air_resistance["๐ฌ๏ธ Air resistance (0.50 โ 0.94 ๐)"]:::derived
composite_slower["๐ชจ๐ชถ < ๐ชจ Composite slower (0.60 โ 0.40 ๐)"]:::derived
composite_faster["๐ชจ๐ชถ > ๐ชจ Composite faster (0.60 โ 0.40 ๐)"]:::derived
paradox["โ๏ธ paradox (0.98)"]:::derived
vacuum_law["๐ก Vacuum law (0.30 โ 0.96 ๐)"]:::derived
strat_0(["๐ abduction"])
obs_daily --> strat_0
aristotle --> strat_0
strat_0 --> air_resistance
strat_1(["๐ง deduction"])
aristotle --> strat_1
strat_1 --> composite_slower
strat_2(["๐ง deduction"])
aristotle --> strat_2
strat_2 --> composite_faster
strat_3(["๐ง deduction"])
air_resistance --> strat_3
strat_3 --> vacuum_law
oper_0{{"โ contradiction"}}:::contra
composite_slower --- oper_0
composite_faster --- oper_0
oper_0 --- paradox
classDef setting fill:#f0f0f0,stroke:#999,color:#333
classDef premise fill:#ddeeff,stroke:#4488bb,color:#333
classDef derived fill:#ddffdd,stroke:#44bb44,color:#333
classDef contra fill:#ffebee,stroke:#c62828,color:#333
| Claim | Prior | โ | Belief | |
|---|---|---|---|---|
| ๐ Daily observation | 0.90 | โ | 1.00 | ๐ confirmed by both explanations |
| ๐๏ธ Aristotle's law | 0.90 | โ | 0.07 | ๐ contradiction propagates back โ refuted |
| ๐ฌ๏ธ Air resistance | 0.50 | โ | 0.94 | ๐ abduction: the better explanation wins |
| ๐ชจ๐ชถ Composite slower | 0.60 | โ | 0.40 | ๐ contradiction forces mutual exclusion |
| ๐ชจ๐ชถ Composite faster | 0.60 | โ | 0.40 | ๐ symmetric with composite slower |
| ๐ก Vacuum law | 0.30 | โ | 0.96 | ๐ Galileo wins โ remove air, all fall equally |
Note how the contradiction and abduction are independent subgraphs, yet BP automatically combines both lines of evidence: the contradiction refutes Aristotle (0.90 โ 0.07) while the abduction elevates air resistance (0.50 โ 0.94), and together they lift the vacuum law from a speculative 0.30 to a near-certain 0.96 โ no new experimental data needed, just the structure of the reasoning itself.
Install
pip install gaia-lang
For development:
git clone https://github.com/SiliconEinstein/Gaia.git
cd Gaia && uv sync
Claude Code Plugin
Gaia provides a Claude Code plugin with skills that guide the full knowledge formalization workflow โ from reading a paper to publishing a Gaia package on GitHub.
# 1. Add the Gaia marketplace (one-time setup)
/plugin marketplace add SiliconEinstein/Gaia
# 2. Install the gaia plugin
/plugin install gaia
Available skills:
| Skill | Purpose |
|---|---|
/gaia |
Entry point โ routes to the right skill based on your request |
/gaia:formalization |
Four-pass paper formalization: extract nodes โ connect strategies โ check completeness โ refine types |
/gaia:gaia-cli |
CLI reference โ gaia init, compile, infer, check, register, add |
/gaia:gaia-lang |
DSL reference โ knowledge types, operators, strategies, metadata, package structure |
/gaia:review |
Write review sidecars โ assign priors, judge strategies, parameterize inference |
/gaia:publish |
Generate GitHub presentation (--github skeleton โ narrative README โ push) |
Formalize a Paper End-to-End
With the plugin installed, formalizing a scientific paper into a Gaia knowledge package is a three-step process:
-
/gaia:formalizationโ Point Claude at your paper (PDF or text inartifacts/). The skill guides a four-pass process: extract knowledge nodes, connect reasoning strategies, check completeness, and refine strategy types. Output: a compilable Gaia package with review sidecar. -
/gaia:publishโ Aftergaia compile . --githubgenerates the skeleton, this skill fills in the narrative README, writes section summaries, and pushes to GitHub. Your repo gets a human-readable presentation of the formalized knowledge with interactive graphs. -
gaia registerโ Submit the package to the Gaia Official Registry so others cangaia addit as a dependency.
CLI Workflow
gaia init โ gaia add โ write package โ gaia compile โ write review โ gaia infer โ gaia compile --github โ /gaia:publish โ gaia register
(scaffold) (add deps) (DSL code) (DSL โ IR) (self-review) (BP preview) (GitHub skeleton) (fill narrative) (registry PR)
| Command | Purpose |
|---|---|
gaia init <name> |
Scaffold a new Gaia knowledge package |
gaia add <package> |
Install a registered Gaia package from the official registry |
gaia compile [path] |
Compile Python DSL to Gaia IR (.gaia/ir.json) |
gaia compile --github [path] |
Generate GitHub presentation skeleton (.github-output/): wiki, README, React Pages, graph.json |
gaia compile --module-graphs [path] |
Generate per-module detailed reasoning graphs to docs/detailed-reasoning.md |
gaia check [path] |
Validate package structure and IR consistency (used by registry CI) |
gaia infer [path] |
Run belief propagation with a review sidecar |
gaia register [path] |
Submit package to the Gaia Official Registry |
Create a Knowledge Package
1. Initialize
gaia init galileo-falling-bodies-gaia
cd galileo-falling-bodies-gaia
This scaffolds a complete package with pyproject.toml (including [tool.gaia]
config and a generated UUID), the correct src/ directory layout, and a DSL
template. Package name must end with -gaia.
2. Write DSL declarations
Organize your knowledge in separate modules under the package directory. gaia compile imports the top-level package, so any file transitively imported from __init__.py is automatically discovered.
src/galileo_falling_bodies/knowledge.py โ declare propositions:
from gaia.lang import claim
aristotle = claim("Aristotle's doctrine: the heavier an object is, the faster it falls.")
heavy_faster = claim("A heavy stone falls faster than a light one in air.")
composite_slower = claim("The composite should fall slower โ the light stone drags the heavy one back.")
composite_faster = claim("The composite should fall faster โ the combined weight is greater.")
vacuum_law = claim("In vacuum all bodies fall at the same rate.")
src/galileo_falling_bodies/reasoning.py โ declare constraints and strategies:
from gaia.lang import contradiction, deduction
from .knowledge import aristotle, composite_slower, composite_faster, heavy_faster, vacuum_law
deduction(premises=[aristotle], conclusion=composite_slower,
reason="If heavier = faster, then the light stone must slow down the heavy one.")
deduction(premises=[aristotle], conclusion=composite_faster,
reason="If heavier = faster, then the heavier composite must fall faster.")
paradox = contradiction(composite_slower, composite_faster,
reason="Same premise yields opposite conclusions")
galileo_argument = deduction(
premises=[paradox, heavy_faster],
conclusion=vacuum_law,
reason="Contradiction in Aristotle's doctrine forces a new law",
)
src/galileo_falling_bodies/__init__.py โ re-export all declarations:
from .knowledge import aristotle, heavy_faster, composite_slower, composite_faster, vacuum_law
from .reasoning import paradox, galileo_argument
__all__ = [
"aristotle", "heavy_faster", "composite_slower",
"composite_faster", "vacuum_law",
"paradox", "galileo_argument",
]
3. Compile and validate
gaia compile .
gaia check .
4. Write a review sidecar to assign priors and strategy parameters for inference.
Reviews live in src/galileo_falling_bodies/reviews/. Each review is a Python file exporting a REVIEW bundle โ different reviewers can assign different priors to the same knowledge.
src/galileo_falling_bodies/reviews/self_review.py:
from gaia.review import ReviewBundle, review_claim, review_strategy
from .. import aristotle, heavy_faster, galileo_argument
REVIEW = ReviewBundle(
source_id="self_review",
objects=[
review_claim(aristotle, prior=0.9,
judgment="supporting",
justification="Widely accepted for 2000 years, matches everyday experience."),
review_claim(heavy_faster, prior=0.8,
judgment="supporting",
justification="Well-documented observation in air."),
review_strategy(galileo_argument,
judgment="formalized",
justification="Classic reductio ad absurdum."),
],
)
5. Run belief propagation
gaia infer .
The engine compiles the IR into a factor graph, automatically selects the best algorithm (exact junction tree for small graphs, loopy BP for larger ones), and writes results to .gaia/reviews/self_review/:
Inferred 5 beliefs from 2 priors and 0 strategy parameter records
Method: JT (exact), 2ms
Review: self_review
Output: .gaia/reviews/self_review/beliefs.json
beliefs.json contains the posterior probability for each claim after propagation:
| Claim | Prior | โ | Posterior | |
|---|---|---|---|---|
aristotle |
0.90 | โ | 0.01 | โฌ๏ธ contradiction propagates back โ Aristotle refuted |
heavy_faster |
0.80 | โ | 0.67 | โฌ๏ธ pulled down by the deduction chain |
composite_slower |
โ | โ | 0.34 | โฌ๏ธ contradiction forces mutual exclusion |
composite_faster |
โ | โ | 0.34 | โฌ๏ธ symmetric with composite_slower |
vacuum_law |
โ | โ | 0.83 | โฌ๏ธ deduction from the contradiction raises belief |
If multiple reviews exist, specify which one: gaia infer --review self_review .
6. Generate GitHub presentation
gaia compile . --github
Generates a .github-output/ directory with:
- README.md skeleton with coarse Mermaid overview graph and conclusion table
- Wiki pages โ structured claim reference with QID, prior, belief, reasoning
- graph.json โ knowledge graph data for interactive visualization
- narrative-outline.md โ topologically ordered outline for the
/gaia:publishskill
Run gaia infer . first so the output includes up-to-date belief values. Then use /gaia:publish to fill in the narrative and push to GitHub.
7. Publish
git tag v1.0.0 && git push origin main --tags
gaia register . --registry-dir ../gaia-registry --create-pr
Install a Package
Add a registered Gaia knowledge package as a dependency:
gaia add galileo-falling-bodies-gaia
This queries the Gaia Official Registry
for the package metadata, resolves the latest version, and calls uv add with
a pinned git URL. Use --version to pin a specific version:
gaia add galileo-falling-bodies-gaia --version 1.0.0
DSL Surface
Knowledge
| Function | Description |
|---|---|
claim(content, *, given, background, parameters, provenance) |
Scientific assertion โ the only type carrying probability |
setting(content) |
Background context โ no probability, no BP participation |
question(content) |
Open research inquiry |
Operators (deterministic constraints)
| Function | Semantics |
|---|---|
contradiction(a, b) |
A and B cannot both be true |
equivalence(a, b) |
A and B share the same truth value |
complement(a, b) |
A and B have opposite truth values |
disjunction(*claims) |
At least one must be true |
Strategies (reasoning declarations)
| Function | Description |
|---|---|
noisy_and(premises, conclusion) |
All premises jointly support conclusion |
infer(premises, conclusion) |
General conditional probability table |
deduction(premises, conclusion) |
Deductive reasoning (conjunction โ implication) |
abduction(observation, hypothesis) |
Inference to best explanation |
analogy(source, target, bridge) |
Analogical transfer |
extrapolation(source, target, continuity) |
Continuity-based prediction |
elimination(exhaustiveness, excluded, survivor) |
Process of elimination |
case_analysis(exhaustiveness, cases, conclusion) |
Case-by-case reasoning |
mathematical_induction(base, step, conclusion) |
Inductive proof |
induction(observations, law) |
Multiple observations supporting a general law |
composite(premises, conclusion, sub_strategies) |
Hierarchical composition |
Architecture
gaia/
โโโ lang/ DSL runtime, declarations, and compiler
โโโ ir/ Gaia IR schema, validation, formalization
โโโ bp/ Belief propagation engine (4 backends)
โโโ cli/ CLI commands (init, compile, check, add, infer, register)
โโโ review/ Review sidecar model
Documentation
- DSL Reference
- Package Model
- Knowledge & Reasoning Semantics
- CLI Workflow
- Gaia IR Specification
- Registry Design
Testing
pytest
ruff check .
ruff format --check .
License
MIT
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 gaia_lang-0.2.6.tar.gz.
File metadata
- Download URL: gaia_lang-0.2.6.tar.gz
- Upload date:
- Size: 115.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
842e2bb1713d067a9b055cd8827eb926e3e1a329b2612e42f8a3467901f888d1
|
|
| MD5 |
6f9833d07a9355d4931dc55b2bac11ec
|
|
| BLAKE2b-256 |
7915100dc1e9725d33c26c2fd4f9dbb118002de10079379b9f7e31e3505c9377
|
Provenance
The following attestation bundles were made for gaia_lang-0.2.6.tar.gz:
Publisher:
publish.yml on SiliconEinstein/Gaia
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gaia_lang-0.2.6.tar.gz -
Subject digest:
842e2bb1713d067a9b055cd8827eb926e3e1a329b2612e42f8a3467901f888d1 - Sigstore transparency entry: 1246064581
- Sigstore integration time:
-
Permalink:
SiliconEinstein/Gaia@69b210d5f84c489adcddcee13a8e97c8eb63b9cf -
Branch / Tag:
refs/tags/v0.2.6 - Owner: https://github.com/SiliconEinstein
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@69b210d5f84c489adcddcee13a8e97c8eb63b9cf -
Trigger Event:
push
-
Statement type:
File details
Details for the file gaia_lang-0.2.6-py3-none-any.whl.
File metadata
- Download URL: gaia_lang-0.2.6-py3-none-any.whl
- Upload date:
- Size: 133.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efb14804db4e8446bb67d9d80eba309d0822b2041006ad63ddca3803f927bf8c
|
|
| MD5 |
3bdaf778452df08b6da96471c5c32c96
|
|
| BLAKE2b-256 |
08d34371dddc63176c411fcbc2d5af5c02702423c5340b79e331f655d5a4af25
|
Provenance
The following attestation bundles were made for gaia_lang-0.2.6-py3-none-any.whl:
Publisher:
publish.yml on SiliconEinstein/Gaia
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gaia_lang-0.2.6-py3-none-any.whl -
Subject digest:
efb14804db4e8446bb67d9d80eba309d0822b2041006ad63ddca3803f927bf8c - Sigstore transparency entry: 1246064627
- Sigstore integration time:
-
Permalink:
SiliconEinstein/Gaia@69b210d5f84c489adcddcee13a8e97c8eb63b9cf -
Branch / Tag:
refs/tags/v0.2.6 - Owner: https://github.com/SiliconEinstein
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@69b210d5f84c489adcddcee13a8e97c8eb63b9cf -
Trigger Event:
push
-
Statement type: