Skip to content

HoloScript Communication Architecture — 3-Layer Specification

Date: 2026-03-20 | Source: Direct source audit across 7 packages | Status: Implemented

HoloScript implements a 3-layer communication stack that covers real-time scene coordination, agent-to-agent task delegation, and tool discovery/invocation. Each layer operates independently but shares identity through uAA2 JWT tokens.

Layer Overview

LayerPurposeTransportLatencySource Package
L1: RealTimeIn-scene state sync, CRDT collaborationWebSocket, WebRTC, BroadcastChannel<16mscore/src/network/, collab-server/, core/src/collaboration/
L2: A2AAgent-to-agent task delegationHTTP JSON-RPC, Agent Cards50–500msagent-protocol/, core/src/compiler/A2AAgentCardCompiler.ts
L3: MCPTool discovery and invocationStreamable HTTP, JSON-RPC100ms–5smcp-server/ (verify tool count via curl mcp.holoscript.net/health)

Architecture Diagram

mermaid
flowchart TB
    subgraph L1["Layer 1 — RealTime (<16ms)"]
        WS["WebSocket Relay<br/>:4999/collab"]
        CRDT["CRDTDocument<br/>(Yjs-backed)"]
        SYNC["SyncProtocol<br/>WebSocket | WebRTC | Local"]
        NET["NetworkedTrait v3.0.1<br/>delta compression + interpolation"]
        WS --> CRDT
        SYNC --> NET
    end

    subgraph L2["Layer 2 — A2A (50-500ms)"]
        PROTO["uAA2++ 7-Phase Protocol<br/>INTAKE→AUTONOMIZE"]
        CARD["A2A Agent Card<br/>/.well-known/agent-card.json"]
        MICRO["MicroPhaseDecomposer<br/>parallel task graphs"]
        PWG["PWG Knowledge Format<br/>Pattern / Wisdom / Gotcha"]
        PROTO --> MICRO
        CARD --> PROTO
        PROTO --> PWG
    end

    subgraph L3["Layer 3 — MCP (100ms-5s)"]
        DISC["/.well-known/mcp<br/>discovery endpoint"]
        TOOLS["MCP Tools<br/>(see /health for count)"]
        STATE["push_state_delta<br/>fetch_authoritative_state"]
        STREAM["Streamable HTTP<br/>POST /mcp"]
        DISC --> TOOLS
        TOOLS --> STATE
        STREAM --> TOOLS
    end

    L1 -- "entity state" --> L3
    L2 -- "task delegation" --> L3
    L2 -- "scene presence" --> L1
    L3 -- "tool results" --> L2

    style L1 fill:#1a1a2e,stroke:#16213e,color:#e2e2e2
    style L2 fill:#16213e,stroke:#0f3460,color:#e2e2e2
    style L3 fill:#0f3460,stroke:#533483,color:#e2e2e2

Layer 1: RealTime — In-Scene State Synchronization

Purpose

Sub-frame entity state replication for multi-user VR/AR experiences. Two subsystems handle different scopes: SyncProtocol for entity transforms (position, rotation, scale) and CRDTDocument for collaborative text editing (code, config).

Transport Options

TransportFileLatencyUse Case
WebSocketSyncProtocol.ts:330–4565–15msDefault, works everywhere
WebRTCSyncProtocol.ts:458–5591–5msLow-latency P2P, STUN via stun.l.google.com:19302
BroadcastChannelSyncProtocol.ts:561–623~1msSame-origin tabs (local dev)

Auto-detection (NetworkedTrait.ts:280–329): Attempts WebRTC first, falls back to WebSocket, then Local.

SyncProtocol Configuration

Default batch window:   16ms    (SyncProtocol.ts:675)
Default update rate:    60Hz    (SyncProtocol.ts:674)
Distance culling:       100 units (SyncProtocol.ts:673)
Change threshold:       0.001   (SyncProtocol.ts:676)
Reconnect max attempts: 5       (WebSocketTransport, line 341)
Ping interval:          5000ms  (WebSocketTransport, line 434)

Delta Encoding

DeltaEncoder (lines 109–259) tracks per-entity state versions and computes field-level diffs. Only changed fields are transmitted. Operations: set, delete, increment, append.

Interest Management

InterestManager (lines 265–312) provides 3D spatial culling — entities beyond distanceCulling radius are not replicated to a given peer, reducing bandwidth proportional to scene density.

NetworkedTrait Entity Sync

NetworkedTrait v3.0.1 (core/src/traits/NetworkedTrait.ts) attaches to any scene entity:

ConfigValueLine
Sync modesowner, shared, server29
Channelsreliable, unreliable, ordered30
Default sync rate20Hz245
Interpolation delay100ms945
Max extrapolation200ms947
Snap threshold5 units948
Buffer size10 samples481–484
Quantizationconfigurable bits per floatSyncProperty:46

Interpolation modes: linear, hermite, catmull-rom. Quaternion slerp for rotations (lines 652–684).

CRDT Collaborative Editing

CRDTDocument (core/src/collaboration/CRDTDocument.ts) provides Yjs-compatible text collaboration:

  • One Yjs Doc per file, text-level CRDT (not AST)
  • Binary frame: [4B length][NB text][8B version] (line 633)
  • Undo/redo stack (max 100, capture timeout 500ms)
  • Peer awareness: cursor, selection, world position, avatar ID
  • Change debounce: 50ms

Collaboration Server

collab-server/src/server.ts — WebSocket relay:

  • Endpoint: ws://host:4999/collab?room=<roomId>&token=<jwt>
  • Auth: JWT HS256 via COLLAB_AUTH_SECRET / NEXTAUTH_SECRET
  • Message types: join, cursor, leave, ping
  • Broadcast: All peers in room except sender

Sequence: Two Users Editing a Composition

mermaid
sequenceDiagram
    participant A as User A
    participant WS as Collab Server :4999
    participant B as User B

    A->>WS: ws://...?room=comp-42&token=jwt_a
    WS-->>A: connection established
    B->>WS: ws://...?room=comp-42&token=jwt_b
    WS-->>B: connection established

    A->>WS: {type:"join", userId:"a", name:"Alice", color:"#f00"}
    WS->>B: {type:"join", userId:"a", name:"Alice", color:"#f00"}

    A->>WS: CRDT update (Yjs binary frame)
    WS->>B: CRDT update (forwarded)
    B->>B: CRDTDocument.applyUpdate()

    B->>WS: {type:"cursor", userId:"b", x:42, y:7}
    WS->>A: {type:"cursor", userId:"b", x:42, y:7}

Layer 2: A2A — Agent-to-Agent Protocol

Purpose

Cross-agent task delegation using a structured lifecycle protocol. Agents advertise capabilities via Agent Cards (Google A2A spec) and execute work through the uAA2++ 7-phase cycle.

uAA2++ 7-Phase Protocol

Defined in packages/agent-protocol/src/index.ts:

#PhasePurpose
0INTAKELoad context, discover tools, authenticate
1REFLECTAnalyze task, identify patterns from PWG knowledge
2EXECUTEPerform work, call tools
3COMPRESSExtract patterns, wisdom, gotchas from results
4REINTAKERe-evaluate with new knowledge
5GROWUpdate capabilities, expand tool repertoire
6EVOLVEArchitectural improvements, protocol upgrades
7AUTONOMIZESelf-directed task generation (max 3/cycle)

BaseAgent contract (lines 65–143): Every agent implements intake(), reflect(), execute(), compress(), reintake(), grow(), evolve(). runCycle(task, context) orchestrates all phases sequentially.

Agent Identity

typescript
interface AgentIdentity {
  id: string; // UUID
  name: string; // e.g. "holoscript-daemon"
  domain: string; // e.g. "holoscript"
  version: string;
  capabilities: string[];
}

PWG Knowledge Interchange

Three knowledge types flow between agents during COMPRESS/REINTAKE:

TypeID FormatKey FieldsExample
PatternP.DOMAIN.NNproblem, solution, confidence (0–1)P.HS.042 — parser error handling
WisdomW.DOMAIN.NNinsight, context, sourceW.HS.127 — expression gap fix
GotchaG.DOMAIN.NNmistake, fix, severityG.HS.004 — hand-crafted types

MicroPhaseDecomposer

MicroPhaseDecomposer (lines 411–533) breaks complex tasks into dependency graphs with topological sort and parallel execution groups. Default timeout: 30s per micro-phase.

A2A Agent Card Compiler

A2AAgentCardCompiler (core/src/compiler/A2AAgentCardCompiler.ts) compiles .holo/.hsplus compositions into Google A2A Agent Cards:

  • Spec: A2A Protocol v1.0.0 (Google, April 2025)
  • Well-known path: /.well-known/agent-card.json
  • Extends CompilerBase (line 239) with RBAC capability check
  • Compiles 11 skill types from HoloScript constructs:
    • Templates, Objects, Logic blocks, Spatial, Domain blocks (13 domains), NPCs, Dialogues, Quests, Abilities, State machines, State blocks
  • Auto-generates JSON-RPC interfaces for state/event access (lines 721–751)

Sequence: Agent Task Delegation

mermaid
sequenceDiagram
    participant DA as Daemon Agent
    participant ORCH as MCP Orchestrator
    participant HA as HoloScript Agent
    participant MCP as mcp.holoscript.net

    DA->>ORCH: GET /servers (discover agents)
    ORCH-->>DA: [{name:"holoscript-remote", url:"mcp.holoscript.net"}]

    DA->>MCP: GET /.well-known/agent-card.json
    MCP-->>DA: {skills:[...], capabilities:{streaming:true}}

    DA->>DA: INTAKE — load PWG context
    DA->>DA: REFLECT — match task to agent skill

    DA->>MCP: POST /mcp {tool:"holo_parse", args:{code:"..."}}
    MCP-->>DA: {ast: {...}, errors: []}

    DA->>DA: COMPRESS — extract Wisdom entry
    DA->>ORCH: POST /tools/call {server:"semantic-search-hub", tool:"add_wisdom", args:{...}}
    ORCH-->>DA: {stored: true}

    DA->>DA: AUTONOMIZE — generate follow-up tasks (max 3)

Layer 3: MCP — Model Context Protocol Tools

Purpose

Standardized tool discovery and invocation for LLM agents. HoloScript exposes MCP tools (verify count via curl mcp.holoscript.net/health) via the MCP Streamable HTTP transport.

Discovery Endpoint

GET /.well-known/mcp (http-server.ts:297–338) — ahead of the MCP specification (currently an active SEP, not yet finalized).

Response shape:

json
{
  "mcpVersion": "2025-03-26",
  "name": "holoscript-mcp",
  "transport": {
    "type": "streamable-http",
    "url": "https://mcp.holoscript.net/mcp",
    "authentication": { "type": "bearer", "header": "Authorization" }
  },
  "capabilities": { "tools": { "count": "..." } },
  "tools": [{ "name": "parse_hs", "description": "..." }, ...],
  "endpoints": {
    "mcp": "https://mcp.holoscript.net/mcp",
    "health": "https://mcp.holoscript.net/health",
    "render": "https://mcp.holoscript.net/api/render",
    "share": "https://mcp.holoscript.net/api/share"
  }
}

Tool Categories (verify counts via GET /health)

ModuleToolsSource
Core languageparse_hs, parse_holo, validate_holoscript, explain_code, analyze_code, convert_formattools.ts, handlers.ts
Traitslist_traits, explain_trait, suggest_traitshandlers.ts:285–340
Generatorsgenerate_object, generate_scenegenerators.ts
CompilerCompilation to backend targets (verify via find *Compiler.ts)compiler-tools.ts
Graph analysisScene graph traversal, dependency analysisgraph-tools.ts, graph-rag-tools.ts
IDE integrationLSP-adjacent tools for editorside-tools.ts
Browserbrowser_launch, browser_execute, browser_screenshotbrowser/
Networkingpush_state_delta, fetch_authoritative_statenetworking-tools.ts
MonitoringHealth, metrics, diagnosticsmonitoring-tools.ts
Self-improveDaemon orchestration, quality scoringself-improve-tools.ts
Testingholoscript test integrationholotest-tools.ts
GLTF import3D model ingestiongltf-import-tools.ts
SnapshotsState capture and restoresnapshot-tools.ts
KnowledgeWisdom/gotcha/pattern managementwisdom-gotcha-tools.ts

State Synchronization Tools

Two MCP tools bridge Layer 1 (RealTime) into Layer 3 (MCP), allowing LLM agents to participate in scene state:

push_state_delta — Push field-level changes with server-authoritative conflict resolution (last-write-wins):

json
{
  "tool": "push_state_delta",
  "args": {
    "entityId": "cube-001",
    "payload": { "position": [1, 2, 3], "color": "#ff0000" }
  }
}

fetch_authoritative_state — Read the current truth for any entity, bypassing stale local caches:

json
{
  "tool": "fetch_authoritative_state",
  "args": { "entityId": "cube-001" }
}

Sequence: LLM Agent Modifying a Scene

mermaid
sequenceDiagram
    participant LLM as LLM Agent
    participant MCP as mcp.holoscript.net
    participant AUTH as State Authority
    participant WS as L1 WebSocket Relay

    LLM->>MCP: GET /.well-known/mcp
    MCP-->>LLM: {tools:[...], transport:{type:"streamable-http"}}

    LLM->>MCP: POST /mcp {tool:"parse_hs", args:{code:"object Cube {...}"}}
    MCP-->>LLM: {ast: {type:"object", name:"Cube", ...}}

    LLM->>MCP: POST /mcp {tool:"push_state_delta", args:{entityId:"cube-001", payload:{position:[1,2,3]}}}
    MCP->>AUTH: LWW merge against authoritative state
    AUTH-->>MCP: {status:"success", deltas:1}
    MCP-->>LLM: {status:"success", message:"1 delta resolved"}

    Note over AUTH,WS: In production, deltas broadcast via L1

    LLM->>MCP: POST /mcp {tool:"fetch_authoritative_state", args:{entityId:"cube-001"}}
    MCP->>AUTH: Read current state
    AUTH-->>MCP: {position:[1,2,3], color:"#ff0000"}
    MCP-->>LLM: {position:[1,2,3], color:"#ff0000"}

Cross-Layer Integration

Identity Flow

All three layers share authentication through uAA2 JWT tokens:

LayerAuth MechanismToken Source
L1 RealTime?token=<jwt> query param on WebSocketCOLLAB_AUTH_SECRET / NEXTAUTH_SECRET
L2 A2AAgentIdentity.id + RBAC capability checkCompilerBase.getRBAC()
L3 MCPAuthorization: Bearer <token> headerHOLOSCRIPT_API_KEY env var

Layer Bridging

L1 ←→ L3:  networking-tools.ts bridges entity state between
           SyncProtocol (L1) and MCP tool calls (L3).
           LLM agents can push_state_delta to modify scenes
           that human users see in real-time.

L2 ←→ L3:  A2A agents discover tools via GET /.well-known/mcp (L3)
           and execute them through POST /mcp. The MCP orchestrator
           routes cross-server tool calls between registered agents.

L2 ←→ L1:  Agents set presence via CRDTDocument.setWorldPosition()
           and PeerAwareness. Agent avatars appear in-scene alongside
           human users.

Failure Mode Table

FailureAffected LayerDegradationRecovery
WebSocket disconnectL1Entity state freezes at last known position; local edits queueExponential backoff reconnect (5 attempts, 1s×2^n)
WebRTC ICE failureL1Falls back to WebSocket transport automaticallyAuto-detection chain in NetworkedTrait.connect('auto')
CRDT merge conflictL1Text-level CRDT resolves automatically (Yjs guarantees convergence)No manual intervention needed
Agent Card unavailableL2Task delegation fails; agent operates in standalone modeOrchestrator caches last-known card; retry on next cycle
uAA2++ phase failureL2CycleResult.status = 'partial'; remaining phases skippedPWG gotcha recorded; next cycle applies learned fix
MCP server downL3Tool calls return errors; agents fall back to local parsingHealth check at /health; Railway auto-restart
State Authority corruptL3push_state_delta returns stale dataDisk-backed JSON rebuilt from authoritative source on restart
Auth token expiredAllRequests rejected with 401Token refresh via uAA2 service; lock file includes spentUSD for budget tracking

Comparison to 2026 MCP Standard

FeatureMCP Spec (2025-11-25)HoloScript ImplementationStatus
Streamable HTTP transportReplaced SSE (2025-03-26)POST /mcp with streaming supportAligned
.well-known/mcp discoveryActive SEP (not yet finalized)http-server.ts:297 — full manifest + tool listAhead of spec
Tool invocationJSON-RPC over HTTPMCP tools via handleTool() dispatcherAligned
ResourcesResource templates + subscriptionsNot implemented (tools-only model)Intentional gap
PromptsPrompt templatesNot implementedIntentional gap
Tasks primitiveAdded in 2025-11-25 specAgent protocol handles task lifecycle at L2Different layer
MCP Registryregistry.modelcontextprotocol.io (preview)MCP Orchestrator with 9 registered serversAhead of spec
Agent-optimized toolsNot in spec*_quick_*, *_batch_*, *_smart_* prefixes in orchestratorBeyond spec
Multi-server orchestrationNot in specIDEA protocol (Initialize/Discover/Execute/Affirm)Beyond spec
Real-time state sync via MCPNot in specpush_state_delta / fetch_authoritative_stateBeyond spec

Key Differentiation

The MCP specification defines a single-layer tool protocol. HoloScript extends this into three layers:

  1. L1 fills the real-time gap — MCP has no sub-second state sync. HoloScript's SyncProtocol + CRDT layer enables VR-grade entity replication that MCP alone cannot provide.

  2. L2 fills the agent coordination gap — MCP defines tool discovery but not agent-to-agent delegation. The uAA2++ protocol + A2A Agent Cards provide a structured lifecycle for multi-agent systems.

  3. L3 aligns with MCP while extending it with domain-specific capabilities (spatial state sync, semantic traits via find packages/core/src/traits, compiler targets via find *Compiler.ts) that demonstrate how vertical MCP servers can specialize beyond generic tool providers.


Source Files

ComponentPathLines
SyncProtocolpackages/core/src/network/SyncProtocol.ts959
NetworkedTraitpackages/core/src/traits/NetworkedTrait.ts1,073
CRDTDocumentpackages/core/src/collaboration/CRDTDocument.ts640+
Collab Serverpackages/collab-server/src/server.ts166
Agent Protocolpackages/agent-protocol/src/index.ts534
A2A Compilerpackages/core/src/compiler/A2AAgentCardCompiler.ts751
MCP HTTP Serverpackages/mcp-server/src/http-server.ts400+
MCP Handlerspackages/mcp-server/src/handlers.ts1,000+
Networking Toolspackages/mcp-server/src/networking-tools.ts167

Released under the MIT License.