Skip to main content

Deterministic vector language protocol for multi-agent AI orchestration

Project description

PrismLang

PrismLang

Deterministic Vector Language Protocol for LangGraph Multi-Agent AI

Stop paying the token tax on every agent hop. Start routing with math.

PyPI Python License LangGraph Tests Security


๐Ÿ“– Docs ยท ๐Ÿš€ Quickstart ยท ๐Ÿ“Š Benchmarks ยท ๐Ÿข Insight IT Solutions


pip install prismlang

The Problem

Every node in a LangGraph multi-agent pipeline reads the entire message history as prompt tokens. By turn 3 of a standard graph, every agent is paying for every prior agent's output โ€” every single call.

Turn 1 โ†’  800 B   1 agent  reading history
Turn 2 โ†’ 1,600 B  2 agents reading history
Turn 3 โ†’ 2,400 B  3 agents reading history    โ† you're paying 3ร— for the same data

On top of that:

  • No audit trail โ€” you can't trace why an agent classified something the way it did
  • No tenant isolation โ€” in multi-tenant SaaS, one misconfigured agent can bleed context across org boundaries

The Solution

PrismLang replaces growing text payloads with 64-number deterministic vectors โ€” one per agent turn. A single decorator on your existing nodes. No agent refactoring. No LLM retraining.

[Your Agent]  โ†’  "Credit risk elevated in EM bonds."  (text, 400+ tokens)
                              โ†“  @prism_node
              โ†’  PrismEnvelope { vector[64], slug="risk", rule_chain }  (~414 bytes)

The math guarantees that the same input always produces the same vector, that different tenants produce incompatible vectors, and that every routing decision is traceable back to a taxonomy rule.


How It Works

PrismLang applies two equations on every agent output:

Step 1 โ€” Spherical Blend (pulls the embedding toward its category direction)

v' = normalize( (1 โˆ’ ฮฑ) ยท v  +  ฮฑ ยท โ€–vโ€– ยท eแตข )

Step 2 โ€” JL Reduction (compresses to k=64 dims, isolated per tenant)

p = normalize( P ยท v' )

Where P is a (64 ร— 384) Gaussian matrix seeded from SHA-256(tenant_id). A vector stolen from Tenant A is geometrically meaningless to any model operating under Tenant B's projection.

                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚           Your LangGraph Graph              โ”‚
                    โ”‚                                             โ”‚
  [researcher] โ”€โ”€โ†’ [summarizer] โ”€โ”€โ†’ [reviewer] โ”€โ”€โ†’ [translator]  โ”‚
       โ”‚                โ”‚               โ”‚               โ”‚         โ”‚
  @prism_node      @prism_node     @prism_node     (boundary)     โ”‚
       โ”‚                โ”‚               โ”‚               โ”‚         โ”‚
  PrismEnvelope    PrismEnvelope   PrismEnvelope   Human text     โ”‚
  {64-d vector}    {64-d vector}   {64-d vector}                  โ”‚
  {rule_chain}     {rule_chain}    {rule_chain}                    โ”‚
                    โ”‚                                             โ”‚
                    โ”‚  prism_sequence  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  append-only     โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Quick Start

from prismlang import (
    Category, TaxonomyConfig, PrismProjector,
    PrismState, prism_node, BoundaryTranslator,
    JsonFileCheckpointer,
)
from langgraph.graph import StateGraph, END

# 1. Define your domain taxonomy
taxonomy = TaxonomyConfig(categories=[
    Category("risk",       "Market Risk",   ["risk", "exposure", "volatility"]),
    Category("market",     "Market Data",   ["price", "equity", "bond"]),
    Category("compliance", "Compliance",    ["regulation", "audit", "kyc"]),
])

# 2. One projector per tenant โ€” cryptographically isolated
projector = PrismProjector(taxonomy, tenant_id="acme-finance-prod", k=64)

# 3. Decorate your existing nodes โ€” zero changes to agent logic
@prism_node(agent_id="analyst", projector=projector)
def analyst(state: PrismState) -> dict:
    return {"raw_output": "Credit risk exposure elevated in EM bonds."}

@prism_node(agent_id="reviewer", projector=projector)
def reviewer(state: PrismState) -> dict:
    prev = state["prism_sequence"][-1]["category_slug"]
    return {"raw_output": f"Reviewing {prev} findings for compliance sign-off."}

# 4. Build and run โ€” exactly like any LangGraph graph
translator = BoundaryTranslator()
graph = StateGraph(PrismState)
graph.add_node("analyst",    analyst)
graph.add_node("reviewer",   reviewer)
graph.add_node("translator", translator.as_langgraph_node())
graph.set_entry_point("analyst")
graph.add_edge("analyst", "reviewer")
graph.add_edge("reviewer", "translator")
graph.add_edge("translator", END)

app = graph.compile(checkpointer=JsonFileCheckpointer())
result = app.invoke({
    "prism_sequence": [], "raw_output": "", "tenant_id": "acme-finance-prod"
})

# Inspect the audit envelope
envelope = result["prism_sequence"][0]
print(envelope["category_slug"])   # "risk"
print(len(envelope["vector"]))     # 64
print(envelope["rule_chain"])
# ['text -> encoder(all-MiniLM-L6-v2, d=384)',
#  "category_inference -> slug='risk'",
#  'spherical_blend(alpha=0.300) -> v_prime',
#  "JL_reduction(seed=sha256('acme-finance-prod'), k=64) -> p"]

Benchmark Results

Measured against standard LangGraph text-state across three enterprise domains.
Full methodology in docs/BENCHMARK.md. Results stored in PostgreSQL.

Domain Metric Standard LangGraph PrismLang Change
๐Ÿฅ Healthcare
ICU triage pipeline
Prompt tokens (3 turns) 391 148 โˆ’62.1%
State size (turn 3) 1,928 B 960 B โˆ’50.2%
๐Ÿ’น Finance
Risk / portfolio pipeline
Prompt tokens (3 turns) 407 175 โˆ’57.0%
State size (turn 3) 1,760 B 960 B โˆ’45.5%
๐Ÿ“ˆ Trade Market
Signal / execution pipeline
Prompt tokens (3 turns) 435 180 โˆ’58.6%
State size (turn 3) 1,867 B 960 B โˆ’48.6%

LLM inference latency: unchanged. PrismLang reduces state transport, not compute.
Encoding overhead per turn: ~31โ€“35 ms CPU-only (no GPU required).


Key Properties

Property Detail
Zero agent refactoring Agents return {"raw_output": "..."} โ€” nothing else changes
Deterministic Same text + same tenant = identical vector, always
Full audit trail Every envelope carries a rule_chain tracing the full decision path
Tenant isolation SHA-256(tenant_id) seeds the JL matrix โ€” cross-tenant vectors are incompatible
No GPU ONNX Runtime CPU inference โ€” runs on any standard server
No external API Encoder is fully local โ€” no network call per token
Model-agnostic Works with GPT-4, Claude, Gemini, Llama, or any LLM
Async native @async_prism_node for async LangGraph nodes
Two checkpointers JsonFileCheckpointer (zero deps) + PostgresCheckpointer

Installation Options

# Core (local JSON checkpointing)
pip install prismlang

# PostgreSQL checkpointing
pip install "prismlang[postgres]"

# Async support (asyncpg + aiofiles)
pip install "prismlang[async-postgres,async-files]"

# Full development environment
pip install "prismlang[dev]"

Run the Benchmarks

git clone https://github.com/insightitsGit/prismlang
cd prismlang
pip install -e ".[dev]"

# Runs all 3 domain benchmarks and prints comparison table
python -m benchmarks.run_all

Requires a running PostgreSQL instance. Set DATABASE_URL or use the default:
postgresql://insight_admin:...@localhost/prismLangDB


Project Structure

prismlang/
โ”œโ”€โ”€ prismlang/
โ”‚   โ”œโ”€โ”€ encoder.py        # ONNX all-MiniLM-L6-v2 โ†’ 384-d unit vector
โ”‚   โ”œโ”€โ”€ taxonomy.py       # TaxonomyConfig + Category direction vectors (eแตข)
โ”‚   โ”œโ”€โ”€ projector.py      # PrismProjector: spherical blend + JL reduction
โ”‚   โ”œโ”€โ”€ middleware.py     # @prism_node + @async_prism_node decorators
โ”‚   โ”œโ”€โ”€ checkpointer.py   # JsonFile + Postgres + Async variants
โ”‚   โ”œโ”€โ”€ exceptions.py     # Typed exception hierarchy (17 classes)
โ”‚   โ”œโ”€โ”€ envelope.py       # PrismEnvelope TypedDict
โ”‚   โ”œโ”€โ”€ state.py          # PrismState (LangGraph append-only channel)
โ”‚   โ””โ”€โ”€ translator.py     # BoundaryTranslator (structural reconstruction)
โ”œโ”€โ”€ benchmarks/
โ”‚   โ””โ”€โ”€ domains/          # Healthcare ยท Finance ยท Trade Market
โ”œโ”€โ”€ demo/
โ”‚   โ””โ”€โ”€ graph.py          # Runnable 3-node LangGraph demo
โ”œโ”€โ”€ tests/                # 34 tests ยท 0 failures
โ””โ”€โ”€ docs/
    โ”œโ”€โ”€ ARCHITECTURE.md
    โ”œโ”€โ”€ BENCHMARK.md
    โ””โ”€โ”€ SECURITY.md

Security

PrismLang's tenant isolation is a geometric property guaranteed by the Johnson-Lindenstrauss lemma โ€” not an access-control system. For production deployments, see docs/SECURITY.md which covers:

  • What the JL matrix does and does not protect
  • Overlay encryption for PII in raw_output
  • Dependency security notes (onnxruntime, psycopg2, asyncpg)
  • NumPy PRNG stability across version upgrades

To report a vulnerability: prismrag@insightits.com โ€” do not open a public GitHub issue.


Citation

@techreport{parva2026prismlang,
  title       = {PrismLang: A Deterministic Vector Language Protocol
                 for Auditable Multi-Agent AI Orchestration},
  author      = {Parva, Amin},
  year        = {2026},
  institution = {Insight IT Solutions LLC},
  url         = {https://www.insightits.com/prismlang}
}

License

Apache 2.0 โ€” free for commercial and personal use.


Built by Insight IT Solutions LLC

Enterprise AI systems ยท LangGraph architecture ยท Vector search ยท Production deployment

๐ŸŒ Website ยท ๐Ÿ“ง Contact ยท ๐Ÿ”’ Security

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

prismlang-0.1.0.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

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

prismlang-0.1.0-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file prismlang-0.1.0.tar.gz.

File metadata

  • Download URL: prismlang-0.1.0.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for prismlang-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7fa7b1ad02b2377c9b83fb350237ffc61662d258662f755ef40addef57915a2e
MD5 7e7da73595a7f69627239ca2ffff4a9e
BLAKE2b-256 5b05bbcce2404cd6dd366aebb5f2eae917ffc7d598fcfbd133ecf558605bc75a

See more details on using hashes here.

File details

Details for the file prismlang-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: prismlang-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for prismlang-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3639083b60f17312e0f8f9c104e90e176e3113b309514d84f3fa43bafa62b7a2
MD5 4887462c3e6ba1076902752bc890c42a
BLAKE2b-256 55b9b7c8616e3f2930c8202d7408410aa461ba140647078376a50e380c8e36cb

See more details on using hashes here.

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