Neural Context Protocol (NCP): bounded, persistent context for multi-agent pipelines.
Project description
Neural Context Protocol
Your pipeline grows. Your context shouldn't.
Multi-agent pipelines compound. Every turn, the model re-reads growing history it mostly doesn't need. By turn 50 you're replaying 80,000 tokens of context to do 840 tokens of useful work.
NCP fixes this by replacing full-history replay with a bounded, trust-weighted working memory that stays flat as your pipeline deepens.
Turn 10: raw replay → 12,000 tok NCP → ~840 tok
Turn 30: raw replay → 45,000 tok NCP → ~840 tok
Turn 50: raw replay → 80,000 tok NCP → ~840 tok ← bounded
17.52x fewer tokens. Same pipeline depth. Reproducible.
Quickstart
pip install neural-context-protocol
ncp init
ncp serve --host 127.0.0.1 --port 4242 --cwd /path/to/project
For Claude Code:
cp examples/06_claude_code/mcp_servers.json .mcp.json
See examples/06_claude_code/README.md.
For Codex CLI, copy examples/07_codex_cli/mcp_servers.json into your Codex MCP config location.
See examples/07_codex_cli/README.md.
ncp init creates .ncp/config.toml and a CLAUDE.md turn contract in the project root.
How It Works
Instead of replaying a growing transcript, NCP assembles a bounded context from three blocks every turn:
[NCP:CONSCIOUS] ~120 tok — what this agent knows right now
[NCP:SUBCONSCIOUS] ~480 tok — relevant past, retrieved not replayed
[NCP:WHISPERS] ~240 tok — bounded signals from other agents
─────────────────────────────────────────────────────────────────
Total: ~840 tok — stays bounded as the pipeline deepens
Memory survives restarts. The same runtime serves multiple hosts against the same store. Agents coordinate through bounded whispers without stuffing prompts.
Turn Flow
flowchart TD
A["Host calls ncp_get_context"]
B["Assembler loads conscious state"]
C["Resolve recent refs"]
D["Retrieve top relevant chunks"]
E["Drain bounded whispers"]
F["Assemble bounded context"]
G["Host runs provider turn"]
H["Host persists durable memory"]
A --> B --> C --> D --> E --> F --> G --> H
Architecture
flowchart LR
A["Claude / Codex / OpenCode / other MCP hosts"]
B["ncp serve<br/>HTTP/SSE MCP runtime"]
C["Assembler<br/>bounded context + retrieval"]
D["SQLite mode<br/>local-first store"]
E["pgvector mode<br/>durable memory"]
F["Redis<br/>whispers + fetch-session state"]
A --> B
B --> C
C --> D
C --> E
C --> F
Context Trust
Most frameworks treat stored context as equally credible. NCP doesn't.
Every memory chunk carries a base_trust score and a written_at_drift marker. Retrieval scoring discounts chunks written during high-drift periods. The CoherenceChecker monitors per-turn drift_score and fires alerts when agents start diverging. Agents emit world_check whispers to report detected drift back into the runtime.
ChunkSource: user_verified | tool_result | agent_inferred | synthesis
base_trust: float (0.0–1.0) — weight applied at retrieval time
drift_score: float (0.0–1.0) — pipeline coherence, updated per turn
written_at_drift: float — drift level when this memory was written
The effect: the model receives context ranked by how much it should believe it, not just by recency.
What NCP Is (and Isn't)
NCP is the memory bus, not the orchestrator.
It sits underneath your existing agent framework — LangGraph, CrewAI, AutoGen, or a custom orchestrator — and gives every connected host the same bounded, trust-weighted working memory. Bring your own orchestrator. Bring your own agents.
It is not a vector database. Not a model training framework. Not an orchestrator. Not the right default for simple single-agent or very short-lived tasks.
Use it when you have 3+ agents, 10+ turns, and real shared state to preserve.
Benchmarks
| Scenario | Baseline | Baseline tokens | NCP tokens | Reduction |
|---|---|---|---|---|
| 4-agent coding pipeline (40 turns) | raw replay | 1,927 | 174 | 17.52x |
| 4-agent coding pipeline (40 turns) | rolling summary | 1,176 | 174 | 10.69x |
| 6-role research pipeline (36 turns) | raw replay | 1,700 | 156 | 16.35x |
| Cross-host handoff (Claude → OpenCode) | window baseline | 0.0 success | 0.8 success | +0.8 |
| Needle recall at budget 4 | sliding window | 0.00 | 0.50 | +0.50 |
MACE multi-agent coordination score (40 turns): 0.9608
Benchmarks are reproducible:
python3 benchmarks/coding_pipeline/run.py
python3 benchmarks/needle/run.py --turns 24 --needles 6 --budget 4
Core Tool Surface
NCP exposes one MCP endpoint: http://127.0.0.1:4242/mcp
ncp_get_context — assemble bounded context for this turn
ncp_write_memory — persist durable memory to the subconscious
ncp_fetch — retrieve a prior turn result by ID
ncp_emit_whisper — send a bounded signal to another agent
Storage Tiers
| Tier | When to use | Backing |
|---|---|---|
| SQLite | Default. Zero extra services. | .ncp/store.db |
| pgvector | Durable semantic retrieval across machines. | Postgres + pgvector |
| Redis | Cross-agent coordination, whispers, fetch-session state. | Redis 7 |
Start with SQLite. Add pgvector and Redis when you need richer retrieval or multiple agents coordinating across processes.
Managed local Postgres + Redis from an installed CLI:
pip install 'neural-context-protocol[pgvector,redis]'
ncp init --store pgvector
ncp infra up
ncp serve --host 127.0.0.1 --port 4242 --cwd /path/to/project
Bring your own Postgres + Redis:
pip install 'neural-context-protocol[pgvector,redis]'
ncp init --store pgvector
ncp migrate apply --cwd /path/to/project
ncp serve --host 127.0.0.1 --port 4242 --cwd /path/to/project
Operator Commands
ncp status # store and activity metrics
ncp cost # token and USD rollups
ncp explain # human-readable runtime summary
ncp viz # pipeline visualization
ncp consolidate # merge and compact memory
ncp calibrate # recalibrate trust and retrieval weights
ncp handoff # cross-agent handoff coordination
ncp batch # process a JSONL file of NCP operations
Cross-Agent Handoffs
ncp handoff claude --cwd /path/to/project --pipeline-id pipe_demo --emit-to opencode
ncp handoff opencode --cwd /path/to/project --pipeline-id pipe_demo --emit-to claude
Verify Setup
ncp status --cwd /path/to/project
ncp cost --cwd /path/to/project
ncp explain --cwd /path/to/project
ncp statusshows store and activity metrics.ncp costshows token and USD rollups once turns are logged.ncp explaingives a human-readable runtime summary.
Examples
Runnable examples in the repo:
python3 examples/01_quickstart.py
python3 examples/02_multi_agent.py
Tool-specific setup lives in:
In Our Own Pipelines
NCP is the memory bus. In our workflows, Sarathi is one orchestrator that runs on top of it. Sarathi is an integration example, not a requirement — NCP works under any MCP-compatible host.
Documentation
- Setup guide
- Protocol spec
- Benchmark: coding pipeline
- Benchmark: needle recall
- Benchmark: matched-budget efficacy
- Benchmark: research pipeline
- MACE multi-agent eval
- Post-V1 roadmap
- Active handoff packet
- CHANGELOG
NCP is MIT licensed. Built by @kulkarni2u.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file neural_context_protocol-1.0.4.tar.gz.
File metadata
- Download URL: neural_context_protocol-1.0.4.tar.gz
- Upload date:
- Size: 205.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
186daa25230aaf14ed9bc00ecb9e0d673bbde14341b0cd35922d4abb7d19db17
|
|
| MD5 |
141a5f193cbb0104527ea9c9113df1d6
|
|
| BLAKE2b-256 |
20c12f74f020b0428f13a75666d775a97089d61dad6516c7c41768ebe44bf1bb
|
Provenance
The following attestation bundles were made for neural_context_protocol-1.0.4.tar.gz:
Publisher:
release.yml on kulkarni2u/neural-context-protocol
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
neural_context_protocol-1.0.4.tar.gz -
Subject digest:
186daa25230aaf14ed9bc00ecb9e0d673bbde14341b0cd35922d4abb7d19db17 - Sigstore transparency entry: 1741891650
- Sigstore integration time:
-
Permalink:
kulkarni2u/neural-context-protocol@6a9baaae5b723ad9e348b460c9ee31a5bba9cdd2 -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/kulkarni2u
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6a9baaae5b723ad9e348b460c9ee31a5bba9cdd2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file neural_context_protocol-1.0.4-py3-none-any.whl.
File metadata
- Download URL: neural_context_protocol-1.0.4-py3-none-any.whl
- Upload date:
- Size: 133.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6dcad170e2e603734abbe3592495077cc84bcf211eb8cb78728881e66a979a33
|
|
| MD5 |
f75b9c322c9f25aa8600b218775e0bac
|
|
| BLAKE2b-256 |
6c872240c64224acaaaf77086e18ec1d4b065734cc3c0bb7c06ee795e2c69799
|
Provenance
The following attestation bundles were made for neural_context_protocol-1.0.4-py3-none-any.whl:
Publisher:
release.yml on kulkarni2u/neural-context-protocol
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
neural_context_protocol-1.0.4-py3-none-any.whl -
Subject digest:
6dcad170e2e603734abbe3592495077cc84bcf211eb8cb78728881e66a979a33 - Sigstore transparency entry: 1741891684
- Sigstore integration time:
-
Permalink:
kulkarni2u/neural-context-protocol@6a9baaae5b723ad9e348b460c9ee31a5bba9cdd2 -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/kulkarni2u
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6a9baaae5b723ad9e348b460c9ee31a5bba9cdd2 -
Trigger Event:
push
-
Statement type: