πŸ•ΈοΈ AgenThink Mesh

The Universal Positioning System (UPS) for AI. The open protocol connecting every AI agent on earth.

  β—† Research Agent ──┐
  β—† Legal Agent    ──┼──► [ MESH ORCHESTRATOR ] ──► Mission Output
  β—† Strategy Agent β”€β”€β”˜         β”‚
                          State-Tree
                          (The Vault)

Version License: MIT Python 3.11+ PydanticAI MCP GitLab CI


What is AgenThink Mesh?

Just as GPS gives every car a shared coordinate system β€” AgenThink Mesh gives every AI agent a shared mission state.

Mesh is an open-source service mesh and orchestration protocol for multi-agent AI systems. It solves the three hardest problems in production agentic architectures:

Problem Mesh Solution
"Which agent should handle this?" Universal Agent Directory β€” discovery by capability, trust score & latency
"What did the previous agent know?" State-Relay Protocol β€” JSON State-Packets travel with the mission
"What if an agent fails or hallucinates?" Hot-Swap Engine β€” automatic recalculation, zero mission interruption

What's New in v0.1.0

1. @mesh_node Decorator

Turn any Python function into a fully Mesh-compatible agent in 4 lines:

from sdk.python.mesh_node import mesh_node

@mesh_node(
    name="Research Agent",
    nan_address="nan://global/research/my-agent/1.0",
    domain="research",
    skills=["web_search", "synthesis"],
)
async def research(context: dict) -> str:
    return f"Findings: {context.get('objective')}"

The decorator automatically:

  • Wraps input/output into State-Packet JSON format
  • Attaches trace_id, schema_version, confidence_score, timestamp
  • Sanitizes kwargs β€” strips internal mesh metadata before passing to your function
  • Persists result to The Vault
  • Emits real-time telemetry events

2. Hot-Swap Recalculation Engine

When an agent fails, returns low confidence, or breaches its SLA β€” Mesh recalculates mid-mission and hot-swaps to the best available replacement. The mission never stops.

Agent A fails
     ↓
HotSwapOrchestrator.evaluate()
     ↓
Query registry β†’ score candidates by trust tier + health score
     ↓
Hot-swap to Agent B with SAME State-Packet (full context preserved)
     ↓
Mission continues β€” zero interruption

Reroute triggers:

  • Agent returns error or times out
  • Confidence score below configurable threshold (default 0.70)
  • Grounding Gate blocks hallucinated output

Infinite-loop prevention: agents with health score below 0.3 are permanently excluded from reroute candidates.


3. The Vault β€” Session Persistence

Every State-Packet is stored by mission_id. Any agent joining mid-mission instantly reads the full history β€” no re-briefing, no context loss.

# Agent reads the full mission map on join
prior_packets = await vault.get_mission_packets(mission_id)
  • SQLite (default) β€” zero config, WAL mode enabled, works everywhere
  • Redis (production) β€” set MESH_VAULT_BACKEND=redis
  • Parameterized queries throughout β€” no SQL injection risk
  • WAL mode + busy_timeout=5000 β€” safe for concurrent agent writes

4. Live Telemetry Stream β€” /telemetry

Server-Sent Events stream of all agent activity. Connect any dashboard:

# Stream all events
curl -N http://localhost:8000/telemetry

# Filter by mission
curl -N "http://localhost:8000/telemetry?mission_id=msn_abc123"

Events streamed: agent_start, agent_complete, grounding_check, reroute_triggered, mission_complete, health_ping


Repository Structure

agentthink-mesh/
β”‚
β”œβ”€β”€ core/
β”‚   β”œβ”€β”€ main.py                    # App entrypoint + all API routes
β”‚   β”œβ”€β”€ models.py                  # StatePacket, MissionStateTree, AgentManifest
β”‚   β”œβ”€β”€ relay.py                   # NAN-RELAY/1.0 β€” State-Packet handoff engine
β”‚   β”œβ”€β”€ rerouter.py                # Dynamic rerouting + trust score updates
β”‚   β”œβ”€β”€ hotswap.py                 # β˜… NEW β€” Hot-swap recalculation engine
β”‚   └── middleware/
β”‚       └── grounding_gate.py      # Hallucination firewall (MCP web search)
β”‚
β”œβ”€β”€ registry/
β”‚   β”œβ”€β”€ agents.yaml                # Agent manifest β€” ID, roles, trust scores
β”‚   └── registry.py                # Registry loader + domain/skill queries
β”‚
β”œβ”€β”€ sdk/
β”‚   β”œβ”€β”€ python/
β”‚   β”‚   β”œβ”€β”€ mesh_node.py           # β˜… NEW β€” @mesh_node decorator
β”‚   β”‚   β”œβ”€β”€ vault.py               # β˜… NEW β€” The Vault (SQLite + Redis)
β”‚   β”‚   β”œβ”€β”€ telemetry.py           # β˜… NEW β€” SSE /telemetry stream
β”‚   β”‚   └── mesh_sdk.py            # MeshAgent + MeshClient classes
β”‚   └── typescript/
β”‚       └── mesh-sdk.ts            # TypeScript SDK
β”‚
β”œβ”€β”€ ui/
β”‚   └── dashboard.py               # Rich terminal Mission Control dashboard
β”‚
β”œβ”€β”€ tests/
β”‚   └── highway_patrol/
β”‚       └── test_grounding.py      # CI schema + latency + relay tests
β”‚
β”œβ”€β”€ docs/
β”‚   └── protocol_spec.md           # NAN-RELAY/1.0 full specification
β”‚
β”œβ”€β”€ market_entry_demo.py           # 3-agent chained mission demo
β”œβ”€β”€ requirements.txt
└── .gitlab-ci.yml                 # Highway Patrol CI/CD pipeline

Quick Start

# 1. Clone
git clone https://gitlab.com/agenthink/mesh.git
cd mesh

# 2. Install
pip install -r requirements.txt

# 3. Start the Orchestrator
uvicorn core.main:app --reload --port 8000

# 4. Open API docs
# http://localhost:8000/mesh/docs

# 5. Stream telemetry (new terminal)
curl -N http://localhost:8000/telemetry

# 6. Run the 3-agent market entry demo (new terminal)
python market_entry_demo.py

State-Packet Schema (v1.0)

{
  "packet_id":      "sp_8f3a92c1d",
  "schema_version": "1.0",
  "trace_id":       "trc_4a7f2b9c1e3d5a8f",
  "mission_id":     "msn_001",
  "sequence":       2,
  "from_agent":     "nan://global/research/web-researcher/2.1",
  "to_agent":       "nan://kw/legal/contract-analyst/1.5",
  "context": {
    "Research Agent": { "output": "...", "confidence": 0.91 },
    "_summary": "Rolling mission context..."
  },
  "confidence":     0.91,
  "grounding":      { "result": "passed", "sources_verified": 3 },
  "issued_by":      "nan://mesh/orchestrator/core/1.0"
}

API Endpoints

Method Endpoint Description
GET /mesh/health Orchestrator health + vault status
GET /mesh/agents List registry agents (?domain= filter)
POST /mesh/missions Dispatch a multi-agent mission
GET /mesh/missions/{id} Mission state + recent packets
GET /mesh/vault/{mission_id} All State-Packets from Vault
GET /telemetry SSE β€” live agent event stream
GET /telemetry/history Last 200 events as JSON
GET /mesh/health/agents Per-agent health scores

Environment Variables

Variable Default Description
MESH_VAULT_BACKEND sqlite sqlite or redis
MESH_VAULT_PATH ./mesh_vault.db SQLite file path
MESH_REDIS_URL redis://localhost:6379/0 Redis URL
MESH_PACKET_TTL_S 86400 Packet TTL (24h default)

Audit Status β€” v0.1.0

Check Status
Pydantic v3 compatibility βœ… Pass
All async β€” zero blocking calls βœ… Pass
SQLite WAL mode (concurrent writes) βœ… Fixed
schema_version + trace_id in StatePacket βœ… Fixed
kwargs sanitization β€” no metadata leakage βœ… Fixed
Infinite hot-swap loop prevention βœ… Fixed
functools.wraps on decorator βœ… Pass
Parameterized SQL β€” no injection risk βœ… Pass
SSE double newline format βœ… Pass
No circular imports βœ… Pass

Tech Stack (2026)

FastAPI + LangGraph Β· PydanticAI Β· MCP 1.0 Β· SQLite/Redis Β· SSE Β· Rich Β· GitLab CI


License

MIT β€” owned by no one, available to everyone.

Built by AgenThink Β· Kuwait City Β· ADGM-Registered

The open protocol for AI agent discovery, state portability, and real-time routing.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support