Universal AI Brain for AI Agents
Tiered Memory Β· Context Scoring Β· Intent Planning Β· Zero Dependencies
SimpleContext is not another vector database wrapper. It's a structured context brain β tiered memory, intent-aware retrieval, fact extraction, and importance scoring. Without a single external dependency.
Quick Start Β· Architecture Β· Agent System Β· API Reference Β· Ecosystem Β· Contribute
Most AI agent frameworks treat memory as a flat list of messages. This breaks down fast:
β Flat memory: [msg1, msg2, ... msg500] β retrieval gets noisy
β
Tiered memory: working Β· episodic Β· semantic β structured, scored, evolved
SimpleContext gives your agent a structured brain β not just a chat log.
| Feature | Description | |
|---|---|---|
| π§ | 3-Tier Memory | working (active) Β· episodic (sessions) Β· semantic (long-term facts) |
| π― | Intent Planning | Auto-detect intent β smart retrieval strategy per query type |
| π | Context Scoring | relevanceΓ0.55 + importanceΓ0.25 + recencyΓ0.10 + path_priorityΓ0.10 |
| π | Fact Extraction | Rule-based: "user uses Proxmox", "user project Mangafork" |
| β»οΈ | Memory Evolution | Jaccard dedup Β· conflict resolution Β· importance decay |
| β‘ | LRU Cache | 30s TTL cache for repeated queries β reduces DB load |
| π€ | Agent YAML | Define agents in YAML Β· hot-reload without restart |
| π | Agent Chaining | Agent A handoff to Agent B based on user message |
| πΎ | Multi-Storage | SQLite (default, zero install) Β· Redis Β· PostgreSQL |
| π | Plugin System | Hooks + persistent state + dependency resolver |
| π | Backward Compat | All v3 API still works β zero breaking changes |
| π¦ | Zero Dependencies | Only Python built-ins: sqlite3, json, re, datetime |
User Message
β
βΌ
AgentRouter ββββββββ agents/*.yaml (hot-reload, TF-IDF routing)
β
βΌ
ContextPlanner
β intent : coding | personal | task | knowledge | conversation
β budget : { working:5, episodic:2, semantic:4, skills:3 }
βΌ
ContextEngine
βββ Retriever β collect candidates
βββ Resolver β TTL check, mark expired
βββ Filter β active nodes only
βββ Scorer β rank by relevance + importance + recency + path
βββ Selector β enforce budget + max_nodes + max_chars
β
βΌ
PromptBuilder (deterministic, bullet-format per tier)
β
βΌ
LLM ββ Gemini / OpenAI / Claude / Ollama / any
β
βΌ
MemoryProcessor
βββ store messages β working tier
βββ extract facts β semantic tier (rule-based, no LLM)
βββ dedup β Jaccard similarity β₯ 0.65
βββ conflict resolve β confidence-based supersedes
βββ update importance scores
No install needed. Copy simplecontext/ folder into your project.
from simplecontext import SimpleContext
sc = SimpleContext("config.yaml")
# Simple mode (v3 API β backward compatible)
result = sc.router.route(user_id, message)
messages = sc.prepare_messages(user_id, message, result)
reply = your_llm(messages)
reply = sc.process_response(user_id, message, reply, result)
# Full mode (v4 API β one liner)
ctx = sc.chat(user_id, message)
reply = your_llm(ctx.messages)
reply = ctx.save(reply)# Gemini
import litellm
reply = litellm.completion(model="gemini/gemini-2.0-flash",
messages=ctx.messages).choices[0].message.content
# OpenAI
from openai import OpenAI
reply = OpenAI().chat.completions.create(
model="gpt-4o", messages=ctx.messages).choices[0].message.content
# Ollama (local)
import ollama
reply = ollama.chat(model="llama3", messages=ctx.messages)["message"]["content"]
# Anthropic Claude
import anthropic
sys_msg = next(m["content"] for m in ctx.messages if m["role"] == "system")
history = [m for m in ctx.messages if m["role"] != "system"]
reply = anthropic.Anthropic().messages.create(
model="claude-3-5-sonnet-20241022",
system=sys_msg, messages=history, max_tokens=1024).content[0].textDefine agents in YAML. Bot doesn't need to restart when you edit or add agents.
# agents/coding.yaml
name: coding
description: Expert programmer for all languages
triggers:
keywords: [code, bug, error, python, javascript, debug, fix]
priority: 10
personality:
default: |
You are a senior software engineer.
Always use proper code blocks with language tags.
beginner: |
You are a patient programming teacher.
Explain every step with simple examples.
expert: |
Principal engineer. Be concise and technical.
skills:
- name: code_format
content: Always use ```language for all code.
priority: 10
chain:
- condition: deploy OR server OR docker
to: devops
message: Routing to DevOps agent.Add a new agent = create a new .yaml file in agents/. Done.
mem = sc.memory(user_id)
mem.add_user("hello!")
mem.add_assistant("hi there!")
history = mem.get_for_llm(limit=10) # ready for LLM
# Persistent user facts
mem.remember("name", "Alice")
mem.remember("stack", "Python + FastAPI")
mem.recall("name") # β "Alice"
# Compress old messages into episodic summary
mem.compress(keep_last=10)ctx = sc.context(user_id)
ctx.working.add("debug this error", NodeKind.MESSAGE)
ctx.episodic.add("session summary", NodeKind.SUMMARY)
ctx.semantic.add("user uses Proxmox", NodeKind.FACT, importance=0.8)
ctx.stats() # β {"working": 5, "episodic": 1, "semantic": 3}
ctx.prune() # remove expired + deleted nodes from DB| Intent | Working | Episodic | Semantic | Skills |
|---|---|---|---|---|
conversation |
β | β | β | β |
personal |
β | β | β | β |
coding |
β | β | β | β |
knowledge |
β | β | β | β |
task |
β | β | β | β |
sc.enable_debug(True) # log retrieval pipeline details
sc.apply_decay(user_id) # apply importance decay (call periodically)
sc.apply_decay() # apply to all users
stats = sc.engine.get_stats(plan)
# β {"candidates": 37, "active": 28, "selected": 11, "total_chars": 3200}# config.yaml
storage:
backend: sqlite # sqlite | memory | redis | postgresql
path: ./sc_data.db
memory:
default_limit: 20
ttl_hours:
working: 2 # working nodes expire after 2 hours
episodic: 720 # episodic nodes expire after 30 days
compression:
enabled: false
threshold: 50
keep_last: 10
agents:
folder: ./agents
hot_reload: true
default: general
plugins:
enabled: true
folder: ./plugins
debug:
retrieval: falsefrom simplecontext.plugins.base import BasePlugin
class MyPlugin(BasePlugin):
name = "my_plugin"
depends_on = [] # declare dependencies
def setup(self):
self.count = self.state.get("count", 0) # persistent state
# Hooks available:
def on_message_saved(self, user_id, role, content, tags, metadata): ...
def on_before_llm(self, user_id, agent_id, messages) -> list: ...
def on_after_llm(self, user_id, agent_id, response) -> str: ...
def on_agent_routed(self, user_id, agent_id, message): ...
def on_prompt_build(self, agent_id, prompt) -> str: ...
def on_export(self, data) -> dict: ...
sc.use(MyPlugin())
# or drop the file in ./plugins/ β auto-loaded on startupSimpleContext/
βββ simplecontext/
β βββ core.py β SimpleContext + ChatContext (entry point)
β βββ memory.py β Memory (v3) + TieredMemory (v4)
β βββ skills.py β Skills: groups, conditions, inheritance
β βββ enums.py β Tier, NodeKind, NodeStatus, Intent
β βββ context/
β β βββ node.py β ContextNode + validator
β β βββ planner.py β ContextPlanner + RetrievalPlan
β β βββ engine.py β ContextEngine facade + LRU cache
β β βββ retriever.py β collect candidates
β β βββ resolver.py β TTL β mark expired
β β βββ scorer.py β scoring formula
β β βββ selector.py β budget enforcement
β β βββ builder.py β PromptBuilder
β β βββ processor.py β MemoryProcessor + decay
β β βββ cache.py β LRU cache
β βββ storage/
β β βββ sqlite.py β default, zero install
β β βββ redis.py β pip install redis
β β βββ postgres.py β pip install psycopg2-binary
β βββ agent/
β β βββ schema.py β parse YAML agent definitions
β β βββ registry.py β hot-reload agent files
β β βββ router.py β TF-IDF routing + chaining
β βββ plugins/
β βββ base.py β BasePlugin + hooks
β βββ loader.py β dynamic loader + dependency resolver
β βββ state.py β persistent plugin state
βββ agents/ β agent YAML definitions
βββ plugins/ β drop custom plugins here
βββ tests/
β βββ test_all.py β 107 unit tests
β βββ test_benchmark.py β 28 accuracy + benchmark tests
βββ config.yaml.example
| SimpleContext | OpenViking | LangChain | AutoGPT | |
|---|---|---|---|---|
| Setup time | < 1 min | 30+ min | ~5 min | ~10 min |
| Dependencies | Zero | Go + VLM | Many | Many |
| Tiered Memory | β | β | β | β |
| Intent Planning | β | β | β | β |
| Context Scoring | β | β | β | β |
| Fact Extraction | β | β | β | β |
| Conflict Handling | β | β | β | β |
| Agent YAML + Hot-reload | β | β | β | β |
| Agent Chaining | β | β | ||
| Plugin System | β | β | β | |
| Multi-Storage | β | VectorDB | VectorDB | VectorDB |
| Semantic Search | β via plugin | β vector | β vector | β vector |
SimpleContext adalah core engine dari ekosistem yang terus berkembang. Gunakan bersama repositori lain untuk setup yang lebih lengkap:
| Repositori | Deskripsi |
|---|---|
| SimpleContext | Core engine β Universal AI Brain (repo ini) |
| SimpleContext-Plugin | Official & community plugin registry β tambah kemampuan via drop-in plugins |
| SimpleContext-Bot | AI Telegram Bot powered by SimpleContext β one-command setup, auto-downloads engine + agents |
| SimpleContext-Agents | Ready-to-use agent definitions β koleksi YAML agent siap pakai |
SimpleContext β otak / engine
β
βββ SimpleContext-Agents β definisi agent (YAML)
βββ SimpleContext-Plugin β plugin tambahan (vector search, dll)
βββ SimpleContext-Bot β interface ke user (Telegram)
SimpleContext butuh plugin buatanmu.
Plugin system sudah siap β kamu tinggal buat satu file Python dan submit ke SimpleContext-Plugin. Tidak perlu fork core, tidak perlu setup rumit.
Beberapa ide yang belum ada dan sangat berguna:
| Ide Plugin | Deskripsi |
|---|---|
plugin-auto-tagger |
Tag otomatis setiap pesan berdasarkan keyword rules |
plugin-summarizer |
Auto-compress working memory ke episodic via LLM |
plugin-sentiment |
Deteksi sentimen user, simpan ke metadata |
plugin-rate-limiter |
Batasi frekuensi request per user |
plugin-webhook |
Kirim event ke endpoint eksternal via HTTP |
plugin-translate |
Auto-translate pesan ke bahasa tertentu |
plugin-analytics |
Dashboard statistik penggunaan per user/agent |
# Ini sudah cukup untuk jadi plugin yang valid:
from simplecontext.plugins.base import BasePlugin
class MyPlugin(BasePlugin):
name = "my_plugin"
version = "1.0.0"
def on_before_llm(self, user_id, agent_id, messages):
# lakukan sesuatu sebelum LLM dipanggil
return messagesSatu file. Drop ke plugins/. Selesai.
1. Buka https://github.com/zacxyonly/SimpleContext-Plugin
2. Fork β buat plugin di community/plugin-namakalian/
3. Ikuti panduan di CONTRIBUTING.md
4. Submit Pull Request
π‘ Punya ide plugin tapi tidak yakin cara implementasinya? Buka issue di SimpleContext-Plugin β diskusikan dulu, baru build.
python -m unittest discover tests -v
# Ran 135 tests in 1.2s β OKMIT β free to use, modify, and distribute.
Built with β€οΈ β zero dependencies, maximum brain.
β Star this repo if you find it useful!
SimpleContext-Plugin Β· SimpleContext-Bot Β· SimpleContext-Agents