PAIRL — compact, lossless agent-to-agent message protocol. Python parser, validator (V1–V12), canonicalizer/hasher, and renderer.
Project description
pairl (Python)
Reference implementation of PAIRL — a compact, human-readable, machine-parseable message format for agent-to-agent communication. This package parses PAIRL, validates it (rules V1–V12), canonicalizes and SHA-256–hashes it, and renders it back to human-readable text. Pure standard library, no runtime dependencies.
Why PAIRL?
Agents exchanging context in natural language burn tokens and let facts drift; raw JSON is rigid and verbose. PAIRL separates a lossy intent channel (tone, length, speech act) from a lossless fact channel (names, numbers, evidence) and references large content instead of copying it.
| Natural language | JSON | PAIRL | |
|---|---|---|---|
| Token cost | high | medium–high | low (≈40–90% less) |
| Facts preserved losslessly | ✗ (drift) | ✓ | ✓ (dedicated channel) |
| Tone/intent without verbosity | verbose | ✗ | ✓ (compact intents) |
| Validatable on the wire | ✗ | schema | ✓ (V1–V12) |
| Speaker/turn attribution in one body | ✗ | manual | ✓ (turn markers) |
| Repeated records compacted | ✗ | ✗ | ✓ (columnar blocks) |
| Content-addressable (stable hash) | ✗ | canonical JSON | ✓ (§9 + SHA-256) |
| Human-renderable | ✓ | poor | ✓ (renderer) |
Protocol architecture
A PAIRL message is a header block (@v, @id, @ts, threading, budget, …)
followed by a blank line and body records:
- Intents —
req{t=topic,s=f,l=2}— the lossy channel: speech act + style. - Lossless records —
#fact,#ref,#evid,#rule— exact data, treated as ground truth (never paraphrased). - Economic records —
#cost,#quota— native budget/usage tracking. - Tool records —
#call,#ret,#think,#edit— compact tool-use chains. - Turn markers (v1.3) —
#u1/#a2— attribute records to a speaker when a whole conversation is compressed into one body. - Columnar blocks (v1.5) —
#evid[claim,src,conf]+ positional rows — declare a repeated key schema once instead of per record (~40% fewer tokens, lossless).
Canonicalization & hashing (§9). Columnar blocks expand to #type key=value
records before hashing, so a message produces the same SHA-256 whether sent in
columnar or key=value form — enabling content-addressing, dedup, and caching.
Install
pip install pairl
Library
import pairl
msg = pairl.parse(open("message.pairl").read())
res = pairl.validate(msg) # rules V1–V12
print(res.valid, res.errors, res.warnings)
print(pairl.compute_hash(msg)) # canonical SHA-256 (columnar-invariant)
print(pairl.render(msg)) # faithful human-readable rendering
CLI
python -m pairl validate [--strict] message.pairl # exit 0 ok / 1 invalid
python -m pairl render message.pairl
python -m pairl hash message.pairl
python -m pairl canon message.pairl
Test
cd impl/python && python -m unittest discover -s tests
Links
- Specification: https://github.com/dwehrmann/PAIRL/blob/main/SPEC.md
- Repository & other implementations (TypeScript, Rust) + shared conformance corpus: https://github.com/dwehrmann/PAIRL/tree/main/impl
- Website: https://pairl.dev
Licensed under Apache-2.0.
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 pairl-1.5.2.tar.gz.
File metadata
- Download URL: pairl-1.5.2.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b717c99d56f11a07cde00cc59fcfd83e0916542becf66f2712782c38000f057a
|
|
| MD5 |
bb07ba661d98211248c0debc420b5602
|
|
| BLAKE2b-256 |
b771101147d205eb355d155b83419cec1da01521dc5253dabf4be2cec45207bc
|
Provenance
The following attestation bundles were made for pairl-1.5.2.tar.gz:
Publisher:
release.yml on dwehrmann/PAIRL
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pairl-1.5.2.tar.gz -
Subject digest:
b717c99d56f11a07cde00cc59fcfd83e0916542becf66f2712782c38000f057a - Sigstore transparency entry: 1931485326
- Sigstore integration time:
-
Permalink:
dwehrmann/PAIRL@5460a272a620080a2696cb30bae4daaec713d11e -
Branch / Tag:
refs/tags/v1.5.2 - Owner: https://github.com/dwehrmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5460a272a620080a2696cb30bae4daaec713d11e -
Trigger Event:
push
-
Statement type:
File details
Details for the file pairl-1.5.2-py3-none-any.whl.
File metadata
- Download URL: pairl-1.5.2-py3-none-any.whl
- Upload date:
- Size: 16.7 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 |
e78395909bfdd32e5a8e67310f3be9534c914ac69d1548651999ae625b2dfd2c
|
|
| MD5 |
5d49db151229e0629f1036ae7d0815ce
|
|
| BLAKE2b-256 |
acec63462abc43a9e8d2e1c604aea22c45c285cc12f975fd3d6920b17ca5a564
|
Provenance
The following attestation bundles were made for pairl-1.5.2-py3-none-any.whl:
Publisher:
release.yml on dwehrmann/PAIRL
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pairl-1.5.2-py3-none-any.whl -
Subject digest:
e78395909bfdd32e5a8e67310f3be9534c914ac69d1548651999ae625b2dfd2c - Sigstore transparency entry: 1931485476
- Sigstore integration time:
-
Permalink:
dwehrmann/PAIRL@5460a272a620080a2696cb30bae4daaec713d11e -
Branch / Tag:
refs/tags/v1.5.2 - Owner: https://github.com/dwehrmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5460a272a620080a2696cb30bae4daaec713d11e -
Trigger Event:
push
-
Statement type: