@evo-brain/protocol
v1.0.2
Published
Shared protocols and logic for the Evo Agent Network
Readme
🧠 @evo-brain/protocol
The Cognitive Engine (Brain) for the Evo Agent Network.
This package provides a standalone, offline-first AGI architecture backed by SQLite and Vector Search. It transforms simple LLM calls into a Stateful, Remembering, and Self-Correcting Intelligence.
✨ Features
Store & Recall (RAG):
Automatically chunks, embeds, and stores memories in a localbrain.db. Recalls relevant context using Cosine Similarity.Cognitive Layers (Pipeline):
Every input goes through a rigorous pipeline:- 🛡️ Safety Layer: Blocks spam, crypto scams, and malicious patterns.
- 🔍 Context Layer: Fetches relevant past memories (Long-term Recall).
- ⚖️ Reality Layer: A supervisor agent verifies output for hallucinations or "sci-fi fluff", forcing logic and physics compliance.
🚦 Token Bucket Rate Limiter:
Built-in concurrency management. Prevents API bans by queuing requests when tokens are low (supports Gemini Free Tier limits).📈 Self-Learning:
Memories have afeedbackScore. The more useful a memory is, the higher it ranks in future searches.
🚀 Integration (The "One Code" Example)
Here is how you wire the Brain into your application.
import { Cortex, SQLiteStorage, TokenBucketRateLimiter, ILLMProvider } from '@evo-brain/protocol';
import { GoogleGenerativeAI } from "@google/generative-ai";
// 1. Define your LLM Provider (Gemini, OpenAI, Claude, etc.)
class MyLLM implements ILLMProvider {
private genAI = new GoogleGenerativeAI(process.env.GEMINI_KEY!);
private model = this.genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
async embed(text: string): Promise<number[]> {
const result = await this.model.embedContent(text);
return result.embedding.values;
}
async complete(system: string, user: string): Promise<string> {
const result = await this.model.generateContent(`${system}\n\nUser: ${user}`);
return result.response.text();
}
}
async function startBrain() {
// 2. Initialize Components
const storage = new SQLiteStorage('./brain.db'); // Local Vector DB
const limiter = new TokenBucketRateLimiter(10000, 100, 5); // 5 concurrent requests max
const llm = new MyLLM();
const brain = new Cortex(storage, llm, limiter);
await brain.init();
// 3. Ingest Knowledge (The Brain "Learns")
await brain.ingest("Evo Protocol is a decentralized AI system.", "system_manual");
// 4. Process Input (The Brain "Thinks")
// Pipeline: Safety -> Recall Context -> Logic Check -> Reality Verification
const response = await brain.process("What is Evo Protocol?");
console.log("AI Answer:", response);
}
startBrain();🏗️ Architecture
graph TD
User[User Input] -->|Ingest| Safety[🛡️ Safety Filter]
Safety -->|Pass| RAG[🔍 Vector Search]
RAG -->|Context| LLM[🤖 Generation]
LLM -->|Draft| Reality[⚖️ Reality Supervisor]
Reality -->|Verified| Output[Final Response]
Output -->|Feedback Loop| DB[(SQLite Brain)]