DEV Community

Cover image for Mycelium: A Trust-Aware Memory Mesh for Multi-Agent Systems
Harish Kotra (he/him)
Harish Kotra (he/him)

Posted on

Mycelium: A Trust-Aware Memory Mesh for Multi-Agent Systems

The Problem

AI agents today are getting smarter, but they're still fundamentally amnesiac.

Talk to a customer support agent, get your answer, come back tomorrow — it's a blank slate. Even persistent memory systems usually store facts inside a single agent boundary. What happens when two agents disagree about the same fact? Which one do you trust?

This is the problem I set out to solve: how do you build shared memory across independent agents, with built-in contradiction detection and trust that evolves over time?

Enter Mycelium.


What Mycelium Is

Mycelium is a TypeScript framework for building AI agents with persistent, shared memory backed by a knowledge graph. Think of it as a memory federation — each agent has its own dataset (memory), but they can sync, share, and reconcile facts with peers through a protocol that tracks provenance, detects contradictions, and builds trust.

The name comes from nature. Mycelium networks connect individual fungi into a shared information web — nutrients, warnings, and signals flow between organisms through underground threads. This project applies the same idea to AI agents.


The Architecture

The system has four core layers:

1. Knowledge Graph Memory (Cognee)

Every agent wraps a Cognee dataset. When you add a fact, Cognee:

  • Ingests the text
  • Runs an LLM pipeline to extract entities and relationships
  • Stores them in an embedded Kuzu graph database
  • Generates ONNX embeddings (bge-small-en-v1.5) for semantic search

The result is a structured knowledge graph, not just a vector store. Agents can recall facts, traverse relationships, and get graph-completion answers — not just similarity matches.

2. Provenance-Tracked Sync Protocol

When Agent A shares facts with Agent B, every fact is tagged with its origin before storage:

__provenance__:{"sourceAgentId":"agent_a","factId":"f123","timestamp":1700000000000}
Flight AA1234 departs at 5:00 PM.
Enter fullscreen mode Exit fullscreen mode

This tag survives round-trips through Cognee's graph extraction. You can always trace a fact back to its source — critical for auditability in regulated domains like healthcare and finance.

3. LLM-Powered Contradiction Detection

This is the most technically interesting part. When facts are synced, the engine runs a batched LLM contradiction check — all source and subscriber facts go into a single prompt:

System: You are a contradiction detector. Given two lists of facts,
identify pairs that directly contradict each other.
Respond with JSON: { contradictions: [{ sIndex, tIndex, reason, confidence }] }

User:
Subscriber existing facts:
S0: No known allergies.
S1: Metformin 500 mg once daily.
...

Incoming source facts:
T0: Patient is allergic to Amoxicillin.
T1: Metformin 500 mg twice daily.
...
Enter fullscreen mode Exit fullscreen mode

One LLM call instead of comparing every pair. The response is structured JSON — no parsing ambiguity. Cost: ~$0.001 per run on gpt-4o-mini.

4. Trust Scoring

Trust is a simple score from 0 to 1, starting at 0.5:

Event Trust Change
Auto-merge (no contradictions) +0.05
Manual accept (after review) +0.05
Manual reject -0.20
Contradictions detected (auto) -0.20 (decision = pending_review)

Contradictions are weighted heavily — one contradiction flips auto_merged to pending_review regardless of current trust. This creates an incentive alignment: agents that share reliable, conflict-free facts build trust over time.


Five Domains, One Pattern

To prove the pattern generalizes, I built five end-to-end demos:

Healthcare — Medication Reconciliation

A clinic stores "Metformin 500 mg once daily, no allergies." A pharmacy has "Metformin 500 mg twice daily, allergic to Amoxicillin." The sync engine flags both contradictions before facts are merged. (This is a real, life-critical problem — medication errors cause thousands of deaths annually.)

Supply Chain — Inventory Drift

Warehouse Alpha records "500 units of SKU WX-1001 in stock." Warehouse Beta has "200 units, unit cost $14.99." Same warehouse, different numbers. The engine catches the count and price discrepancies.

Smart Home — IoT Sensor Fusion

The living room hub says "Motion detected in living room at 2:30 AM." The security hub says "No motion detected — security system armed." Conflicting sensor readings flagged for review.

News Verification — Media Fact-Checking

Two news outlets cover the same press conference but report completely different projects — NewsWire says "Elm Street Community Park, $2M budget" while CityPress reports "Oak Avenue Public Library, $5M budget." The engine identifies five contradictions and suggests both projects may be real.

Travel Assistant — Itinerary Synchronization

A travel planner has updated flight info (8:00 PM departure due to ATC congestion), but the personal assistant still shows the original 5:00 PM time. The sync engine catches the conflict and flags it.

Each demo runs in under 30 seconds, costs about a tenth of a cent in LLM calls, and showcases the same core engine.


Technical Details

Stack:

  • Language: TypeScript (ES2022)
  • Graph Memory: Cognee Rust SDK (@cognee/cognee-ts v0.1.2)
  • Graph DB: Kuzu (embedded, via Cognee)
  • LLM: OpenAI gpt-4o-mini (cheap, supports json_schema)
  • Embeddings: ONNX (bge-small-en-v1.5, local — no API needed)
  • Monorepo: pnpm workspaces
  • Runtime: Node.js via tsx (no build step)

Key design decisions:

  1. Batched LLM detection over pairwise: A single prompt with all facts avoids O(n²) calls. The LLM is good enough to compare everything in one pass.

  2. No build step: main in package.json points to raw .ts source. tsx transpiles at runtime. Eliminates the need for tsup, typescript, and Turborepo entirely.

  3. Local-first: Everything runs on your laptop. Kuzu is embedded. ONNX models auto-download. No Cognee Cloud, no Pinecone, no external vector DB.

  4. Provider-agnostic LLM: Swap from OpenAI to Groq to Ollama to LM Studio with a single USE_LLM_PROVIDER env var. The contradiction detector and Cognee's cognify pipeline both work with any provider.


Results

The demos prove the pattern works:

  • Contradiction detection is reliable: In every demo, the batched LLM call correctly identifies the conflicting facts. The structured JSON output is clean and parseable.
  • Trust provides meaningful signal: Contradictions → pending_review → -0.2 creates a clear penalty. Clean syncs → auto_merge → +0.05 rewards reliability.
  • Cognee graph extraction works: The SDK successfully extracts entities and relationships from raw text, even with provenance prefix tags. The Kuzu-backed graph supports traversal and graph completion queries.
  • Generalization holds: Five very different domains, one engine, zero domain-specific code changes.

What's Next

The framework is in alpha. Here's what I want to build next:

Feature Why Difficulty
WebSocket live sync Agents sync in real time, not polling Medium
Git-like 3-pane merge UI Visual contradiction review in dashboard Hard
Trust decay Scores decrease if agents go silent Medium
Multi-hop trust If A trusts B and B trusts C, should A partially trust C? Medium
Constitutional memory Agents reject facts that violate predefined rules Hard
Dashboard → real backend Swap mock data with live CogneeClient calls Medium
Pub/sub subscriptions Agents subscribe to data streams from peers Easy
Contradiction evidence citation LLM returns the exact conflicting snippet Medium

Try It

git clone https://github.com/harishkotra/mycelium
cd mycelium
pnpm install
cp packages/core/.env.example packages/core/.env
# Set your LLM_API_KEY in .env
pnpm --filter healthcare-demo demo
Enter fullscreen mode Exit fullscreen mode

That's it. Run any of the five demos, see contradictions detected and trust adjusted in real time.

Screenshots

Dashboard Demo - 1

Dashboard Demo - 2

Dashboard Demo - 3

Dashboard Demo - 4

Dashboard Demo - 5

Code & more: https://www.dailybuild.xyz/project/184-mycelium

Top comments (0)