Skip to main content

PAIRL — compact, lossless agent-to-agent message protocol. Python parser, validator (V1–V12), canonicalizer/hasher, and renderer.

Project description

pairl (Python)

PyPI Python License

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:

  • Intentsreq{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

Licensed under Apache-2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pairl-1.5.2.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pairl-1.5.2-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

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

Hashes for pairl-1.5.2.tar.gz
Algorithm Hash digest
SHA256 b717c99d56f11a07cde00cc59fcfd83e0916542becf66f2712782c38000f057a
MD5 bb07ba661d98211248c0debc420b5602
BLAKE2b-256 b771101147d205eb355d155b83419cec1da01521dc5253dabf4be2cec45207bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pairl-1.5.2.tar.gz:

Publisher: release.yml on dwehrmann/PAIRL

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pairl-1.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e78395909bfdd32e5a8e67310f3be9534c914ac69d1548651999ae625b2dfd2c
MD5 5d49db151229e0629f1036ae7d0815ce
BLAKE2b-256 acec63462abc43a9e8d2e1c604aea22c45c285cc12f975fd3d6920b17ca5a564

See more details on using hashes here.

Provenance

The following attestation bundles were made for pairl-1.5.2-py3-none-any.whl:

Publisher: release.yml on dwehrmann/PAIRL

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page