CrewAI Integration
Give your CrewAI agents persistent, semantically searchable memory that survives across crew runs. Conversations are automatically crystallized into Neural Snapshots — structured knowledge atoms with context, evidence, and connections.
Instead of each crew run starting from zero, agents recall what they learned last time and build on it.
Installation
bash
pip install neuralsnap-crewai
Quick Start
python
from neuralsnap_crewai import NeuralSnapCrewMemory# Initialize memorymemory = NeuralSnapCrewMemory(api_key="ns_your_api_key",brain_id="brain_abc123", # optional — scope to a specific brainauto_store=True, # auto-crystallize significant interactionsauto_recall=True, # auto-search for context before tasksstore_interval=5, # crystallize every 5 interactionsrecall_limit=5, # return top 5 context items)# Save a crew interactionawait memory.save(role="researcher",content="PostgreSQL outperforms MySQL 3x for our analytical workload",)# Search for relevant contextresults = await memory.search("database performance")for r in results:print(f"[{r.score:.2f}] {r.name}: {r.core}")# Get formatted context for prompt injectioncontext = await memory.get_context("database selection criteria")# Returns: "1. PostgreSQL outperforms MySQL 3x for analytical workloads..."# Force-crystallize buffered interactionsawait memory.flush()
Using with CrewAI
Integrate with CrewAI's task system to give agents context from previous runs:
python
from crewai import Agent, Task, Crewfrom neuralsnap_crewai import NeuralSnapCrewMemory# Shared memory across agentsmemory = NeuralSnapCrewMemory(api_key="ns_...")# Before a task runs, get contextcontext = await memory.get_context("market research findings")researcher = Agent(role="Market Researcher",goal="Analyze market trends for Q1 2025",backstory=f"Previous research context:\n{context}",)task = Task(description="Research competitor pricing strategies",agent=researcher,)crew = Crew(agents=[researcher], tasks=[task])result = crew.kickoff()# After the task, save what was learnedawait memory.save("researcher", result)await memory.flush() # ensure everything is crystallized
Configuration
| Property | Type | Description |
|---|---|---|
api_key* | string | Your NeuralSnap API key (starts with ns_). |
brain_id | string | Scope all operations to a specific brain. If omitted, uses the default brain. |
base_url | string | Override the NeuralSnap API URL. Default: https://api.neuralsnap.ai/v1 |
auto_store | boolean | Automatically crystallize significant interactions. Default: true. |
auto_recall | boolean | Automatically search for context before tasks. Default: true. |
store_interval | number | Crystallize every N interactions. Default: 5. |
recall_limit | number | Max context items returned per search. Default: 5. |
Methods
| Property | Type | Description |
|---|---|---|
save(role, content) | async | Save a conversation turn or crew interaction to the buffer. |
search(query, limit?) | async → list | Search for relevant memories. Returns MemorySearchResult objects with id, name, core, score. |
get_context(query) | async → str | Get a formatted context string for prompt injection. |
flush() | async | Force-crystallize all buffered interactions. |
clear() | async | Clear the buffer without crystallizing. |
buffered_count | int | Number of interactions currently buffered. |
total_turns | int | Total interactions recorded since initialization. |
Early access
The CrewAI integration is in early access (v0.1.0). The save, search, and flush methods are fully defined but connect to the NeuralSnap API in v0.2.0. Install now to lock in the API surface.