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.1.tar.gz (15.4 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.1-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file pairl-1.5.1.tar.gz.

File metadata

  • Download URL: pairl-1.5.1.tar.gz
  • Upload date:
  • Size: 15.4 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.1.tar.gz
Algorithm Hash digest
SHA256 2925f3c42aca984b08260d0da4f777a7474489b8ade2c5ad9db14b588cf1a63f
MD5 6d549b1cc7450434e34b0753f23c084a
BLAKE2b-256 f968cac9fdbbd46be993dea56a0ba64a588108289495a93402dd8aa395aebcbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for pairl-1.5.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: pairl-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 16.5 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0a7a233584402fd753bdee253fee6b33fbc94f13170d66adc8ff614fb16f2c63
MD5 d4f0d5987b8f54bb934df79c8966663f
BLAKE2b-256 e490299b549256ee048838aa648d4e802fb12e95e851268365558214b8fd6244

See more details on using hashes here.

Provenance

The following attestation bundles were made for pairl-1.5.1-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