One hallucinating agent silently corrupts context. Relay treats it like a ledger — signed, snapshotted, reversible.
pip install relay-middleware
One hallucinating agent corrupts the shared context. Every downstream agent inherits the damage. No audit trail, no rollback, no way to know where it broke.
Relay wraps every handoff in a cryptographically signed envelope. Contradictions trigger automatic rollback. The pipeline stays clean without any manual intervention.
Every context envelope HMAC-signed. Tampered payloads rejected before they propagate downstream.
Roll back to any prior snapshot in one call. Hallucinations vanish cleanly — no manual diff required.
Fan-out to multiple agents simultaneously. Merge via UNION, VOTE, or FIRST_WINS strategies.
Hard token caps per agent and per pipeline. Limits enforced before any LLM call is made.
LangChain, OpenAI, Anthropic, Ollama, CrewAI, AutoGen. Or your own callable. Lazy-loaded adapters.
PEP 561 compliant. mypy --strict passes across all 28 source files. Zero type: ignore.
# 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 hallucinates — drops "entities" silently
agent2_output = {"summary": "revenue increased"}
# Agent 3 inherits corrupted context — no audit trail, no rollback
agent3_input = f"Given: {json.dumps(agent2_output)}\nSummarize."
from relay.core_pipeline import CoreRelayPipeline
from relay.types import RollbackSuccess
pipeline = CoreRelayPipeline(
signing_secret="your-secret-key",
token_budget=8000
)
# Agent 1 — creates signed, immutable envelope
result = pipeline.execute_step({"entities": ["Apple"], "revenue": "2024"})
envelope1 = result.value # signed, snapshotted
# Agent 2 — accidentally drops "entities" (hallucination)
result = pipeline.execute_step({"summary": "growth"})
# Relay detects the contradiction and rolls back automatically
if isinstance(result, RollbackSuccess):
clean = pipeline.current_envelope # envelope1 restored