synapse-layer 1.2.0__tar.gz → 2.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- synapse_layer-2.3.0/PKG-INFO +688 -0
- synapse_layer-2.3.0/README.md +665 -0
- synapse_layer-2.3.0/pyproject.toml +38 -0
- synapse_layer-2.3.0/synapse_layer/__init__.py +13 -0
- synapse_layer-2.3.0/synapse_layer/a2a_client.py +337 -0
- synapse_layer-2.3.0/synapse_layer/crewai_tools.py +432 -0
- synapse_layer-2.3.0/synapse_layer/langchain_memory.py +281 -0
- synapse_layer-2.3.0/synapse_layer/plugins/__init__.py +8 -0
- synapse_layer-2.3.0/synapse_layer/plugins/base.py +153 -0
- synapse_layer-2.3.0/synapse_layer/plugins/medical_resolver.py +137 -0
- synapse_layer-2.3.0/synapse_layer.egg-info/PKG-INFO +688 -0
- synapse_layer-2.3.0/synapse_layer.egg-info/SOURCES.txt +14 -0
- synapse_layer-2.3.0/synapse_layer.egg-info/requires.txt +8 -0
- synapse_layer-2.3.0/synapse_layer.egg-info/top_level.txt +1 -0
- synapse_layer-1.2.0/LICENSE +0 -201
- synapse_layer-1.2.0/PKG-INFO +0 -377
- synapse_layer-1.2.0/README.md +0 -327
- synapse_layer-1.2.0/pyproject.toml +0 -108
- synapse_layer-1.2.0/synapse_layer/__init__.py +0 -24
- synapse_layer-1.2.0/synapse_layer.egg-info/PKG-INFO +0 -377
- synapse_layer-1.2.0/synapse_layer.egg-info/SOURCES.txt +0 -92
- synapse_layer-1.2.0/synapse_layer.egg-info/requires.txt +0 -28
- synapse_layer-1.2.0/synapse_layer.egg-info/top_level.txt +0 -2
- synapse_layer-1.2.0/synapse_memory/__init__.py +0 -127
- synapse_layer-1.2.0/synapse_memory/autosave/__init__.py +0 -29
- synapse_layer-1.2.0/synapse_memory/autosave/engine.py +0 -380
- synapse_layer-1.2.0/synapse_memory/autosave/formatter.py +0 -54
- synapse_layer-1.2.0/synapse_memory/autosave/policy.py +0 -223
- synapse_layer-1.2.0/synapse_memory/autosave/triggers.py +0 -235
- synapse_layer-1.2.0/synapse_memory/autosave/types.py +0 -72
- synapse_layer-1.2.0/synapse_memory/backends/__init__.py +0 -34
- synapse_layer-1.2.0/synapse_memory/backends/forge_backend.py +0 -661
- synapse_layer-1.2.0/synapse_memory/backends/interface.py +0 -73
- synapse_layer-1.2.0/synapse_memory/backends/memory_backend.py +0 -90
- synapse_layer-1.2.0/synapse_memory/backends/sqlite_backend.py +0 -226
- synapse_layer-1.2.0/synapse_memory/client.py +0 -269
- synapse_layer-1.2.0/synapse_memory/core.py +0 -591
- synapse_layer-1.2.0/synapse_memory/crypto/__init__.py +0 -25
- synapse_layer-1.2.0/synapse_memory/crypto/aes.py +0 -197
- synapse_layer-1.2.0/synapse_memory/embeddings.py +0 -148
- synapse_layer-1.2.0/synapse_memory/engine/__init__.py +0 -29
- synapse_layer-1.2.0/synapse_memory/engine/handover.py +0 -936
- synapse_layer-1.2.0/synapse_memory/engine/validator.py +0 -526
- synapse_layer-1.2.0/synapse_memory/exceptions.py +0 -70
- synapse_layer-1.2.0/synapse_memory/integrations/__init__.py +0 -51
- synapse_layer-1.2.0/synapse_memory/integrations/autogen_memory.py +0 -242
- synapse_layer-1.2.0/synapse_memory/integrations/crewai_memory.py +0 -456
- synapse_layer-1.2.0/synapse_memory/integrations/langchain_memory.py +0 -254
- synapse_layer-1.2.0/synapse_memory/integrations/llamaindex.py +0 -355
- synapse_layer-1.2.0/synapse_memory/integrations/semantic_kernel.py +0 -453
- synapse_layer-1.2.0/synapse_memory/plugins/__init__.py +0 -46
- synapse_layer-1.2.0/synapse_memory/plugins/defaults.py +0 -80
- synapse_layer-1.2.0/synapse_memory/plugins/interfaces.py +0 -156
- synapse_layer-1.2.0/synapse_memory/plugins/plugin_loader.py +0 -75
- synapse_layer-1.2.0/synapse_memory/privacy.py +0 -167
- synapse_layer-1.2.0/synapse_memory/router.py +0 -205
- synapse_layer-1.2.0/synapse_memory/sanitizer.py +0 -295
- synapse_layer-1.2.0/synapse_memory/wrapper.py +0 -270
- synapse_layer-1.2.0/tests/test_autosave.py +0 -596
- synapse_layer-1.2.0/tests/test_backends.py +0 -208
- synapse_layer-1.2.0/tests/test_core_integration.py +0 -336
- synapse_layer-1.2.0/tests/test_coverage_boost.py +0 -394
- synapse_layer-1.2.0/tests/test_crypto.py +0 -145
- synapse_layer-1.2.0/tests/test_forge_backend.py +0 -458
- synapse_layer-1.2.0/tests/test_handover.py +0 -268
- synapse_layer-1.2.0/tests/test_plugin_architecture.py +0 -527
- synapse_layer-1.2.0/tests/test_privacy.py +0 -155
- synapse_layer-1.2.0/tests/test_sanitizer.py +0 -251
- synapse_layer-1.2.0/tests/test_validator.py +0 -207
- synapse_layer-1.2.0/tests/test_wrapper.py +0 -90
- {synapse_layer-1.2.0 → synapse_layer-2.3.0}/setup.cfg +0 -0
- {synapse_layer-1.2.0 → synapse_layer-2.3.0}/synapse_layer.egg-info/dependency_links.txt +0 -0
|
@@ -0,0 +1,688 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: synapse-layer
|
|
3
|
+
Version: 2.3.0
|
|
4
|
+
Summary: Universal memory layer for AI agents - Persistent, Private, Model-agnostic
|
|
5
|
+
Author-email: Synapse Layer <founder.synapselayer@proton.me>
|
|
6
|
+
Project-URL: Homepage, https://synapselayer.org
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/SynapseLayer/synapse-sdk-python/issues
|
|
8
|
+
Project-URL: Documentation, https://synapselayer.org/docs
|
|
9
|
+
Project-URL: Repository, https://github.com/SynapseLayer/synapse-sdk-python
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
Requires-Dist: requests>=2.25.0
|
|
18
|
+
Requires-Dist: pydantic>=2.0.0
|
|
19
|
+
Provides-Extra: langchain
|
|
20
|
+
Requires-Dist: langchain-core>=0.1.0; extra == "langchain"
|
|
21
|
+
Provides-Extra: crewai
|
|
22
|
+
Requires-Dist: crewai>=0.1.0; extra == "crewai"
|
|
23
|
+
|
|
24
|
+
# 🧠 Synapse Layer
|
|
25
|
+
|
|
26
|
+
[](https://pypi.org/project/synapse-layer/)
|
|
27
|
+
[](./site/docs/sdk/a2a-protocol.md)
|
|
28
|
+
[](https://modelcontextprotocol.io/)
|
|
29
|
+
[](./site/docs/sdk/python.md)
|
|
30
|
+
[](./site/docs/sdk/python.md)
|
|
31
|
+
[](./LICENSE)
|
|
32
|
+
[](./sdk/python/tests/)
|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
> *"Giving Agents a Past. Giving Models a Soul."*
|
|
36
|
+
|
|
37
|
+
**The Long-Term Memory Layer for Every Agent.**
|
|
38
|
+
Persistent · Private · Model-agnostic · Open-source
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## What It Does
|
|
43
|
+
|
|
44
|
+
Synapse Layer gives AI agents a persistent, encrypted memory system that works across models and sessions:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
48
|
+
│ AGENT SESSION 1 │
|
|
49
|
+
│ (Claude 3.5 Sonnet) │
|
|
50
|
+
│ │
|
|
51
|
+
│ User: "I prefer Portuguese and dark mode" ────────────┐ │
|
|
52
|
+
│ Agent: "Noted. Storing in memory..." │ │
|
|
53
|
+
└──────────────────────────────────────────────────────────┼──┘
|
|
54
|
+
│
|
|
55
|
+
┌────────────────────────────┘
|
|
56
|
+
│
|
|
57
|
+
▼
|
|
58
|
+
┌───────────────────────┐
|
|
59
|
+
│ SYNAPSE LAYER VAULT │
|
|
60
|
+
│ │
|
|
61
|
+
│ ✓ AES-256-GCM │
|
|
62
|
+
│ ✓ Zero-Knowledge │
|
|
63
|
+
│ ✓ TQ: 0.95 │
|
|
64
|
+
└───────────────────────┘
|
|
65
|
+
│
|
|
66
|
+
│
|
|
67
|
+
┌───────────┴────────────┐
|
|
68
|
+
│ │
|
|
69
|
+
▼ ▼
|
|
70
|
+
┌──────────────────────┐ ┌──────────────────────┐
|
|
71
|
+
│ SESSION 2 │ │ SESSION 3 │
|
|
72
|
+
│ (GPT-4o) │ │ (Gemini) │
|
|
73
|
+
│ │ │ │
|
|
74
|
+
│ Agent recalled: │ │ Agent recalled: │
|
|
75
|
+
│ "Dark mode ✓" │ │ "Portuguese ✓" │
|
|
76
|
+
│ "PT-BR ✓" │ │ "Dark mode ✓" │
|
|
77
|
+
└──────────────────────┘ └──────────────────────┘
|
|
78
|
+
|
|
79
|
+
CONTINUOUS CONTEXT ACROSS MODELS
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Features
|
|
85
|
+
|
|
86
|
+
| Feature | Description | Status |
|
|
87
|
+
|---------|-------------|--------|
|
|
88
|
+
| **Zero-Knowledge Encryption** | AES-256-GCM, client-side only; server never sees plaintext | ✅ v0.7.0 |
|
|
89
|
+
| **Python SDK** | Async client with LangChain & CrewAI adapters | ✅ v0.7.0 |
|
|
90
|
+
| **A2A Protocol v1.0** | JSON-RPC 2.0 for agent-to-agent communication | ✅ v0.7.0 |
|
|
91
|
+
| **Neural Handover™** | HMAC-SHA256 signed context transfer between models | ✅ v0.6.0 |
|
|
92
|
+
| **Trust Quotient (TQ)** | Weighted memory ranking formula (confidence + recency + usage) | ✅ v0.7.0 |
|
|
93
|
+
| **Semantic Search** | pgvector HNSW for intelligent memory recall | ✅ v0.6.0 |
|
|
94
|
+
| **Conflict Resolution** | Automatic detection & resolution of contradictory memories | ✅ v0.6.0 |
|
|
95
|
+
| **GDPR/LGPD Compliant** | Soft-delete with audit trails; data minimization | ✅ v0.6.0 |
|
|
96
|
+
| **MCP Compatible** | Works with Claude, LLaMA, and any MCP client | ✅ v0.6.0 |
|
|
97
|
+
| **Open Source** | Apache 2.0 license | ✅ v0.1.0 |
|
|
98
|
+
| **Plugin System** | Extensible resolvers for domain-specific conflict resolution | ✅ v1.0.0 |
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Plugin System
|
|
103
|
+
|
|
104
|
+
Synapse Layer v1.0.0 introduces an extensible **Plugin System** for domain-specific conflict resolution and memory validation.
|
|
105
|
+
|
|
106
|
+
### Core Components
|
|
107
|
+
|
|
108
|
+
**MemoryResolverPlugin** - Abstract base class for plugins:
|
|
109
|
+
```python
|
|
110
|
+
from synapse_layer.plugins import MemoryResolverPlugin, MemoryCandidate, ResolverDecision
|
|
111
|
+
|
|
112
|
+
class MyCustomResolver(MemoryResolverPlugin):
|
|
113
|
+
@property
|
|
114
|
+
def name(self) -> str:
|
|
115
|
+
return "my_resolver"
|
|
116
|
+
|
|
117
|
+
def can_handle(self, candidates: List[MemoryCandidate]) -> bool:
|
|
118
|
+
# Return True if this plugin should handle these candidates
|
|
119
|
+
return any("custom_tag" in c.metadata for c in candidates)
|
|
120
|
+
|
|
121
|
+
def resolve(self, candidates: List[MemoryCandidate]) -> ResolverDecision:
|
|
122
|
+
# Your domain-specific logic here
|
|
123
|
+
return ResolverDecision(winner_memory_id=candidates[0].memory_id)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**PluginRegistry** - Global registry for plugin management:
|
|
127
|
+
```python
|
|
128
|
+
from synapse_layer.plugins import default_registry, MyCustomResolver
|
|
129
|
+
|
|
130
|
+
# Register plugin
|
|
131
|
+
default_registry.register(MyCustomResolver())
|
|
132
|
+
|
|
133
|
+
# Find handler for conflict resolution
|
|
134
|
+
plugin = default_registry.find_handler(candidates)
|
|
135
|
+
if plugin:
|
|
136
|
+
decision = plugin.resolve(candidates)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Example: MedicalTruthResolver
|
|
140
|
+
|
|
141
|
+
Included with Synapse Layer is the **MedicalTruthResolver** plugin, which validates medical/clinical memories using source priority:
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
Priority Order:
|
|
145
|
+
1. Peer-reviewed literature (highest)
|
|
146
|
+
2. Clinical guidelines
|
|
147
|
+
3. Specialist notes
|
|
148
|
+
4. General knowledge
|
|
149
|
+
5. Patient self-reports (lowest)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
When medical memories conflict, the plugin automatically promotes the highest-priority source.
|
|
153
|
+
|
|
154
|
+
### synapse.json — Protocol Manifest
|
|
155
|
+
|
|
156
|
+
Synapse Layer exposes a machine-readable `synapse.json` file at the repository root, listing all capabilities:
|
|
157
|
+
|
|
158
|
+
```json
|
|
159
|
+
{
|
|
160
|
+
"protocol": "synapse-layer",
|
|
161
|
+
"version": "1.0.0",
|
|
162
|
+
"capabilities": [
|
|
163
|
+
"persistent_memory",
|
|
164
|
+
"neural_handover",
|
|
165
|
+
"conflict_resolution",
|
|
166
|
+
"plugin_system",
|
|
167
|
+
"zero_knowledge_context"
|
|
168
|
+
],
|
|
169
|
+
"docs": "https://synapselayer.org/docs"
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Agents can discover and validate Synapse Layer capabilities by reading this file.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Installation
|
|
178
|
+
|
|
179
|
+
> **Status:** Pre-release. PyPI and npm packages are coming soon (v1.0.0 stable release).
|
|
180
|
+
> In the meantime, install directly from the repository.
|
|
181
|
+
|
|
182
|
+
### Python SDK (pre-release)
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
# Install directly from GitHub (works today)
|
|
186
|
+
pip install "synapse-layer[langchain] @ git+https://github.com/SynapseLayer/synapse-sdk-python.git"
|
|
187
|
+
|
|
188
|
+
# Or clone and install locally
|
|
189
|
+
git clone https://github.com/SynapseLayer/synapse-sdk-python.git
|
|
190
|
+
cd synapse-sdk-python
|
|
191
|
+
pip install -e ".[langchain,crewai]"
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Coming soon (stable):
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
pip install synapse-layer
|
|
198
|
+
pip install synapse-layer[langchain]
|
|
199
|
+
pip install synapse-layer[crewai]
|
|
200
|
+
pip install synapse-layer[all]
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### CLI (pre-release)
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# Install directly from GitHub (works today)
|
|
207
|
+
npm install -g github:SynapseLayer/synapse-cli
|
|
208
|
+
|
|
209
|
+
# Or clone and link locally
|
|
210
|
+
git clone https://github.com/SynapseLayer/synapse-cli.git
|
|
211
|
+
cd synapse-cli
|
|
212
|
+
npm install && npm link
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Coming soon (stable):
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
npm install -g @synapselayer/cli
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### MCP Server (production — live today)
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
# Edge Function (no install needed)
|
|
225
|
+
# Endpoint: https://rbeycxzizrrdmxpilepc.supabase.co/functions/v1/mcp-server
|
|
226
|
+
|
|
227
|
+
# Local MCP Server
|
|
228
|
+
# MCP Server source is distributed separately — see synapselayer.org/docs
|
|
229
|
+
# (consult official docs for setup)
|
|
230
|
+
npm install
|
|
231
|
+
npx ts-node src/mcp-server.ts
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## Quick Start
|
|
237
|
+
|
|
238
|
+
### Python SDK (Async)
|
|
239
|
+
|
|
240
|
+
```python
|
|
241
|
+
import asyncio
|
|
242
|
+
from synapse_layer import SynapseA2AClient
|
|
243
|
+
|
|
244
|
+
async def main():
|
|
245
|
+
client = SynapseA2AClient(api_key="your-api-key")
|
|
246
|
+
|
|
247
|
+
async with client:
|
|
248
|
+
# Store a memory
|
|
249
|
+
result = await client.store_memory(
|
|
250
|
+
user_id="user-123",
|
|
251
|
+
content="User prefers Portuguese language",
|
|
252
|
+
source_type="user_input",
|
|
253
|
+
confidence=0.95
|
|
254
|
+
)
|
|
255
|
+
print(f"Stored: {result.task_id}")
|
|
256
|
+
|
|
257
|
+
# Recall memories
|
|
258
|
+
recalled = await client.recall_memory(
|
|
259
|
+
user_id="user-123",
|
|
260
|
+
query="language preference",
|
|
261
|
+
limit=5
|
|
262
|
+
)
|
|
263
|
+
print(f"Found {len(recalled.output)} memories")
|
|
264
|
+
|
|
265
|
+
asyncio.run(main())
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### LangChain Integration
|
|
269
|
+
|
|
270
|
+
```python
|
|
271
|
+
from langchain.chains import ConversationChain
|
|
272
|
+
from langchain.llms import Anthropic
|
|
273
|
+
from synapse_layer import SynapseMemory
|
|
274
|
+
|
|
275
|
+
# Create persistent memory
|
|
276
|
+
memory = SynapseMemory(
|
|
277
|
+
api_key="your-api-key",
|
|
278
|
+
user_id="user-001",
|
|
279
|
+
recall_limit=10
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
# Use in conversation
|
|
283
|
+
chain = ConversationChain(
|
|
284
|
+
llm=Anthropic(),
|
|
285
|
+
memory=memory,
|
|
286
|
+
verbose=True
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
response = chain.run(input="What did I tell you last week?")
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### CrewAI Integration
|
|
293
|
+
|
|
294
|
+
```python
|
|
295
|
+
from crewai import Agent, Task, Crew
|
|
296
|
+
from synapse_layer import (
|
|
297
|
+
SynapseStoreMemoryTool,
|
|
298
|
+
SynapseRecallMemoryTool,
|
|
299
|
+
SynapseHandoverTool
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
# Create tools
|
|
303
|
+
store = SynapseStoreMemoryTool(api_key="your-api-key")
|
|
304
|
+
recall = SynapseRecallMemoryTool(api_key="your-api-key")
|
|
305
|
+
handover = SynapseHandoverTool(api_key="your-api-key")
|
|
306
|
+
|
|
307
|
+
# Create agent
|
|
308
|
+
researcher = Agent(
|
|
309
|
+
role="Researcher",
|
|
310
|
+
goal="Gather and store findings",
|
|
311
|
+
tools=[store, recall, handover]
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
# Run crew
|
|
315
|
+
crew = Crew(agents=[researcher], tasks=[...])
|
|
316
|
+
crew.kickoff()
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## Trust Quotient (TQ) Formula
|
|
322
|
+
|
|
323
|
+
Memory quality is determined by a **weighted composite score** that combines three dimensions:
|
|
324
|
+
|
|
325
|
+
TQ = (confidence_score * 0.4) + (recency_score * 0.3) + (usage_normalized * 0.3)
|
|
326
|
+
|
|
327
|
+
### Breakdown
|
|
328
|
+
|
|
329
|
+
| Component | Weight | Description |
|
|
330
|
+
|-----------|--------|-------------|
|
|
331
|
+
| **confidence_score** | 40% | User-provided confidence (0.0-1.0) |
|
|
332
|
+
| **recency_score** | 30% | Time-decay based on age; newer = higher |
|
|
333
|
+
| **usage_normalized** | 30% | Normalized access frequency |
|
|
334
|
+
|
|
335
|
+
### Example: High vs Low TQ
|
|
336
|
+
|
|
337
|
+
**High TQ Memory:**
|
|
338
|
+
```
|
|
339
|
+
"User purchased premium plan on 2026-04-01"
|
|
340
|
+
- confidence = 0.99 (API response)
|
|
341
|
+
- recency = 0.99 (stored today)
|
|
342
|
+
- usage = 0.85 (accessed 17/20 times)
|
|
343
|
+
|
|
344
|
+
TQ = (0.99 * 0.4) + (0.99 * 0.3) + (0.85 * 0.3) = 0.948 (Excellent)
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
**Low TQ Memory:**
|
|
348
|
+
```
|
|
349
|
+
"User might prefer dark mode"
|
|
350
|
+
- confidence = 0.35 (uncertain)
|
|
351
|
+
- recency = 0.18 (60 days old)
|
|
352
|
+
- usage = 0.05 (accessed 1/20 times)
|
|
353
|
+
|
|
354
|
+
TQ = (0.35 * 0.4) + (0.18 * 0.3) + (0.05 * 0.3) = 0.209 (Poor)
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
Memories are ranked by TQ in recall results, ensuring most reliable and relevant memories appear first.
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## Neural Handover™
|
|
362
|
+
|
|
363
|
+
Transfer context between models without losing state:
|
|
364
|
+
|
|
365
|
+
```python
|
|
366
|
+
# Agent A (Claude)
|
|
367
|
+
handover = await client.create_handover(
|
|
368
|
+
user_id="user-123",
|
|
369
|
+
target_model="gpt-4o",
|
|
370
|
+
summary="Analyzed Q3 financial data; found 15% revenue growth"
|
|
371
|
+
)
|
|
372
|
+
# Returns: handover_token (HMAC-SHA256 signed)
|
|
373
|
+
|
|
374
|
+
# Agent B (GPT-4o) - receives context automatically
|
|
375
|
+
# Full context injected via Neural Handover™
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
**How it works:**
|
|
379
|
+
1. Source agent packages context + memories into JSON
|
|
380
|
+
2. Sign with HMAC-SHA256 for integrity
|
|
381
|
+
3. Return handover token
|
|
382
|
+
4. Target agent loads context, validates signature, continues session
|
|
383
|
+
5. No memory loss between models
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
## Architecture
|
|
388
|
+
|
|
389
|
+
```
|
|
390
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
391
|
+
│ CLIENT LAYER │
|
|
392
|
+
│ │
|
|
393
|
+
│ ┌─────────────┐ ┌──────────────┐ ┌──────────────────┐ │
|
|
394
|
+
│ │ Python SDK │ │ TypeScript │ │ Any MCP Client │ │
|
|
395
|
+
│ │ (Async) │ │ SDK │ │ (Claude, etc) │ │
|
|
396
|
+
│ └──────┬──────┘ └──────┬───────┘ └────────┬─────────┘ │
|
|
397
|
+
│ │ │ │ │
|
|
398
|
+
│ └────────────────┼───────────────────┘ │
|
|
399
|
+
│ │ │
|
|
400
|
+
│ ▼ │
|
|
401
|
+
│ ┌────────────────────────┐ │
|
|
402
|
+
│ │ AES-256-GCM Encryption │ │
|
|
403
|
+
│ │ (Client-side only) │ │
|
|
404
|
+
│ └────────────┬───────────┘ │
|
|
405
|
+
└───────────────────────────┼──────────────────────────────────┘
|
|
406
|
+
│ encrypted blobs + embeddings
|
|
407
|
+
▼
|
|
408
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
409
|
+
│ SERVER LAYER │
|
|
410
|
+
│ │
|
|
411
|
+
│ ┌──────────────────────────────────────────────────────┐ │
|
|
412
|
+
│ │ Supabase Edge Functions (A2A Protocol) │ │
|
|
413
|
+
│ │ │ │
|
|
414
|
+
│ │ store_memory | recall_memory | create_handover │ │
|
|
415
|
+
│ │ resolve_conflict | forget_memory │ │
|
|
416
|
+
│ └──────────────────────┬───────────────────────────────┘ │
|
|
417
|
+
│ │ │
|
|
418
|
+
│ ▼ │
|
|
419
|
+
│ ┌──────────────────────────────────────────────────────┐ │
|
|
420
|
+
│ │ PostgreSQL + pgvector (HNSW) │ │
|
|
421
|
+
│ │ Region: sa-east-1 (Sao Paulo) │ │
|
|
422
|
+
│ │ │ │
|
|
423
|
+
│ │ - Encrypted memory blobs (AES-256-GCM) │ │
|
|
424
|
+
│ │ - 384-dim embeddings (semantic search) │ │
|
|
425
|
+
│ │ - Trust Quotient scores (TQ ranking) │ │
|
|
426
|
+
│ │ - Audit trails (GDPR/LGPD compliance) │ │
|
|
427
|
+
│ └──────────────────────────────────────────────────────┘ │
|
|
428
|
+
└──────────────────────────────────────────────────────────────┘
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
---
|
|
432
|
+
## Discovery & Static Files
|
|
433
|
+
|
|
434
|
+
**Discovery files** (agent-card.json, agent.json, etc.) are served from `public/.well-known/`
|
|
435
|
+
by the Next.js static file server. This is the canonical source for all agent discovery endpoints.
|
|
436
|
+
Do not edit `.well-known/` at the repository root — it has been removed to maintain a single source of truth.
|
|
437
|
+
|
|
438
|
+
> **Canonical agent discovery path:** `public/.well-known/agent-card.json`
|
|
439
|
+
> Served at: `https://synapselayer.org/.well-known/agent-card.json`
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
## Core Engine — Trust Quotient (TQ)
|
|
443
|
+
|
|
444
|
+
Every memory in Synapse Layer has a Trust Quotient score that determines its lifecycle.
|
|
445
|
+
|
|
446
|
+
### TQ Formula
|
|
447
|
+
|
|
448
|
+
TQ = (confidence_score * 0.4) + (recency_score * 0.3) + (usage_normalized * 0.3)
|
|
449
|
+
|
|
450
|
+
Where:
|
|
451
|
+
confidence_score in [0.0, 1.0] -- source reliability
|
|
452
|
+
recency_score = 1.0 / (1.0 + ln(days_since_created + 1.0))
|
|
453
|
+
usage_normalized = min(usage_count / 100.0, 1.0)
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
### Memory Lifecycle
|
|
457
|
+
|
|
458
|
+
[CREATED] --> TQ calculated on write
|
|
459
|
+
|
|
|
460
|
+
v
|
|
461
|
+
[ACTIVE] --> TQ >= 0.7: promoted as canonical
|
|
462
|
+
| TQ 0.3-0.7: normal active memory
|
|
463
|
+
| TQ < 0.5: credit decremented daily
|
|
464
|
+
v
|
|
465
|
+
[WEAKENING] --> credit_balance approaches 0
|
|
466
|
+
|
|
|
467
|
+
v
|
|
468
|
+
[DECAYED] --> TQ < 0.3 AND age > 30 days: soft-deleted
|
|
469
|
+
(deleted_at set, credit_balance = 0)
|
|
470
|
+
Canonical memories are NEVER auto-decayed.
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
### Conflict Resolution
|
|
474
|
+
|
|
475
|
+
When two memories conflict (same conflict_group_id), SynapseResolver:
|
|
476
|
+
1. Fetches all candidates from active_memories view
|
|
477
|
+
2. Calculates TQ for each candidate
|
|
478
|
+
3. Promotes the highest-TQ memory as canonical (is_canonical = true)
|
|
479
|
+
4. Demotes all others (is_canonical = false)
|
|
480
|
+
|
|
481
|
+
### Memory Decay Schedule
|
|
482
|
+
|
|
483
|
+
- Runs automatically via pg_cron at 03:00 UTC daily
|
|
484
|
+
- Manual trigger: POST /memory-decay with method: "run_decay"
|
|
485
|
+
- Returns JSON: { decayed, decremented, processed, run_at, thresholds }
|
|
486
|
+
|
|
487
|
+
### SDK Cache
|
|
488
|
+
|
|
489
|
+
```python
|
|
490
|
+
from synapse_layer import SynapseMemory
|
|
491
|
+
|
|
492
|
+
# Default: 2 second TTL cache (avoids duplicate round-trips)
|
|
493
|
+
memory = SynapseMemory(
|
|
494
|
+
supabase_url="...",
|
|
495
|
+
supabase_key="...",
|
|
496
|
+
cache_ttl_seconds=2.0, # set to 0 to disable
|
|
497
|
+
)
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
---
|
|
501
|
+
|
|
502
|
+
## Neural Handover(TM) v2
|
|
503
|
+
|
|
504
|
+
Transfer complete AI context between different models — zero context loss.
|
|
505
|
+
|
|
506
|
+
### How it works
|
|
507
|
+
|
|
508
|
+
```
|
|
509
|
+
Agent A (Claude) Agent B (GPT-4o)
|
|
510
|
+
| |
|
|
511
|
+
| 1. create_handover(target="gpt-4o") |
|
|
512
|
+
|-----> MCP Server |
|
|
513
|
+
| | 2. handover-initiate |
|
|
514
|
+
| |-----> Supabase |
|
|
515
|
+
| | (HMAC verified) |
|
|
516
|
+
| |<----- handover_id |
|
|
517
|
+
|<----- handover_id |
|
|
518
|
+
| 3. Share handover_id -------> |
|
|
519
|
+
| 4. handover-complete |
|
|
520
|
+
| |<----- Supabase |
|
|
521
|
+
| | (integrity re-verified) |
|
|
522
|
+
| |<----- full context (encrypted) |
|
|
523
|
+
| 5. Inject via MCP |
|
|
524
|
+
| |-----> Agent B continues |
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
### Prompt Adapters
|
|
528
|
+
|
|
529
|
+
Each model family receives context in its optimal format:
|
|
530
|
+
|
|
531
|
+
| Model Family | Format | Optimized For |
|
|
532
|
+
|---|---|---|
|
|
533
|
+
| Claude | XML tags | Structured context parsing |
|
|
534
|
+
| GPT | Markdown | Header-based navigation |
|
|
535
|
+
| Gemini | JSON structured | Structured output mode |
|
|
536
|
+
| Llama (large) | [CONTEXT] blocks | Efficient token usage |
|
|
537
|
+
| Llama (small) | [CTX] ultra-compact | 8k context windows |
|
|
538
|
+
| Mistral | [CONTEXT] blocks | Compact format |
|
|
539
|
+
|
|
540
|
+
### Security
|
|
541
|
+
|
|
542
|
+
- **HMAC-SHA256**: Every packet is signed. Tampered packets are automatically revoked.
|
|
543
|
+
- **One-time use**: Each handover_id can only be consumed once.
|
|
544
|
+
- **TTL**: Packets expire after 24 hours.
|
|
545
|
+
- **Zero-Knowledge**: `session_context` and `memories` remain AES-256-GCM encrypted throughout.
|
|
546
|
+
|
|
547
|
+
### Quick Start
|
|
548
|
+
|
|
549
|
+
```typescript
|
|
550
|
+
import { NeuralHandover } from "@synapse-layer/core";
|
|
551
|
+
|
|
552
|
+
// Agent A: create handover
|
|
553
|
+
const pkg = NeuralHandover.create(memories, "gpt-4o", "Session summary...");
|
|
554
|
+
console.log(pkg.id); // Share this with Agent B
|
|
555
|
+
|
|
556
|
+
// Agent B: verify and use
|
|
557
|
+
const isValid = NeuralHandover.verifySignature(pkg);
|
|
558
|
+
const context = NeuralHandover.adapter("gpt-4o", pkg.memories, pkg.summary);
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
---
|
|
562
|
+
|
|
563
|
+
## Repository Structure
|
|
564
|
+
|
|
565
|
+
```
|
|
566
|
+
synapse-layer/
|
|
567
|
+
├── sdk/python/ # Python SDK (0.7.0)
|
|
568
|
+
│ ├── synapse_layer/
|
|
569
|
+
│ │ ├── __init__.py # Public API exports
|
|
570
|
+
│ │ ├── a2a_client.py # JSON-RPC 2.0 client
|
|
571
|
+
│ │ ├── langchain_memory.py # LangChain adapters
|
|
572
|
+
│ │ └── crewai_tools.py # CrewAI tools
|
|
573
|
+
│ ├── tests/
|
|
574
|
+
│ │ ├── conftest.py # Shared fixtures (25+ fixtures)
|
|
575
|
+
│ │ ├── test_a2a_client.py # A2A client tests (29+ tests)
|
|
576
|
+
│ │ └── test_langchain_memory.py # LangChain adapter tests
|
|
577
|
+
│ └── pyproject.toml # Dependencies + tool config
|
|
578
|
+
│
|
|
579
|
+
├── site/docs/sdk/ # SDK Documentation
|
|
580
|
+
│ ├── python.md # Python SDK guide (0.7.0)
|
|
581
|
+
│ └── a2a-protocol.md # A2A Protocol reference
|
|
582
|
+
│
|
|
583
|
+
├── public/.well-known/
|
|
584
|
+
│ └── agent-card.json # Agent Card (5 skills)
|
|
585
|
+
│
|
|
586
|
+
├── src/ # TypeScript core
|
|
587
|
+
│ ├── crypto.ts # AES-256-GCM + PBKDF2
|
|
588
|
+
│ ├── handover.ts # Neural Handover™ v1
|
|
589
|
+
│ └── engine/ # Consensus Engine™
|
|
590
|
+
│
|
|
591
|
+
├── supabase/ # Database + Edge Functions
|
|
592
|
+
│ ├── functions/mcp-server/ # A2A Protocol endpoint
|
|
593
|
+
│ └── migrations/ # Schema + indexes
|
|
594
|
+
│
|
|
595
|
+
├── CHANGELOG.md # Version history
|
|
596
|
+
├── README.md # This file (v0.7.0)
|
|
597
|
+
├── LICENSE # Apache 2.0
|
|
598
|
+
└── package.json # Dependencies
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
---
|
|
602
|
+
|
|
603
|
+
## Running Tests
|
|
604
|
+
|
|
605
|
+
### Python SDK Tests
|
|
606
|
+
|
|
607
|
+
```bash
|
|
608
|
+
# Install dev dependencies (from git)
|
|
609
|
+
pip install "synapse-layer[all,dev] @ git+https://github.com/SynapseLayer/synapse-sdk-python.git"
|
|
610
|
+
|
|
611
|
+
# Run all tests
|
|
612
|
+
pytest sdk/python/tests/
|
|
613
|
+
|
|
614
|
+
# Run with coverage
|
|
615
|
+
pytest sdk/python/tests/ --cov=synapse_layer
|
|
616
|
+
|
|
617
|
+
# Run specific test class
|
|
618
|
+
pytest sdk/python/tests/test_a2a_client.py::TestSynapseA2AClientInit
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
**Test Coverage:**
|
|
622
|
+
- 29+ test methods
|
|
623
|
+
- 0 failures
|
|
624
|
+
- Async/await testing with pytest-asyncio
|
|
625
|
+
- Mock JSON-RPC responses
|
|
626
|
+
- LangChain & CrewAI integration tests
|
|
627
|
+
- Edge cases: empty content, special characters, rate limits
|
|
628
|
+
|
|
629
|
+
---
|
|
630
|
+
|
|
631
|
+
## Roadmap
|
|
632
|
+
|
|
633
|
+
| Version | Status | Highlights |
|
|
634
|
+
|---------|--------|-----------|
|
|
635
|
+
| **v0.5.0** | Complete | Research & architecture design |
|
|
636
|
+
| **v0.6.0** | Complete | Core infrastructure (encryption, MCP, Consensus Engine) |
|
|
637
|
+
| **v0.7.0** | Complete | Python SDK + A2A Protocol + Test Suite |
|
|
638
|
+
| **v0.9.0** | Complete | Neural Handover™ v2 + Edge Functions (D3) |
|
|
639
|
+
| **v1.0.0** | **Current** | Plugin System + synapse.json + Ecosystem (D4) |
|
|
640
|
+
| **v2.0** | Next | PyPI/npm release; Docs site; Dashboard UI |
|
|
641
|
+
|
|
642
|
+
---
|
|
643
|
+
|
|
644
|
+
## Philosophy
|
|
645
|
+
|
|
646
|
+
> **"The server never sees your data."**
|
|
647
|
+
|
|
648
|
+
Synapse Layer is built on zero-knowledge principles:
|
|
649
|
+
|
|
650
|
+
- Security: Privacy is mandatory, not optional
|
|
651
|
+
- Infrastructure: Memory is infrastructure, not a plugin
|
|
652
|
+
- Portability: Model portability matters - no lock-in
|
|
653
|
+
- Trust: Trust is cryptographic, not contractual
|
|
654
|
+
- Community: Built in Sao Paulo for Brazilian and global developers
|
|
655
|
+
|
|
656
|
+
---
|
|
657
|
+
|
|
658
|
+
## License
|
|
659
|
+
|
|
660
|
+
**Apache 2.0** - Open-source and free for commercial use.
|
|
661
|
+
See [LICENSE](./LICENSE) for details.
|
|
662
|
+
|
|
663
|
+
---
|
|
664
|
+
|
|
665
|
+
## Links
|
|
666
|
+
|
|
667
|
+
| Resource | URL |
|
|
668
|
+
|----------|-----|
|
|
669
|
+
| Website | [synapselayer.org](https://synapselayer.org) |
|
|
670
|
+
| Docs | [synapselayer.org/docs](https://synapselayer.org/docs) |
|
|
671
|
+
| GitHub | [github.com/SynapseLayer/synapse-sdk-python](https://github.com/SynapseLayer/synapse-sdk-python) |
|
|
672
|
+
| Issues | [github.com/SynapseLayer/synapse-sdk-python/issues](https://github.com/SynapseLayer/synapse-sdk-python/issues) |
|
|
673
|
+
| Agent Card | [synapselayer.org/.well-known/agent-card.json](https://synapselayer.org/.well-known/agent-card.json) |
|
|
674
|
+
| Email | founder.synapselayer@proton.me |
|
|
675
|
+
|
|
676
|
+
> **Note:** The canonical `.well-known/` path is served from `public/.well-known/` in this repository.
|
|
677
|
+
> Do not edit `.well-known/` at the root — it is a legacy reference only.
|
|
678
|
+
|
|
679
|
+
---
|
|
680
|
+
|
|
681
|
+
<p align="center">
|
|
682
|
+
<strong>Synapse Layer v1.0.0</strong><br>
|
|
683
|
+
<em>"Giving Agents a Past. Giving Models a Soul."</em><br><br>
|
|
684
|
+
Built in Sao Paulo by Ismael Marchi<br>
|
|
685
|
+
<a href="https://github.com/SynapseLayer/synapse-sdk-python">GitHub</a> |
|
|
686
|
+
<a href="https://synapselayer.org/docs">Docs</a> |
|
|
687
|
+
<a href="./LICENSE">Apache 2.0 License</a>
|
|
688
|
+
</p>
|