LucyAndLuna2023/meshctx

MeshCtx is a 17-brain-region emulated self-improving agent platform.

1

stars

22

commits

Python

primary language

Sep 7, 2026

updated

meshctx.dev

README

MeshCtx

🧠 MeshCtx v3.116.0

全脑仿真自进化AI Agent · SDM突破性记忆 · 自修改代码 · 17脑区 · 14模块

Brain-Inspired Self-Evolving AI Agent Platform

Quick Start · Why MeshCtx · Features · API · Contributing


🌍 Why MeshCtx?

Most AI agents are stateless tools. MeshCtx is a cognitive architecture.

FeatureTypical AgentMeshCtx
MemoryVector store lookupHippocampal replay + emotional weighting + pattern chunking
PlanningSingle-pass chainFree energy principle + active inference + thalamic gating
Self-improvementNoneGenomic optimizer (genetic algorithm on own parameters)
Code modificationStaticNeural plasticity-inspired self-modifying code at runtime
ArchitectureFlat modules17 brain regions simulating cortical-subcortical loops

MeshCtx treats AI agent design as a neuroscience problem, not just an engineering problem.


🔓 Open Source / Closed Core Architecture

RepoVisibilityContent
meshctx (this repo)🔓 PublicSecurity modules (full impl) + core module interface stubs (signatures + docs)
meshctx-core🔒 Private33 core modules full implementation (AgentSwarm · Kernel · SuperBrain · Sandbox · MultiAgent · AutonomousEngine)

For developers: src/core/*.py contains complete interface definitions. Use from src.core.agent_swarm import AgentIdentity for type-safe integration.

Commercial: pip install meshctx-core (private repo, license required) — zero code changes needed.


🚀 Quick Start

Windows

# Download installer (recommended)
# https://github.com/LucyAndLuna2023/meshctx/releases/latest
# meshctx-setup.exe — NSIS wizard, 7 languages, one-click install

Linux / WSL / macOS

curl -fsSL https://raw.githubusercontent.com/LucyAndLuna2023/meshctx/main/install.sh | bash
meshctx setup    # Configure API keys
meshctx start    # Start web service (http://localhost:3001)

macOS 专用脚本: curl -fsSL .../install-mac.sh | bash。 安装脚本默认英文显示;支持 9 语言: zh/en/ja/ko/fr/de/es/it/ar。中文用户可显式切回: MESHCTX_LANG=zh ./install.sh(macOS 同理 MESHCTX_LANG=zh ./install-mac.sh;Windows 同理 set MESHCTX_LANG=zh && install.bat)。

From Source

git clone https://github.com/LucyAndLuna2023/meshctx.git
cd meshctx && pip install -e .
meshctx chat     # CLI mode

Commands

meshctx start          # Web service (default http://localhost:3001)
meshctx chat           # CLI conversation
meshctx setup          # Configure API keys and models
meshctx desktop        # Windows desktop client
meshctx agent          # Multi-step autonomous agent

🧠 Core Features

🧬 GenomicOptimizer (v3.116) 🆕

Genetic algorithm that evolves agent's own parameters: temperature, top_p, prompt style, memory weights.

  • Gaussian mutation · transposon-style jumps · crossover · elitist selection · niche protection
  • ~784 lines, zero dependencies, thread-safe, outperforms manual tuning in ~10 generations

🔍 Observability Tracing (v3.116) 🆕

  • Span/TraceLogger: llm · tool · chain full pipeline tracing
  • Thread-safe (RLock) + optional JSONL disk export

🔄 RAG Query Rewriting + RRF Fusion (v3.116) 🆕

  • Multi-path rewriting (synonym/sub-question/expansion) + Reciprocal Rank Fusion reranking

🛡️ Terminal Security Sandbox (v3.116) 🆕

  • Session continuity + 3-tier danger classification (normal/dangerous/critical)
  • Dangerous command interception, critical commands require approval

🧠 Brain-Inspired Cognitive Architecture

  • 17 brain regions: Free energy principle · active inference · global workspace · homeostasis
  • Hybrid reasoning: Free energy-driven exploration vs fast-path decisions
  • SuperBrain: Hippocampal replay · amygdala emotional tagging · default mode network · thalamic gating
  • Metacognition: Self-evaluation · error classification · behavior adjustment

🧩 Human-Like Memory System (v2.40)

Traditional AI: Store → Keyword match
MeshCtx:       Pattern chunking → Emotional weighting → Hippocampal replay → Associative spread
  • Pattern chunking: Compress raw data into meaning patterns (like a chess player recognizing formations)
  • Emotional weighting: CRITICAL memories decay 200x slower than routine
  • Hippocampal replay: Background 5-min cycle consolidates memories + discovers associations
  • Reconsolidation: Each recall updates the memory (core human learning mechanism)
  • Associative spread: Weighted link propagation (smell → scene → person → conversation)
  • Adaptive forgetting: Forget details, keep patterns — forgetting is a feature, not a bug
  • FSRS spaced repetition (phase-1): Per-memory stability/difficulty (D/S/R) state machine schedules every recall at the edge of forgetting — reviews land exactly when retrieval is about to fail, cutting injection tokens while maximizing retention
  • Active recall write-back: Every hit + confirmation rewrites stability and re-schedules the next review (test-effect / retrieval practice theory); forgetful lapses are punished with a stability halving
  • CMA-ES self-tuning (phase-1): Continuous parameters (temperature / top_p / memory weights / FSRS weights) optimized via covariance-matrix-adaptation evolution — replaces blind GA mutation with gradient-free global optimization

🐝 Agent Swarm — Manager-Worker Multi-Agent (v3.34)

meshctx start --port 3001  # Manager node

# Register worker on another machine
curl -X POST http://manager:3001/swarm/register \
  -d '{"worker_id":"bot1","name":"Coder","capabilities":["code"]}'

# Submit complex task — auto-decompose → dispatch → parallel execute
curl -X POST http://manager:3001/swarm/execute \
  -d '{"task":"Research best practices + write code + review","type":"research"}'
  • Manager-Worker architecture with network + key-based coordination
  • Auto task decomposition: research/code/analysis/report templates
  • Identity auth: ed25519 + HMAC + 5-min anti-replay
  • Collaboration: Delegate · Vote · Consensus · Ensemble

🌐 Multi-Platform Gateway (v2.39)

WeChat Enterprise · Feishu · Telegram · Slack · Discord · WhatsApp

📊 Usage Insights (v2.38)

Per day/week/month tracking: sessions · messages · tokens · latency · error rate

🔄 Credential Pool Rotation (v2.37)

Multi-API key rotation: round_robin · least_used · random · auto-exhaustion detection


📊 Version History

VersionHighlightsTests
v2.37Credential pool rotation825
v2.40Human-like memory (6 mechanisms)916
v2.41Self-healing ops engine935
v2.42Hooks engine (8 events, Claude Code parity)956
v3.115DeepSeek TUI competitor (14 modules, 4200 lines)130
v3.116Open-source agent framework (RAG+RRF, Sandbox, GenomicOptimizer, Observability)3404

🏗️ Architecture

meshctx/
├── src/
│   ├── main.py              # FastAPI main app
│   ├── web_ui.py            # Web UI templates
│   ├── cli.py               # CLI commands
│   ├── i18n.py              # 10-language i18n
│   └── core/                # Core modules
│       ├── hybrid_reasoning.py  # Free energy reasoning
│       ├── observability.py     # Span/TraceLogger
│       ├── rag_orchestrator.py  # RAG + RRF fusion
│       ├── terminal_sandbox.py  # Security sandbox
│       ├── genomic_optimizer.py # Genetic algorithm engine
│       ├── memory_v5.py         # 4-tier memory injection
│       └── ...                  # 14 modules total
├── tests/                   # 3404 tests
├── docs/                    # Documentation site
└── install.sh               # One-click install

🔌 API

Chat

EndpointMethodDescription
/api/chatPOSTConversation (JSON)
/api/chat/streamPOSTStreaming (SSE)

Dual Session (Planner-Executor)

EndpointMethodDescription
/api/dual/planPOSTPlanner planning
/api/dual/executePOSTExecutor execution
/api/dual/statsGETSession stats

Memory

EndpointMethodDescription
/api/memory/statsGETMemory diagnostics
/api/memory/addPOSTAdd memory
/api/memory/searchPOSTSearch memories

Agent Swarm

EndpointMethodDescription
/swarm/registerPOSTRegister worker
/swarm/executePOSTSubmit swarm task
/swarm/statusGETSwarm status

Subagent

EndpointMethodDescription
/api/subagent/runPOSTLaunch isolated subagent
/api/subagent/{id}/statusGETQuery status

🔒 Security

  • Secret scanning: Auto-detect and redact API keys/tokens/PII
  • Hooks interception: Block dangerous commands by default
  • Credential pool: Key rotation prevents exhaustion
  • Approval modes: YOLO / smart / manual three-tier

🌐 Platform Support

PlatformInstallStatus
WindowsNSIS installer (10 languages)
Linuxcurl|bash script
macOSDMG + Homebrew
WSLSame as Linux
Dockerdocker-compose⚠️ WIP

🤝 Contributing

We welcome contributions! Here's how:

  1. Fork this repo
  2. Create a feature branch: git checkout -b feature/amazing-thing
  3. Commit with conventional commits: feat: add thalamic gating filter
  4. Test: python -m pytest tests/ -x
  5. Push and open a Pull Request

Good First Issues

  • 🧠 Add new brain region simulations
  • 🔌 New platform gateway connectors
  • 📊 Dashboard visualizations
  • 🐛 Bug fixes and test coverage

Development Setup

git clone https://github.com/LucyAndLuna2023/meshctx.git
cd meshctx
pip install -e ".[dev]"
python -m pytest tests/ -x

📄 License

  • Framework layer: AGPLv3 Open Source
  • Core brain layer: Source visible · Non-commercial free · Commercial license required
  • Contact: license@meshctx.com

⭐ Star this repo if you find it useful!
Built with 🧠 by LucyAndLuna2023

Contributors

LucyAndLuna2023

22 commits

LucyAndLuna2023/meshctx

MeshCtx is a 17-brain-region emulated self-improving agent platform.

1

stars

22

commits

Python

primary language

Sep 7, 2026

updated

meshctx.dev

README

MeshCtx

🧠 MeshCtx v3.116.0

全脑仿真自进化AI Agent · SDM突破性记忆 · 自修改代码 · 17脑区 · 14模块

Brain-Inspired Self-Evolving AI Agent Platform

Quick Start · Why MeshCtx · Features · API · Contributing


🌍 Why MeshCtx?

Most AI agents are stateless tools. MeshCtx is a cognitive architecture.

FeatureTypical AgentMeshCtx
MemoryVector store lookupHippocampal replay + emotional weighting + pattern chunking
PlanningSingle-pass chainFree energy principle + active inference + thalamic gating
Self-improvementNoneGenomic optimizer (genetic algorithm on own parameters)
Code modificationStaticNeural plasticity-inspired self-modifying code at runtime
ArchitectureFlat modules17 brain regions simulating cortical-subcortical loops

MeshCtx treats AI agent design as a neuroscience problem, not just an engineering problem.


🔓 Open Source / Closed Core Architecture

RepoVisibilityContent
meshctx (this repo)🔓 PublicSecurity modules (full impl) + core module interface stubs (signatures + docs)
meshctx-core🔒 Private33 core modules full implementation (AgentSwarm · Kernel · SuperBrain · Sandbox · MultiAgent · AutonomousEngine)

For developers: src/core/*.py contains complete interface definitions. Use from src.core.agent_swarm import AgentIdentity for type-safe integration.

Commercial: pip install meshctx-core (private repo, license required) — zero code changes needed.


🚀 Quick Start

Windows

# Download installer (recommended)
# https://github.com/LucyAndLuna2023/meshctx/releases/latest
# meshctx-setup.exe — NSIS wizard, 7 languages, one-click install

Linux / WSL / macOS

curl -fsSL https://raw.githubusercontent.com/LucyAndLuna2023/meshctx/main/install.sh | bash
meshctx setup    # Configure API keys
meshctx start    # Start web service (http://localhost:3001)

macOS 专用脚本: curl -fsSL .../install-mac.sh | bash。 安装脚本默认英文显示;支持 9 语言: zh/en/ja/ko/fr/de/es/it/ar。中文用户可显式切回: MESHCTX_LANG=zh ./install.sh(macOS 同理 MESHCTX_LANG=zh ./install-mac.sh;Windows 同理 set MESHCTX_LANG=zh && install.bat)。

From Source

git clone https://github.com/LucyAndLuna2023/meshctx.git
cd meshctx && pip install -e .
meshctx chat     # CLI mode

Commands

meshctx start          # Web service (default http://localhost:3001)
meshctx chat           # CLI conversation
meshctx setup          # Configure API keys and models
meshctx desktop        # Windows desktop client
meshctx agent          # Multi-step autonomous agent

🧠 Core Features

🧬 GenomicOptimizer (v3.116) 🆕

Genetic algorithm that evolves agent's own parameters: temperature, top_p, prompt style, memory weights.

  • Gaussian mutation · transposon-style jumps · crossover · elitist selection · niche protection
  • ~784 lines, zero dependencies, thread-safe, outperforms manual tuning in ~10 generations

🔍 Observability Tracing (v3.116) 🆕

  • Span/TraceLogger: llm · tool · chain full pipeline tracing
  • Thread-safe (RLock) + optional JSONL disk export

🔄 RAG Query Rewriting + RRF Fusion (v3.116) 🆕

  • Multi-path rewriting (synonym/sub-question/expansion) + Reciprocal Rank Fusion reranking

🛡️ Terminal Security Sandbox (v3.116) 🆕

  • Session continuity + 3-tier danger classification (normal/dangerous/critical)
  • Dangerous command interception, critical commands require approval

🧠 Brain-Inspired Cognitive Architecture

  • 17 brain regions: Free energy principle · active inference · global workspace · homeostasis
  • Hybrid reasoning: Free energy-driven exploration vs fast-path decisions
  • SuperBrain: Hippocampal replay · amygdala emotional tagging · default mode network · thalamic gating
  • Metacognition: Self-evaluation · error classification · behavior adjustment

🧩 Human-Like Memory System (v2.40)

Traditional AI: Store → Keyword match
MeshCtx:       Pattern chunking → Emotional weighting → Hippocampal replay → Associative spread
  • Pattern chunking: Compress raw data into meaning patterns (like a chess player recognizing formations)
  • Emotional weighting: CRITICAL memories decay 200x slower than routine
  • Hippocampal replay: Background 5-min cycle consolidates memories + discovers associations
  • Reconsolidation: Each recall updates the memory (core human learning mechanism)
  • Associative spread: Weighted link propagation (smell → scene → person → conversation)
  • Adaptive forgetting: Forget details, keep patterns — forgetting is a feature, not a bug
  • FSRS spaced repetition (phase-1): Per-memory stability/difficulty (D/S/R) state machine schedules every recall at the edge of forgetting — reviews land exactly when retrieval is about to fail, cutting injection tokens while maximizing retention
  • Active recall write-back: Every hit + confirmation rewrites stability and re-schedules the next review (test-effect / retrieval practice theory); forgetful lapses are punished with a stability halving
  • CMA-ES self-tuning (phase-1): Continuous parameters (temperature / top_p / memory weights / FSRS weights) optimized via covariance-matrix-adaptation evolution — replaces blind GA mutation with gradient-free global optimization

🐝 Agent Swarm — Manager-Worker Multi-Agent (v3.34)

meshctx start --port 3001  # Manager node

# Register worker on another machine
curl -X POST http://manager:3001/swarm/register \
  -d '{"worker_id":"bot1","name":"Coder","capabilities":["code"]}'

# Submit complex task — auto-decompose → dispatch → parallel execute
curl -X POST http://manager:3001/swarm/execute \
  -d '{"task":"Research best practices + write code + review","type":"research"}'
  • Manager-Worker architecture with network + key-based coordination
  • Auto task decomposition: research/code/analysis/report templates
  • Identity auth: ed25519 + HMAC + 5-min anti-replay
  • Collaboration: Delegate · Vote · Consensus · Ensemble

🌐 Multi-Platform Gateway (v2.39)

WeChat Enterprise · Feishu · Telegram · Slack · Discord · WhatsApp

📊 Usage Insights (v2.38)

Per day/week/month tracking: sessions · messages · tokens · latency · error rate

🔄 Credential Pool Rotation (v2.37)

Multi-API key rotation: round_robin · least_used · random · auto-exhaustion detection


📊 Version History

VersionHighlightsTests
v2.37Credential pool rotation825
v2.40Human-like memory (6 mechanisms)916
v2.41Self-healing ops engine935
v2.42Hooks engine (8 events, Claude Code parity)956
v3.115DeepSeek TUI competitor (14 modules, 4200 lines)130
v3.116Open-source agent framework (RAG+RRF, Sandbox, GenomicOptimizer, Observability)3404

🏗️ Architecture

meshctx/
├── src/
│   ├── main.py              # FastAPI main app
│   ├── web_ui.py            # Web UI templates
│   ├── cli.py               # CLI commands
│   ├── i18n.py              # 10-language i18n
│   └── core/                # Core modules
│       ├── hybrid_reasoning.py  # Free energy reasoning
│       ├── observability.py     # Span/TraceLogger
│       ├── rag_orchestrator.py  # RAG + RRF fusion
│       ├── terminal_sandbox.py  # Security sandbox
│       ├── genomic_optimizer.py # Genetic algorithm engine
│       ├── memory_v5.py         # 4-tier memory injection
│       └── ...                  # 14 modules total
├── tests/                   # 3404 tests
├── docs/                    # Documentation site
└── install.sh               # One-click install

🔌 API

Chat

EndpointMethodDescription
/api/chatPOSTConversation (JSON)
/api/chat/streamPOSTStreaming (SSE)

Dual Session (Planner-Executor)

EndpointMethodDescription
/api/dual/planPOSTPlanner planning
/api/dual/executePOSTExecutor execution
/api/dual/statsGETSession stats

Memory

EndpointMethodDescription
/api/memory/statsGETMemory diagnostics
/api/memory/addPOSTAdd memory
/api/memory/searchPOSTSearch memories

Agent Swarm

EndpointMethodDescription
/swarm/registerPOSTRegister worker
/swarm/executePOSTSubmit swarm task
/swarm/statusGETSwarm status

Subagent

EndpointMethodDescription
/api/subagent/runPOSTLaunch isolated subagent
/api/subagent/{id}/statusGETQuery status

🔒 Security

  • Secret scanning: Auto-detect and redact API keys/tokens/PII
  • Hooks interception: Block dangerous commands by default
  • Credential pool: Key rotation prevents exhaustion
  • Approval modes: YOLO / smart / manual three-tier

🌐 Platform Support

PlatformInstallStatus
WindowsNSIS installer (10 languages)
Linuxcurl|bash script
macOSDMG + Homebrew
WSLSame as Linux
Dockerdocker-compose⚠️ WIP

🤝 Contributing

We welcome contributions! Here's how:

  1. Fork this repo
  2. Create a feature branch: git checkout -b feature/amazing-thing
  3. Commit with conventional commits: feat: add thalamic gating filter
  4. Test: python -m pytest tests/ -x
  5. Push and open a Pull Request

Good First Issues

  • 🧠 Add new brain region simulations
  • 🔌 New platform gateway connectors
  • 📊 Dashboard visualizations
  • 🐛 Bug fixes and test coverage

Development Setup

git clone https://github.com/LucyAndLuna2023/meshctx.git
cd meshctx
pip install -e ".[dev]"
python -m pytest tests/ -x

📄 License

  • Framework layer: AGPLv3 Open Source
  • Core brain layer: Source visible · Non-commercial free · Commercial license required
  • Contact: license@meshctx.com

⭐ Star this repo if you find it useful!
Built with 🧠 by LucyAndLuna2023

Contributors

LucyAndLuna2023

22 commits

Languages

Python

94.2%

HTML

3.3%

Shell

1.9%