PrismLang — Vector Protocol for LangGraph

Discover PrismLang — LangGraph middleware that cuts token costs. pip install prismlang. Apache 2.0. 57–62% token reduction by domain across healthcare,...

Open-source LangGraph middleware — tenant-isolated 64-d vectors, ONNX CPU encoding, Apache 2.0.

pip install prismlang — or clone github.com/insightitsGit/prismlang. One @prism_node decorator on your existing LangGraph nodes.

Business benefits

Cut LLM & API spend

Inter-agent hops drop from 391+ text tokens to a ~414-byte envelope — 57–62% fewer prompt tokens per graph run. Less repetition across nodes means a smaller monthly OpenAI, Anthropic, or Azure bill.

Less RAM & checkpoint bloat

LangGraph state stays compact: fixed-size vector payloads instead of growing text blobs in checkpointers. Smaller PostgreSQL/JSON checkpoints, lower memory footprint, faster serialize/deserialize on every hop.

CPU-only — no GPU tax

ONNX Runtime encodes locally in ~31–35 ms on standard server hardware. No extra GPU fleet, no embedding API calls for routing — predictable infra cost at scale.

Audit, debug & tenant safety

Every hop gets a rule_chain audit trail for compliance (HIPAA, SOX). Per-tenant JL isolation keeps customer vectors cryptographically separated — critical for multi-tenant SaaS.

Problems PrismLang solves

Runaway costs

Every agent-to-agent hop pays full prompt-token cost for the same context. In a 10-node graph, you pay for the same information ten times.

No audit trail

When routing goes wrong, there's no structured record of why an agent classified a message the way it did. Debug with logs—or nothing.

Shared context = shared risk

In multi-tenant SaaS, one misconfigured agent can expose one tenant's reasoning context to another. Text payloads don't enforce isolation.

How it works

01. Encode

Your agent's text output is embedded by all-MiniLM-L6-v2 (ONNX, fully local, no GPU, no API call) into a 384-dimensional semantic vector.

02. Spherical blend

The vector is pulled toward its category direction using: v′ = normalize((1−α)·v + α·‖v‖·eᵢ). Structurally similar outputs stay geometrically close across agents.

03. JL reduction (tenant isolation)

A Johnson–Lindenstrauss matrix P, seeded from SHA-256(tenant_id), reduces 384-d to 64-d: p = normalize(P · v′). Result: a PrismEnvelope—64 numbers + category slug + full rule_chain.

Domain use cases

Healthcare

Multi-agent clinical decision support—triage, diagnosis, treatment recommendation agents chaining through LangGraph.

−62.1% token reduction; HIPAA-compatible audit trail via rule_chain; per-provider tenant isolation.

Categories: triage, diagnosis, treatment, medication, lab_results

Finance

Risk analysis pipeline—market data ingestion, risk scoring, compliance checking, trade recommendation.

−57.0% token reduction; SOX-compatible audit trail; per-fund-manager tenant isolation.

Categories: risk, market, compliance, portfolio, derivatives

Trade market / supply chain

Commodity trade agents—market intelligence, contract analysis, logistics optimization.

−58.6% token reduction; structured routing across heterogeneous agent types.

Categories: commodity, contract, logistics, pricing, regulatory

Benchmark comparison

DomainMetricStandardPrismLangWinner
HealthcarePrompt tokens391148PrismLang −62%
FinancePrompt tokens407175PrismLang −57%
Trade marketPrompt tokens435180PrismLang −59%
All domainsState growth (per turn)Grows linearlyFixed at 320B/turnPrismLang ~50% smaller
All domainsVector vs text payloadBaseline~2× smallerPrismLang
All domainsCategory audit flowNoneVERIFIEDPrismLang
All domainsLLM time151 ms151 msTie (encoding ~0 ms for short texts)

PrismLang vs raw text routing

PropertyPrismLangRaw text
Token reduction57–62%0% (raw text)
Routing audit trailFull rule_chain per turnNone
Tenant isolationCryptographic (SHA-256 JL seed)None / app-layer only
LLM dependency for routingNoneRequired (GPT-4, Claude, etc.)
GPU requirementNone (ONNX CPU)Often required
LangGraph relationshipMiddleware layer on top — keep your graphN/A (not a graph engine)
LangGraph integration1 decorator on existing nodesRebuild graph from scratch
CheckpointingJSON file + PostgreSQLExternal only
Async supportNative (async_prism_node)N/A
LicenseApache 2.0Varies

Capabilities

57–62% Token Reduction

Compress inter-agent state transport—not context windows—with proven 57–62% savings across domains.

Full Audit Trail

Every envelope carries an immutable rule_chain tracing taxonomy → projection → JL reduction.

Tenant Isolation

SHA-256-seeded JL matrices per tenant—cross-tenant cosine similarity stays below 0.20.

Install

pip install prismlang. Apache 2.0. 57–62% token reduction by domain across healthcare, finance, and trade.

Frequently asked questions

Is PrismLang a replacement for LangGraph?

No. PrismLang is not an orchestration framework and does not replace LangGraph. It is a middleware layer that sits on top of your existing LangGraph graphs — you keep StateGraph, nodes, edges, and checkpointers exactly as they are. Add @prism_node to nodes you want to compress; LangGraph still runs the workflow. PrismLang makes LangGraph multi-agent pipelines leaner, auditable, and tenant-safe.

Does PrismLang work with any LangGraph version?

Yes — PrismLang requires LangGraph ≥ 0.2.0 and integrates via the standard BaseCheckpointSaver API. Tested on LangGraph 0.2.x and 0.3.x.

Do I need a GPU?

No. PrismLang uses ONNX Runtime for CPU-only inference. all-MiniLM-L6-v2 runs efficiently on standard server hardware with ~31–35 ms encode latency.

Can I use my own embedding model?

The encoder module is pluggable. By default, PrismLang uses all-MiniLM-L6-v2 (384-d). Subclass the encoder and pass a custom encode() function—the math works for any fixed-dimension embedding.

Is the 57–62% token reduction guaranteed?

Reduction is domain and taxonomy dependent. Benchmarks measured 57–62% across healthcare, finance, and trade domains. Your results vary based on agent verbosity and taxonomy granularity.

How does tenant isolation actually work?

Each tenant gets a unique JL matrix P derived from SHA-256(tenant_id). The same text under two tenants produces vectors with cosine similarity ≈ 0.14–0.17—near-orthogonal.

Is this a replacement for a vector database?

No. PrismLang is a wire protocol—it compresses agent-to-agent communication. Use it alongside PostgreSQL+pgvector, Pinecone, or similar for RAG retrieval.

Can I contribute to PrismLang?

Yes — see CONTRIBUTING.md at github.com/insightitsGit/prismlang. Taxonomy contributions for new domains are especially welcome.

Official package links: PrismLang interactive demo

View PrismLang in shop