Skip to main content

A context-driven data pipeline and snapshotting library

Project description

Relay

Agent-agent context passing, done right.

Relay is a lightweight, open source Python middleware library for passing context reliably between AI agents in a multi-agent pipeline. Works with any LLM provider or framework — LangChain, OpenAI, Anthropic, LiteLLM, or your own agents.


The Problem

One hallucinating agent silently corrupts the shared context, and every downstream agent inherits the damage. Existing orchestration tools treat the context window as a mutable blob with no version control.

The Solution

Relay treats context like a ledger: append-only, signed at every step, and reversible.


Features

  • Context Broker — Normalizes, timestamps, and cryptographically signs context envelopes
  • Handoff Validator — Detects contradictions and triggers rollback on corruption
  • Snapshot Store — Persists immutable checkpoints for automatic rollback

Installation

git clone https://github.com/kridaydave/Relay.git
cd Relay
pip install -e .

The Aha Moment

Without Relay (manual, error-prone):

# Agent 1 produces output
agent1_output = {"entities": ["Apple", "2024 revenue"], "summary": "Apple grew"}

# Manual serialization — easy to lose data, corrupt context
context = json.dumps(agent1_output)

# Agent 2 receives corrupted context
agent2_input = f"Given: {context}\nAnalyze this."

With Relay (automatic, verified):

from relay.pipeline import RelayPipeline

pipeline = RelayPipeline(
    signing_secret="your-secret-key",
    token_budget=8000
)

# Agent 1 — creates signed envelope
result = pipeline.execute_step({"entities": ["Apple"], "revenue": "2024"})
envelope1 = result.value  # signed, immutable

# Agent 2 — validator detects contradiction
# If Agent 2 accidentally drops "entities", rollback triggers automatically
result = pipeline.execute_step({"summary": "growth"})  # contradiction!

What happens on contradiction:

# Validator detects: critical key "entities" disappeared
# Relay automatically rolls back to last clean snapshot

result = pipeline.rollback()
restored_envelope = result.value
# Now you have the clean envelope from step 1

How It Works

Agent 1 → [Sign Envelope] → Agent 2 → [Validate] → Agent 3
                              ↓
                         [Snapshot]
                              ↓
                    [Rollback if dirty]

Every handoff is signed and validated. If corruption is detected, Relay silently rolls back to the last clean checkpoint.


Context Envelope

Every context move between agents is wrapped in a signed, immutable envelope:

{
  "relay_version": "0.1.0",
  "pipeline_id": "uuid-v4",
  "step": 2,
  "timestamp": "2026-05-04T10:22:00Z",
  "token_budget_used": 1840,
  "token_budget_total": 8000,
  "payload": {...},
  "signature": "sha256:abc123..."
}

Error Handling

Relay uses Result types instead of exceptions:

from relay.types import Success, Failure, Result

result = pipeline.execute_step({"task": "work"})
if isinstance(result, Success):
    envelope = result.value
elif isinstance(result, Failure):
    print(f"Error: {result.reason} (code: {result.code})")

Testing

pytest tests/unit -v

Quality gates:

  • mypy --strict passes
  • 80% test coverage

  • Every public function has a test

License

MIT License - see LICENSE file


Resources

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

relay_middleware-0.1.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

relay_middleware-0.1.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for relay_middleware-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cdef9484e0387d4af78b0339e72400728b16d90e3a77188ce4909f00c1cb43b4
MD5 c7065de2b01d99633ba2708a21e15e75
BLAKE2b-256 e58e9e16bfebbe86ca2fa08dd9cc8ca1f7e68657c2c42b0964a18163a696aad2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for relay_middleware-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b056fd1e2ab91271e68742123144dfc4d5e42c880643d396c31d38c28ef670ff
MD5 b3c3b82889219b49c5baa00e7de0f7a2
BLAKE2b-256 5049c0846db03da8d6937b14184a67352d285704e0b8c8f648d9865c9d6006bb

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