This document describes how Lambda Lang is used within ASAP Protocol for semantic compression of JSON-RPC 2.0 payloads.
| Component | Purpose |
|---|---|
| ASAP Protocol | Transport layer — JSON-RPC 2.0 over HTTP/WebSocket, task orchestration |
| Lambda Lang | Compression layer — semantic atom substitution for payload size reduction |
Together they provide compressed agent-to-agent communication:
┌─────────────────────────────────────────┐
│ Lambda Lang (semantic compression) │ ← "How to compress"
│ §Jrpc§ §Mthd§ §Treq§ §Hb§ │
├─────────────────────────────────────────┤
│ ASAP Protocol (transport layer) │ ← "How to communicate"
│ JSON-RPC 2.0 / HTTP / WebSocket │
└─────────────────────────────────────────┘
ASAP uses standard HTTP content negotiation to enable Lambda compression. The mechanism is fully opt-in — when not requested, everything stays JSON.
Agent A Agent B
│ │
│──── POST /asap ─────────────────────────────▶ │
│ Accept: application/vnd.asap+lambda │
│ │
│ ◀──── 200 OK ─────────────────────────────── │
│ Content-Type: application/vnd.asap+lambda
│ Body: λ1:{§Jrpc§:§V2§, §Mthd§:§Am§, …} │
│ │
application/vnd.asap+lambda
All encoded payloads start with λ1: for forward compatibility. Future codec versions can use λ2:, etc.
- If the server cannot encode with Lambda, it falls back to
application/jsonsilently - Error responses are always returned as JSON regardless of
Acceptheader - Wildcard
Accept: */*does NOT trigger Lambda encoding (conservative negotiation)
The codec substitutes common JSON-RPC and ASAP keys with short Lambda atoms wrapped in §…§ delimiters (chosen because § cannot appear in valid JSON).
| JSON key | Lambda atom |
|---|---|
"jsonrpc" |
§Jrpc§ |
"method" |
§Mthd§ |
"params" |
§Prms§ |
"result" |
§Rslt§ |
"error" |
§Er§ |
"id" |
§Id§ |
"code" |
§Cd§ |
"message" |
§Msg§ |
"data" |
§Dt§ |
| JSON key | Lambda atom |
|---|---|
"envelope" |
§Env§ |
"sender" |
§Snd§ |
"recipient" |
§Rcp§ |
"payload" |
§Pld§ |
"payload_type" |
§Pt§ |
"task_id" |
§Ta§ |
"status" |
§St§ |
"trace_id" |
§Tr§ |
"timestamp" |
§Ts§ |
"version" |
§Vr§ |
| JSON value | Lambda atom |
|---|---|
"asap.message" |
§Am§ |
"2.0" |
§V2§ |
"task.request" |
§Treq§ |
"task.response" |
§Tres§ |
"task.status" |
§Tst§ |
"heartbeat" |
§Hb§ |
"success" |
§Ok§ |
"pending" |
§Pn§ |
"running" |
§Rn§ |
"completed" |
§Cp§ |
"failed" |
§Fl§ |
"cancelled" |
§Cx§ |
Total: 35 atom mappings covering the full JSON-RPC + ASAP envelope vocabulary.
{"jsonrpc":"2.0","method":"asap.message","id":"abc-123","params":{"envelope":{"sender":"agent-a","recipient":"agent-b","payload_type":"task.request","status":"pending","trace_id":"tr-456"}}}λ1:{§Jrpc§:§V2§,§Mthd§:§Am§,§Id§:"abc-123",§Prms§:{§Env§:{§Snd§:"agent-a",§Rcp§:"agent-b",§Pt§:§Treq§,§St§:§Pn§,§Tr§:"tr-456"}}}
Compression ratio: ~28% reduction on this typical ASAP envelope. Savings increase with larger payloads containing more substitutable keys.
- Self-contained: No dependency on the
lambda-langPython package — all atom mappings are inline - Single-pass regex: Pre-compiled
re.compile()pattern for C-level substitution speed (no Pythonforloop) - String-based API:
encode(json_str) → stranddecode(encoded) → str— accepts pre-serialized JSON to leverage Pydantic v2's Rust core (model_dump_json()) - 100% fidelity:
decode(encode(s)) == sfor any valid JSON string
Both server-side encoding and client-side decoding are offloaded via asyncio.to_thread() to prevent blocking FastAPI's event loop on large payloads.
- Codec:
src/asap/transport/codecs/lambda_codec.py - Server negotiation:
src/asap/transport/server.py - Client negotiation:
src/asap/transport/client.py - Unit tests:
tests/transport/unit/test_lambda_codec.py(27 tests) - Integration tests:
tests/transport/integration/test_lambda_negotiation.py(7 tests)
- ASAP Protocol Repository
- Lambda Lang Codec Source
- PR #71 — Original integration
- Issue #52 — Original proposal
- Lambda Lang Core Spec
Integration designed by @adriannoes — ASAP Protocol maintainer