LLM Transport & Efficiency Layer — make LLM calls cheaper, faster, and smarter
Project description
LATTICE
LLM Transport & Efficiency Layer
Make every LLM call cheaper, faster, and safe — without changing your model.
LATTICE sits between your application and any LLM provider. It compresses prompts, caches responses, manages concurrency (TACC), supports a native binary protocol, and routes coding agents through one self-hosted proxy. Your app sends standard OpenAI-format requests; LATTICE makes them smaller, faster, and cache-friendlier.
It is not a router. LATTICE never changes your model, never falls back between providers, never guesses. One provider per request. LATTICE optimises transport and execution.
Table of Contents
- Installation
- Quick Start
- Architecture
- Novel Technology
- Compression Pipeline
- Safety
- Observability
- Supported Providers
- CLI Reference
- Agent Integration
- Development
- Migrating from v0.x
- Documentation
- License
Installation
pip install lattice-transport
Optional extras:
pip install "lattice-transport[redis]" # Multi-process session store
pip install "lattice-transport[mcp]" # MCP tool support
pip install "lattice-transport[all]" # Everything
Requirements: Python 3.10+. No external services required for single-process mode.
Quick Start
# Start the proxy
lattice proxy run --port 8787
# Point any OpenAI SDK at it
export OPENAI_BASE_URL=http://localhost:8787/v1
# Or route an agent through it
lattice lace claude
from lattice import LatticeClient
client = LatticeClient()
response = client.chat.completions.create(
model="openai/gpt-4o",
messages=[{"role": "user", "content": "Explain transport protocols"}],
)
print(response.choices[0].message.content)
Every request is automatically compressed, cached, and optimized in proxy mode — zero application code changes.
Architecture
Application
│ OpenAI / Anthropic API format
▼
LATTICE Proxy :8787
│
├── state/ Session, segments, SemanticCache
├── planner/ RequestClassifier → UnifiedPlanner → ExecutionPlan
├── pipeline/ Pipeline.compress() — IR-native transforms + gates
├── telemetry/ Metrics, downgrade, cost, agent stats
└── providers/ adapters/ (17) + transport/ (HTTP pool, TACC, streaming)
│
▼
LLM Provider (exactly one per request)
Request flow
- Client sends
POST /v1/chat/completions(or Anthropic/v1/messages). SessionManagercreates or loads a session (CAS versioning).content_profilerbuilds a semantic profile;UnifiedPlannerproduces anExecutionPlan.Pipeline.compress()runs transforms with policy, budget, risk, and MILV gates.SemanticCachechecks exact hash, then approximate fingerprint.- On miss, the provider adapter sends via HTTP/2 pool; TACC manages admission.
- Response reverse pass +
x-lattice-*headers viaLatticeHeaderMiddleware.
Novel Technology
LATTICE applies classical systems techniques to LLM workloads — transport and execution, not model features.
| Capability | Summary | Deep dive |
|---|---|---|
| TACC | Token-aware AIMD congestion control | docs/novel/tacc.md |
| Binary framing | 15-byte headers, 17 frame types, CRC32 | docs/novel/binary-framing.md |
| Delta encoding | Turn 2+ sends deltas only; CAS sessions | docs/novel/delta-encoding.md |
| Streaming | Stall detection, resume tokens, multiplex | docs/novel/streaming.md |
| Batching | Groups compatible requests | docs/novel/batching-speculation.md |
| Speculation | Rule-based next-turn precompute | docs/novel/batching-speculation.md |
Batching overhead reduction and long-conversation dedup savings are measured in the canonical benchmark suite — see Claim traceability [^batch] [^dedup].
Compression Pipeline
LATTICE ships 20 transforms (list_transform_names() in lattice.transforms.registry). Six run in the default pipeline; three are execution-only (batching, speculative, delta); the rest are planner-selected or off by default. Every transform is safety-classified and risk-gated.
| P | Transform | Safety | What it does | Default |
|---|---|---|---|---|
| 1 | content_profiler | SAFE | Classifies content, computes semantic risk score | yes |
| 2 | runtime_contract | SAFE | Per-transform budget and timeout | yes |
| 2 | speculative | SAFE | Speculative token generation | exec |
| 3 | batching | SAFE | Request batching for multi-turn workloads | exec |
| 5 | delta_encoder | SAFE | Session-based delta encoding | exec |
| 9 | cache_arbitrage | SAFE | KV-cache alignment reorder | yes |
| 9 | causal_chain | SAFE | Causal chain extraction | no |
| 15 | message_dedup | CONDITIONAL | Exact/near-duplicate turn removal | no |
| 17 | diagnostic_rle | SAFE | Diagnostic repetition RLE | no |
| 18 | context_selector | SAFE | Submodular context selection | no |
| 19 | columnar_pack | SAFE | Columnar table packing | no |
| 20 | reference_sub | CONDITIONAL | UUID/URL/hash → short refs | yes |
| 21 | json_shape | SAFE | JSON shape factoring | no |
| 22 | extractive_compress | SAFE | Extractive compression | no |
| 22 | rate_distortion | CONDITIONAL | Rate-distortion semantic compression | no |
| 23 | path_prefix | SAFE | Filesystem path prefix compression | no |
| 25 | format_conversion | CONDITIONAL | Table/JSON format conversion | no |
| 29 | tool_projection | SAFE | Query-aware tool field projection | no |
| 30 | tool_filter | SAFE | Tool output filtering | yes |
| 40 | output_cleanup | SAFE | Response-side whitespace/JSON cleanup | yes |
exec = execution-only transform (outside default pipeline list).
Headline compression on the canonical feature suite (ollama-cloud / kimi-k2.6:cloud): 40.3% average reduction [^compress]. Pipeline latency ~36 ms [^latency].
→ Transform reference · Claim traceability · Feature parity checklist (61 rows)
Safety
Transforms are classified SAFE, CONDITIONAL, or DANGEROUS. A 0–100 semantic risk score gates lossy transforms; expansion guards cap token growth.
→ Safety guide · SIG · RATS · PSG · MILV
Observability
curl http://localhost:8787/stats | jq
curl http://localhost:8787/metrics
- /stats — transforms, sessions, pools, TACC, maintenance, downgrades
- /metrics — Prometheus counters and histograms
- Response headers —
x-lattice-compression,x-lattice-session-id,x-lattice-delta,x-lattice-cost-usd,x-lattice-provider,x-lattice-transforms-applied
Supported Providers
17 direct adapters. No routing — one provider per request.
| Provider | Prefix | HTTP/2 | Streaming |
|---|---|---|---|
| OpenAI | openai/ |
yes | SSE |
| Anthropic | anthropic/, claude- |
yes | SSE |
| Azure | azure/ |
yes | SSE |
| Bedrock | bedrock/ |
yes | SSE |
| Gemini | gemini/, google/ |
yes | SSE |
| Vertex AI | vertex/ |
yes | SSE |
| Groq | groq/ |
yes | SSE |
| DeepSeek | deepseek/ |
yes | SSE |
| Mistral | mistral/ |
yes | SSE |
| Cohere | cohere/ |
yes | SSE |
| Ollama | ollama/ |
— | SSE |
| Ollama Cloud | ollama-cloud/ |
yes | SSE |
| OpenRouter | openrouter/ |
yes | SSE |
| Fireworks | fireworks/ |
yes | SSE |
| Together | together/ |
yes | SSE |
| Perplexity | perplexity/ |
yes | SSE |
| AI21 | ai21/ |
yes | SSE |
CLI Reference
lattice proxy run --port 8787
lattice proxy start|stop|restart|status
lattice init
lattice lace|unlace <agent>
lattice info|config|status|health|doctor
lattice benchmark --suite feature # wraps benchmarks/evals/cli.py
Agent Integration
lattice lace claude # Claude Code
lattice lace codex # OpenAI Codex
lattice lace cursor # Cursor
lattice lace opencode # OpenCode
lattice lace copilot # GitHub Copilot
lattice doctor (no args) checks all five agents. lattice init applies durable config; lattice lace uses transient routing + tunnel sidecar.
Development
git clone https://github.com/Harsh-Daga/lattice
cd lattice
uv sync
uv run pytest tests/ -q # 2016 collected, 1801 passed (215 skipped)
uv run pytest tests/contract/ -q
uv run ruff check src/ tests/ benchmarks/
uv run ruff format --check src/ tests/ benchmarks/
uv run mypy src/lattice/
uv run python benchmarks/evals/cli.py --suite all \
--providers ollama-cloud \
--provider-model ollama-cloud=kimi-k2.6:cloud \
--iterations 3 --warmup 1
→ AGENTS.md for AI agent contributors
Migrating from v0.x
Internal Python imports changed in 1.0.0. CLI and HTTP are stable.
Documentation
| Section | Documents |
|---|---|
| Getting Started | Quick Start · Installation · CLI |
| Architecture | Runtime · Safety · SDK |
| Novel Tech | TACC · Binary framing · Delta · Streaming |
| Compression | Transforms · Caching |
| Providers | 17 providers |
| Operations | Agent integrations |
Claim footnotes
[^compress]: benchmarks/results/CLAIMS.md — feature suite avg_reduction_ratio from v1.0.0.json
[^latency]: benchmarks/results/CLAIMS.md — avg_pipeline_latency_ms from v1.0.0.json
[^batch]: benchmarks/results/CLAIMS.md — batching overhead row
[^dedup]: benchmarks/results/CLAIMS.md — message_dedup row
License
MIT © Harsh Daga
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 lattice_transport-1.0.0.tar.gz.
File metadata
- Download URL: lattice_transport-1.0.0.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8de5c3d6bd19297d0c1a466390ac7395131c7f53f196bb62aab39e5976118e49
|
|
| MD5 |
96369330f4814584ca9d435054aa06dc
|
|
| BLAKE2b-256 |
1793df7042df911d705a9b547714ae6d3ebdbed25fccad2c0f0d5d86fa81f0fd
|
Provenance
The following attestation bundles were made for lattice_transport-1.0.0.tar.gz:
Publisher:
publish.yml on Harsh-Daga/Lattice
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lattice_transport-1.0.0.tar.gz -
Subject digest:
8de5c3d6bd19297d0c1a466390ac7395131c7f53f196bb62aab39e5976118e49 - Sigstore transparency entry: 1629088057
- Sigstore integration time:
-
Permalink:
Harsh-Daga/Lattice@86e4ba4b8346f75182acc00a3e5ad6eb2fc77b2b -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Harsh-Daga
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@86e4ba4b8346f75182acc00a3e5ad6eb2fc77b2b -
Trigger Event:
release
-
Statement type:
File details
Details for the file lattice_transport-1.0.0-py3-none-any.whl.
File metadata
- Download URL: lattice_transport-1.0.0-py3-none-any.whl
- Upload date:
- Size: 488.4 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 |
4d4f880cb97512bab6e74ed080fa149437b3942f36925959353b536ff82af8bb
|
|
| MD5 |
33b874271af3b28d948407fb34cf9d55
|
|
| BLAKE2b-256 |
a2d62dbe63036463801471dd2e61a65132f6297402e38768b8c55b1c8b310f6e
|
Provenance
The following attestation bundles were made for lattice_transport-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on Harsh-Daga/Lattice
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lattice_transport-1.0.0-py3-none-any.whl -
Subject digest:
4d4f880cb97512bab6e74ed080fa149437b3942f36925959353b536ff82af8bb - Sigstore transparency entry: 1629088082
- Sigstore integration time:
-
Permalink:
Harsh-Daga/Lattice@86e4ba4b8346f75182acc00a3e5ad6eb2fc77b2b -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Harsh-Daga
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@86e4ba4b8346f75182acc00a3e5ad6eb2fc77b2b -
Trigger Event:
release
-
Statement type: