ContextUnityπ
The Open, Zero-Trust AI Service Mesh You Actually Ownπ
Memory Β· Agency Β· Durable Execution Β· Cryptographic Isolation Β· Read-Only Observability
Zero cloud provider lock-in. Zero vendor lock-in. Built for teams shipping real sovereign AI applications.
Documentation Β· Manifesto Β· Roadmap (0.6 β 0.14) Β· Architecture & ADRs Β· Report an Issue
Why ContextUnity?π
Most modern "AI agent frameworks" force an uncomfortable choice:
- Thin prompt wrappers that fall apart the moment you need durable retries, multi-tenant isolation, real memory beyond naive vector chunks, or an audit trail.
- Hosted black-box agent clouds that lock you into one provider, burn tokens on redundant loops, and force you to hand over database credentials and private business data.
ContextUnity is an open-source, modular AI service mesh designed for teams building real AI products they fully own β running identically on a single developer laptop (SQLite + Huey + loopback gRPC) and on a production cluster (PostgreSQL + pgvector + Temporal + mTLS/KMS).
Early Preview (
v0.5.x): ContextUnity is an active open R&D and application platform already powering multiple real products in development. Contracts and manifests are stabilizing across continuous lockstep iterations (0.6 β 0.14+). Feedback, bug reports, and contributions are welcome on GitHub Issues.
Architecture at a Glanceπ
ContextUnity separates orchestration, memory, execution, security, and observability into five typed gRPC services speaking a single protocol (ContextUnit), while your application code and database credentials stay strictly inside your own project perimeter.
flowchart LR
App["Your Application / Project<br/>contextunity.project.yaml<br/>(@federated_tool handlers Β· private DB)"]
subgraph Mesh["ContextUnity Service Mesh (gRPC Β· ContextUnit Β· Attenuated ContextToken)"]
Router["ContextRouter<br/>Stateless LangGraph 1.2 DAGs<br/>Model Routing Β· PII Masking"]
Brain["ContextBrain<br/>5-Module Hybrid Memory<br/>Graph-First Β· Vector Fallback"]
Worker["ContextWorker<br/>PATH L (Huey) / PATH T (Temporal)<br/>Durable Workflows Β· Sandboxes"]
Shield["ContextShield<br/>Zero-Trust Citadel<br/>Secrets Β· Attenuation Β· Firewall"]
Forge["ContextForge<br/>Read-Only Observability<br/>Traces Β· UDB Β· Review Queues"]
end
App <-->|"BiDi gRPC Stream<br/>(Intents & Tool Results)"| Router
Router <--> Brain
Router <--> Shield
Router <--> Worker
Worker <--> Brain
Worker <--> Shield
Forge -.->|"Read-Only Queries"| Brain
Forge -.->|"Read-Only Queries"| Shield
Forge -.->|"Read-Only Queries"| WorkerCore Services & Workspace Packagesπ
Every package in this repository lives in a single uv workspace and ships under strict lockstep versioning (v0.X.Y) β any packages sharing the same 0.X.* minor version are guaranteed contract-compatible over gRPC and ContextUnit.
| Module | Package | Role | Key Capabilities |
|---|---|---|---|
| Core Kernel | contextunity-core | Shared Contracts & SDK | ContextUnit protobufs, ContextToken signing/attenuation, typed L0βL4 boundaries, gRPC clients, manifest models. |
| CLI | contextunity-cli | Operator & Dev Shell | contextunity local up, config bootstrap, diagnostics, memory & manifest commands (same contracts as SDK/MCP). |
| Django Adapter | contextunity-django | Web Integration | Typed Django client integration and GridViewSpec helpers for host web apps. |
| ContextRouter | contextunity-router | Mind & Transport | Stateless LangGraph 1.2 compilation from manifests, multi-provider LLM gateway, fallback chains, RouterShadower PII masking. |
| ContextBrain | contextunity-brain | Flat Hybrid Memory | Blackboard, BrainCell, CellEdges, BrainSynapse (3D Q-learning), BrainEngram compiled surfaces, and UniversalDebugBus (UDB). |
| ContextWorker | contextunity-worker | Durable Execution | Engine-neutral workflows running locally (PATH L / Huey) or distributed (PATH T / Temporal) with actors & schedules. |
| ContextShield | contextunity-shield | The Citadel | Per-node capability stripping, AI firewall, prompt & secret vault, Ed25519/KMS signing, audit trail, Constitution gates. |
| ContextForge | contextunity-forge | Observability Console | Read-only Django + HTMX + GridViewSpec UI for Graph Journey, UDB cases, Context Lineage, Review Queues, and ForgeLibrarian. |
Where does domain business logic live? Always in your own application or extension repository (e.g., Commerce PIM, Knowledge Base, or custom products). ContextUnity provides the cognitive, durable, and security substrate β never a monolith that absorbs your business domain.
Core Design Principlesπ
- Inversion of Control (Federated Execution): ContextUnity never asks for your application database DSN or credentials. Agents emit typed intents; your application executes
@federated_toolhandlers inside its own perimeter over authenticated bidirectional gRPC streams (ADR-0001). - Manifest-First (
contextunity.project.yaml): Projects declare graphs, model policies, orchestration roles, and allowed toolkits in one strictly validated YAML file β zero orchestration boilerplate (ADR-0002). - Graph-First, Vector-Fallback Memory:
ContextBraintraverses spatialscope_path, explicitCellEdges, compiledBrainEngrams, and sparse BM25 first, invoking vector search only as a bounded fallback.BrainSynapsetracks 3D Q-values and separates agent faults from infra faults (ADR-0011, ADR-0018). - Zero-Trust Capability Attenuation: No agent holds ambient privileges.
ContextRouterstripsContextTokenpermissions per graph node from the project manifest; gRPC interceptors and PostgreSQL Row-Level Security (RLS) enforce tenant and project isolation fail-closed (ADR-0017). - Pass-by-Reference & Encrypted Offload: Inter-service calls pass lightweight UUID pointers rather than megabytes of raw prompts; large or sensitive artifacts offload under Shield envelope encryption (ADR-0004, ADR-0015).
- Graceful Degradation (
PATH LβPATH T): Same manifest, same SDK methods, same payloads, same tests β from a single laptop to a production cluster (ADR-0016):
| Layer | Local Loopback (PATH L) | Production Cluster (PATH T) |
|---|---|---|
Memory (ContextBrain) | SQLite + optional sqlite-vec | PostgreSQL + pgvector + RLS |
Execution (ContextWorker) | Huey / in-process durable runner | Temporal Server |
| Service Discovery | In-memory / loopback | Redis + gRPC |
Security (ContextShield) | Local HMAC / dev signer | Ed25519 / KMS + mTLS + ShieldVault PG |
5-Minute Quickstartπ
Requires Python 3.13+ and uv.
# 1. Clone and install all workspace packages
git clone https://github.com/ContextUnity/contextunity.git
cd contextunity
uv sync --all-packages
# 2. Install local Git quality hooks (pre-commit + pre-push)
./scripts/install-hooks.sh
# 3. Mint local development keys (via mise, or set env vars per .env.example)
mise run mint-hmac
mise run mint-shield
# 4. Boot the full local loopback mesh (Router, Brain, Worker, Shield, Forge)
uv run contextunity local upConnecting a Project (contextunity.project.yaml)π
apiVersion: "contextunity/v1alpha8"
project:
id: "my-app"
name: "My Sovereign AI App"
router:
default_graph: "assistant"
config:
models:
llm:
default: "openai/gpt-4o-mini"
graph:
assistant:
template: "local"
nodes:
- name: "responder"
type: "agent"
tools:
- "federated:InventoryToolkit.lookup_sku"Your app connects over the SDK, registers @federated_tool handlers over a BiDi stream, and never exposes internal database credentials to the AI mesh.
Platform Roadmap (0.6 β 0.14 & 0.15+)π
ContextUnity ships as continuous, dependency-ordered lockstep iterations (0.6 β 0.14+) rather than a single monolithic 1.0 cutoff. Every minor release delivers a compact, verifiable vertical slice across coupled services with zero backward release dependencies.
Near-Term Releasesπ
| Release | Focus | What Ships |
|---|---|---|
0.6 (Next) | Hardened Core, Local Brain & Dev Spine | Unified token UUIDs (P-001), secret-safe CLI diagnostics & live BiDi contract (P-101), local CLI provider subscriptions (claude/codex/gemini) & SQL guards (R-103), in-process test harnesses (P-203), Brain Phase-5 receipts, Q-aging & default local embeddings (B-001). |
0.7 | Durable Runtime Spine | Worker CAS-versioned WorkflowRunRecord + ADR-0008 recovery provenance + Huey cron (W-001), ShieldVault PostgreSQL + live secret auth + SecurityAudit (S-001), Ed25519/KMS signer (S-002), service-principal trace artifacts (P-002). |
0.8 | SDK, Live UI & Headless Lab | Lightweight contextunity-sdk + umbrella pip install contextunity metapackage (P-205), AG-UI/A2UI protocol alignment (P-204), Headless Lab CLI/lab:// MCP memory kernel (B-101), Forge Graph Journey / UDB / Lineage views (F-001) & ForgeLibrarian (F-101). |
0.9 | Dynamic DAGs, Channels & ACP | Stateless LangGraph 1.2 inline/durable Task DAGs, type: parallel batch nodes & BlackboardSticker admission (R-201), bidirectional channel connectors + Telegram adapter (R-202), ACP coding-graph adapter (R-203), RouterArchitect with Immune Memory Recall & "verifier" role (R-301). |
Subsequent Track (0.10 β 0.14)π
0.10β Citadel Effects, Tenancy & Constitution: Paired Shield Effect Authorization &ADR-0015encrypted offload (S-101), multi-tenant lifecycle &tenantCLI (S-301),WorkerStrongmanheavy-job budgets (W-101), ShieldConstitutionAST gate + non-configurableHarmlessInvariantfloor (S-202).0.11β Sandboxed Execution, Eval Gates & Audit: O(1) KEK shadow-swap rotation & signed_audit(S-201), Shield admin CLI + OTLP audit export (S-102), ephemeral LinuxWorkerSandmansandbox (W-102),WorkerTestMan/WorkerAuditor(W-201), autonomous candidate pipelines (W-202).0.12β Forge HITL, Economics & Governed Memory: Forge Security/Tenant & Worker/TestMan views + Review Queues emitting Brain outcome feedback (F-201), Router token economics reconciliation (R-401),DualGating+ first-classno-changestates +Memory Linter(B-201), Supervised Lab Mode & HITL policy sync (F-202).0.13β Adaptive Memory, Backups & Path RLS: DerivedContextRank, durable Procedure auto-recall & default-offepsilon-greedyexploration (B-202), encryptedContextSnapshot/v1backup/restore drills (B-301), Engram path-scope PostgreSQL RLS isolation (B-402).0.14β Portability, Compression & Prod Parity: Production TOONContextProjection&EngramIndexpinning (R-501), signedContextSeeduniversal packages & local-first Registry (B-501), bidirectional SQLite β PostgreSQL migration (B-502), verified multi-owner tenant retirement & legal holds (S-302), and live no-mocksPATH L/PATH Tparity &p95baseline gate (P-110).
Evolutionary Horizon (0.15+)π
Long-term research tracks live in docs/plans/backlog/: TeacherβStudent RLM & LoRA hot-swapping, wire-level CodecNegotiation (Immutable Envelope / Mutable Payload), Dialectic depth-escalating retrieval & Spreading Activation, inter-agent Peer Representations, ContextStorage CRDT edge sync, WireGuard/Tailscale P2P mesh, and M2M Economy / Temporal Escrow.
π Read the full narrative in docs/roadmap.md or inspect all 39 executable milestone specs in docs/milestones/.
Where the Documentation Livesπ
| Resource | Location | What You'll Find |
|---|---|---|
| Documentation Website | contextunity.com/docs | Searchable guides, Manifesto, service deep dives, and synced architecture docs. |
| ACDD Spec-Driven Engine | acdd.contextunity.com | The open-source spec, code-map, and verification workflow powering this repo. |
| Architecture & Contracts | docs/architecture/ | Service boundaries, ContextUnit protocol, L0βL4 type boundaries, security model, local/prod parity. |
| ADRs | docs/adr/ | Accepted Architecture Decision Records (ADR-0001 through ADR-0019). |
| Live Milestones & Backlog | docs/milestones/ Β· docs/plans/backlog/ | Executable ACDD milestone contracts (0.6 β 0.14) and 0.15+ research specs. |
| Testing & Quality Gates | TESTS.md Β· docs/testing/independent-review.md | Test taxonomy, markers, in-proc vs live suites, and review criteria. |
| Release & Lockstep Versioning | docs/development/release.md | Lockstep v0.X.Y release process across all workspace packages on PyPI. |
Contributing & Communityπ
We welcome contributors β whether you are fixing a bug, improving docs, adding a model/channel adapter, or tackling a milestone in docs/milestones/.
Development Workflow & Quality Barπ
ContextUnity enforces strict, automated engineering gates so every PR stays clean and verifiable:
- Fork & install workspace + hooks:
uv sync --all-packages ./scripts/install-hooks.sh - Run local quality gates before opening a PR:
# Lint & strict typing (0 errors required) uv run ruff check packages/ services/ scripts/ tests/ uv run basedpyright --level error # Changed-owner lightweight test suite (same gate as pre-push hook) python3 scripts/test_gate.py pre-push # Regenerate protobuf stubs when editing packages/core/protos/ uv run python scripts/build_protos.py - Run ACDD architectural linting & keep AI-assisted coding predictable:
- ContextUnity uses ACDD (
.acdd/lint/zones.yaml,.acdd/lint/rules.yaml, and executable inline```acdd-ruleblocks in architecture docs) to enforce module isolation, graph boundaries, AST security guards, and doc-to-code symbol integrity so both human and AI contributors operate against machine-checked contracts rather than implicit conventions:# Validate manifests, lint rules, and documentation links/invariants acdd validate && acdd docs check && acdd lint --categories arch,docs - Before making architectural or cross-module edits, inspect dependencies and invariants via
acdd query overview|search|inspect|impact(or the ACDD MCP tools).
- ContextUnity uses ACDD (
- Follow repository contracts:
- All shared JSON/gRPC contracts live in
contextunity.core(type-boundaries.md). - Never bypass tenant/project isolation or introduce silent
except Exceptionswallows (delivery-readiness.md). - Include focused regression tests covering both happy and fail-closed paths (TESTS.md).
- For AI-assisted contributors, follow
AGENTS.mdanddocs/AGENTS.mdfor ACDD workflow conventions, verified symbol links, and canonicalINV-*:invariants.
- All shared JSON/gRPC contracts live in
Issues, Ideas & Securityπ
- Bugs & Feature Requests: Open a ticket on GitHub Issues.
- Roadmap & Architecture Discussions: Check
docs/milestones/anddocs/adr/before proposing large structural changes. - Security Vulnerabilities: Please report security issues privately via GitHub Security Advisories rather than posting exploit details in public issues.
Licenseπ
Licensed under the Apache License 2.0 β see LICENSE for full terms.