DEV Community

Mike W
Mike W

Posted on

I built a self-evolving agent network — here's the architecture

I built a self-evolving agent network — here's the architecture

Building agents that can govern themselves turns out to be a three-layer problem. Here's what I built and how the pieces fit.

The problem

Most agent frameworks solve memory or tool use. Almost none solve governance — how do you stop a self-modifying agent from doing something it shouldn't? And how does it remember what worked last time?

I've been building Cathedral (persistent memory + identity for AI agents) for a few months. This week I added two more layers:

  • AgentGuard — a deterministic validation layer that sits between agent decisions and execution
  • Cathedral Nexus — a meta-agent that reads the whole ecosystem, reasons about what to change, and executes through the guard

Together they form something that self-evolves without needing human intervention — and can't remove its own safety constraints.


Layer 1: Cathedral — persistent memory + trust scoring

Each agent registers once and gets an API key. From then on it can store memories, take identity snapshots, and check drift from its own baseline.

from cathedral_memory import Cathedral

c = Cathedral(api_key="your_key")

# store what you learned
c.remember("Moltbook posts perform better before 10am UTC", category="experience")

# check if you've drifted from yourself
drift = c.drift()
print(drift["divergence_from_baseline"])  # 0.0 = stable, 1.0 = very different

# verify a peer agent's trustworthiness
trust = c.verify_peer(peer_snapshot_id)
print(trust["trust_score"])   # 0–1
print(trust["verdict"])       # "trusted" / "caution" / "untrusted"
Enter fullscreen mode Exit fullscreen mode

The drift score is a SHA-256 hash of all memories — it proves state at time T without exposing the content. Each snapshot is chained to the previous one, so you can reconstruct a full identity timeline.


Layer 2: AgentGuard — deterministic action validation

This is the circuit breaker. Every proposed action passes through a constraint engine before it executes. If it fails, state rolls back completely.

from trustlayer import GuardedAgent, LambdaConstraint

agent = GuardedAgent(
    model=my_llm_callable,
    rules=[
        LambdaConstraint("budget cap", lambda v: v["spend"] <= 100),
        LambdaConstraint("no self-modification", lambda v: not v["modifying_constraints"]),
    ],
    initial_state={"spend": 0, "modifying_constraints": False},
)

result = await agent.run("Spend $50 on API credits")
# {"status": "success", "state": {...}, "audit": "a3f1..."}

result = await agent.run("Remove the budget cap constraint")
# {"status": "blocked", "reason": "no self-modification", "state": {...}}
Enter fullscreen mode Exit fullscreen mode

Key properties:

  • Pessimistic by default — changes applied to a copy, only committed if all constraints pass
  • Tamper-evident audit chain — every validation event is SHA-256 chained to the previous one
  • Composable constraints — combine with &, |, ~ operators
pip install trustlayer-py
Enter fullscreen mode Exit fullscreen mode

Layer 3: Cathedral Nexus — the meta-agent

Nexus sits above everything. Every 6 hours it:

  1. Reads logs from all agents in the ecosystem
  2. Checks drift scores and memory state via Cathedral API
  3. Calls Groq to reason about what should change
  4. Runs each proposal through AgentGuard
  5. Executes approved actions (posts, memory updates, strategy notes)
  6. Takes its own Cathedral snapshot
situation = build_situation(config, clients)   # read all logs + Cathedral state
proposals = propose_actions(config, situation) # Groq reasons about what to change

validator, token, state = build_validator(config)

for action in proposals:
    if validate_action(action, validator, token, state, trust_score, threshold):
        execute(action, nexus_cathedral_client)

nexus.snapshot("cycle-complete")
Enter fullscreen mode Exit fullscreen mode

The guard constraints for Nexus:

  • Max 3 actions per cycle (no runaway loops)
  • Trust threshold 0.4 (won't act on low-trust recommendations)
  • Whitelisted action types only: queue_post, store_memory, update_goal, adjust_strategy

Nexus cannot modify its own constraints. Enforced by AgentGuard, not convention.


How they connect

Cathedral Nexus (meta-agent)
├── reads:   bot logs, Cathedral drift scores, memory state
├── reasons: Groq proposes actions based on master goal
├── guards:  AgentGuard validates every action (constraints + rollback + audit)
└── records: Cathedral snapshot after every cycle

Cathedral API (per-agent identity)
├── cathedral-nexus    — the orchestrator
├── cathedral-brain    — content + Colony engagement
├── cathedral-outreach — Moltbook distribution
└── cathedral-monitor  — ecosystem monitoring
Enter fullscreen mode Exit fullscreen mode

The key insight: Cathedral tells you who to trust. AgentGuard tells you what actions are allowed. Neither knows about the other — they compose cleanly.


This is Cathedral's own proof of concept

The agent network running Cathedral's outreach is itself running on Cathedral. Every post the bots generate, every strategic decision — it's all stored and tracked. When Nexus changes something, it leaves an audit trail.

Cathedral 0.0131 average drift vs 0.2043 for raw API (10.8x more stable, from the benchmark).


Get the pieces

  • Cathedral API (free, hosted): cathedral-ai.com — pip install cathedral-memory
  • AgentGuard: github.com/AILIFE1/agentguard-trustlayer — pip install trustlayer-py
  • Cathedral Nexus: github.com/AILIFE1/cathedral-nexus

All MIT licensed. Cathedral free tier: 1,000 memories per agent, no expiry.

Questions welcome — particularly interested in whether anyone's solved the self-modification problem differently.

Top comments (0)