DEV Community

golflover
golflover

Posted on

MeshCtx: Open Source AI Agent with17 Brain Regions

Why I Built an AI Agent with17 Brain Regions (And What I Learned)

Most AI agents are stateless tools. You give them a prompt, they give you an answer, and then... they forget everything.

That bothered me. So I spent18 months building MeshCtx — an open-source AI agent platform that mimics how the human brain actually works.

The Problem with Stateless Agents

Every time you talk to ChatGPT or Claude, it's starting from scratch. No memory consolidation. No learning from mistakes. No self-improvement.

I wanted something different. I wanted an agent that could:

  • Remember and consolidate memories like humans do during sleep
  • Modify its own behavior based on experience
  • Coordinate multiple "brain regions" for complex tasks

The17 Brain Regions

Inspired by neuroscience, I mapped cognitive functions to agent modules:

Brain Region Agent Function
Prefrontal Cortex Planning & Goal Setting
Hippocampus Memory Consolidation
Amygdala Emotional Processing
Cerebellum Motor Coordination
Wernicke's Area Input Comprehension
Broca's Area Output Generation

...and11 more regions, each handling specific cognitive functions.

Self-Modifying Code

The most controversial feature: the agent can rewrite its own logic at runtime. Inspired by Quine programs and genetic programming, the SelfRewriter module can:

  • Analyze its own performance
  • Generate code modifications
  • Test changes in a sandbox
  • Apply successful modifications
# The agent can modify its own prompts and logic
rewriter.analyze_performance(metrics)
suggestion = rewriter.generate_modification()
if rewriter.test_in_sandbox(suggestion):
    rewriter.apply(suggestion)
Enter fullscreen mode Exit fullscreen mode

Memory That Consolidates

The SDM (Sparse Distributed Memory) system doesn't just store vectors. It:

  1. Creates emotional weightings for memories
  2. Consolidates important memories over time (like sleep)
  3. Forgets irrelevant information naturally
  4. Links related memories across sessions

What I Learned

  1. Biology has good patterns — Evolution spent millions of years optimizing these architectures
  2. Self-modification is scary but powerful — With proper sandboxing, it works
  3. Memory is more than storage — Consolidation and forgetting are features, not bugs
  4. Open source matters — AGPLv3 ensures the community can build on this

Try It Yourself

MeshCtx is free forever for personal use:

pip install meshctx
meshctx init
Enter fullscreen mode Exit fullscreen mode

GitHub: https://github.com/LucyAndLuna2023/meshctx


What brain regions would you add to an AI agent? Let me know in the comments.

Top comments (0)