Skip to content

Commit 3a7e9c3

Browse files
author
Ismael Marchi
committed
feat: crewai integration — StorageBackend adapter for unified memory system
- Add synapse_memory/integrations/crewai_memory.py (SynapseCrewStorage) - Implements CrewAI v1.14+ StorageBackend protocol (save, search, delete, update, get_record, list_records, scopes, categories, reset, async) - Full Cognitive Security pipeline: PII redaction + encryption on every save - Add examples/crewai_agent.py with standalone demo - Add tests/integrations/test_crewai_memory.py (37 tests) - Add crewai optional dependency in pyproject.toml - Update README with CrewAI integration section - Lazy imports in integrations __init__ to avoid pulling heavy deps - 324 tests passing, 93% coverage, zero IP exposure
1 parent eb69a56 commit 3a7e9c3

6 files changed

Lines changed: 981 additions & 3 deletions

File tree

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,35 @@ chain_with_history = RunnableWithMessageHistory(
252252
> strategies, and PRO heuristics are available under separate license.
253253
> See [synapselayer.org/docs](https://synapselayer.org/docs).
254254
255+
## 🤖 Using Synapse Layer with CrewAI
256+
257+
Synapse Layer plugs into CrewAI as a persistent, encrypted storage backend
258+
for the unified memory system. Every memory passes through PII redaction,
259+
intent validation, and AES-256 encryption automatically.
260+
261+
```bash
262+
pip install synapse-layer[crewai]
263+
```
264+
265+
```python
266+
from synapse_memory.integrations.crewai_memory import SynapseCrewStorage
267+
from crewai.memory.unified_memory import Memory
268+
from crewai import Crew
269+
270+
crew = Crew(
271+
agents=[...],
272+
tasks=[...],
273+
memory=Memory(storage=SynapseCrewStorage(agent_id="my-crew")),
274+
)
275+
```
276+
277+
The adapter implements CrewAI's `StorageBackend` protocol — scope management,
278+
category filtering, and async variants all work out of the box.
279+
280+
> **Note:** This is the OSS adapter. Advanced scoring, enterprise retrieval
281+
> strategies, and PRO heuristics are available under separate license.
282+
> See [synapselayer.org/docs](https://synapselayer.org/docs).
283+
255284
## Competitive Comparison
256285

257286
| Capability | Synapse Layer | Mem0 | Zep | pgvector (raw) |
@@ -305,7 +334,7 @@ Synapse Layer is not just a library you call — it's **infrastructure your agen
305334
| Version | Status | Highlights |
306335
|---|---|---|
307336
| **v1.0.7** |**Stable** | Auto-Save Engine, Plugin Architecture, MCP Bridge, Smithery listing |
308-
| **v1.1.0** | 🚧 In Progress | ✅ LangChain native adapter, CrewAI integration, embedding model selection |
337+
| **v1.1.0** | 🚧 In Progress | ✅ LangChain native adapter, CrewAI integration, embedding model selection |
309338
| **v1.2.0** | 📋 Planned | Synapse Forge visual debugger, real-time memory inspector |
310339
| **v2.0.0** | 📋 Planned | Multi-tenant vault, team memory spaces, RBAC |
311340

examples/crewai_agent.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"""
2+
Synapse Layer — CrewAI Integration Example
3+
4+
Demonstrates how to use Synapse Layer as the persistent memory
5+
backend for a CrewAI crew.
6+
7+
Requirements:
8+
pip install synapse-layer crewai
9+
10+
Author : Security & Architecture Team @ Synapse Layer
11+
License: Apache 2.0
12+
"""
13+
14+
from synapse_memory.integrations.crewai_memory import SynapseCrewStorage
15+
16+
17+
def main():
18+
# Initialize Synapse Layer as CrewAI's memory storage backend.
19+
# Every memory passes through the Cognitive Security pipeline:
20+
# PII redaction → Intent validation → AES-256 encryption
21+
storage = SynapseCrewStorage(agent_id="research-crew")
22+
23+
# Use with CrewAI's Memory system:
24+
#
25+
# from crewai import Agent, Crew, Task
26+
# from crewai.memory.unified_memory import Memory
27+
#
28+
# memory = Memory(storage=storage)
29+
#
30+
# researcher = Agent(
31+
# role="Senior Researcher",
32+
# goal="Find and summarize key insights",
33+
# backstory="Expert analyst with deep domain knowledge.",
34+
# )
35+
#
36+
# task = Task(
37+
# description="Research the latest trends in AI agent memory.",
38+
# expected_output="A summary of key trends.",
39+
# agent=researcher,
40+
# )
41+
#
42+
# crew = Crew(
43+
# agents=[researcher],
44+
# tasks=[task],
45+
# memory=memory, # Synapse Layer handles persistence
46+
# )
47+
#
48+
# result = crew.kickoff()
49+
50+
# --- Standalone demo (no LLM required) ---
51+
52+
from crewai.memory.types import MemoryRecord
53+
54+
# Store memories through the Synapse security pipeline
55+
records = [
56+
MemoryRecord(
57+
content="User prefers concise technical reports.",
58+
scope="/crew/research",
59+
categories=["preference"],
60+
importance=0.8,
61+
),
62+
MemoryRecord(
63+
content="Project deadline is April 15, 2026.",
64+
scope="/crew/research",
65+
categories=["deadline", "project"],
66+
importance=0.9,
67+
),
68+
]
69+
storage.save(records)
70+
print(f"Stored {len(records)} records through Synapse Layer.")
71+
print(f"Total memories in vault: {storage.count()}")
72+
print()
73+
74+
# List records back
75+
stored = storage.list_records(scope_prefix="/crew/research")
76+
for rec in stored:
77+
print(f" [{rec.importance:.1f}] {rec.content}")
78+
print()
79+
80+
# Scope info
81+
info = storage.get_scope_info("/crew/research")
82+
print(f"Scope: {info.path}")
83+
print(f" Records: {info.record_count}")
84+
print(f" Categories: {info.categories}")
85+
print()
86+
87+
print("Done. Memory persists across sessions with zero-knowledge security.")
88+
89+
90+
if __name__ == "__main__":
91+
main()

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ dependencies = [
4848
langchain = [
4949
"langchain-core>=0.3.0",
5050
]
51+
crewai = [
52+
"crewai>=1.14.0",
53+
]
5154
dev = [
5255
"pytest>=7.4.0",
5356
"pytest-cov>=4.1.0",

synapse_memory/integrations/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77
License: Apache 2.0
88
"""
99

10-
from .langchain_memory import SynapseChatMessageHistory
10+
# Lazy imports to avoid pulling in optional dependencies at import time.
11+
# Users import directly from the submodule they need:
12+
# from synapse_memory.integrations.langchain_memory import SynapseChatMessageHistory
13+
# from synapse_memory.integrations.crewai_memory import SynapseCrewStorage
1114

12-
__all__ = ["SynapseChatMessageHistory"]
15+
__all__ = ["SynapseChatMessageHistory", "SynapseCrewStorage"]
16+
17+
18+
def __getattr__(name: str):
19+
if name == "SynapseChatMessageHistory":
20+
from .langchain_memory import SynapseChatMessageHistory
21+
return SynapseChatMessageHistory
22+
if name == "SynapseCrewStorage":
23+
from .crewai_memory import SynapseCrewStorage
24+
return SynapseCrewStorage
25+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

0 commit comments

Comments
 (0)